Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the validation condition for random distributions lenient #550

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions tests/integration/utils/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def zipf(self, alpha, shape, dtype):
return num.random.zipf(alpha, shape, dtype)


def assert_distribution(a, theo_mean, theo_stdev, tolerance=1e-2):
def assert_distribution(a, theo_mean, theo_stdev, mean_tol=1e-2, stdev_tol=2):
if True:
aa = np.array(a)
average = np.mean(aa)
Expand All @@ -154,12 +154,18 @@ def assert_distribution(a, theo_mean, theo_stdev, tolerance=1e-2):
num.mean((a - average) ** 2)
) # num.std(a) -> does not work
print(
f"average = {average} - expected {theo_mean}"
+ f", stdev = {stdev} - expected {theo_stdev}\n"
f"average = {average} - theoretical {theo_mean}"
+ f", stdev = {stdev} - theoretical {theo_stdev}\n"
)
assert np.abs(theo_mean - average) < tolerance * np.max(
assert np.abs(theo_mean - average) < mean_tol * np.max(
(1.0, np.abs(theo_mean))
)
assert np.abs(theo_stdev - stdev) < tolerance * np.max(
(1.0, np.abs(theo_stdev))
)
# the theoretical standard deviation can't be 0
assert theo_stdev != 0
# TODO: this check is not a good proxy to validating that the samples
# respect the assumed random distribution unless we draw
# extremely many samples. until we find a better validation
# method, we make the check lenient to avoid random
# failures in the CI. (we still need the check to catch
# the cases that are obviously wrong.)
assert np.abs(theo_stdev - stdev) < stdev_tol * np.abs(theo_stdev)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default stddev_tol = 2 = 200% seems like a very high limit for a relative difference. Since standard deviation is always non-negative, what you are essentially checking here is that stddev < 3 * theo_stdev. Is that your goal here, or is stddev_tol = 2 a typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. I spent much time on writing a comment and didn't do the job for the test itself ;) I revised the test to make it more sensible.