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

Fix bug in parametric quantile tuning curves #44

Merged
merged 4 commits into from
Aug 7, 2024

Conversation

nicholaslourie
Copy link
Owner

Fix a bug in the quantile_tuning_curve methods of opda.parametric.QuadraticDistribution and opda.parametric.NoisyQuadraticDistribution. This bug caused the method to return incorrect output whenever q wasn't equal to 0.5 and either minimize was True or minimize was None and convex was True.

While slower, it's much simpler to use the quantile function to
implement the quantile tuning curve.
Clean up QuadraticDistributionTestCase.test_quantile_tuning_curve
and NoisyQuadraticDistributionTestCase.test_quantile_tuning_curve
to make them more alike and to make the logic more self-contained.

In QuadraticDistributionTestCase.test_quantile_tuning_curve
generate the absolute tolerance for the test assertions in the test
itself, the same way that it's already done in
NoisyQuadraticDistributionTestCase.test_quantile_tuning_curve.

In both tests, factor out the number of trials (2,000) and the
quantile being tested (0.5) as the variables n_trials and q to make
these values easily identifiable.
Fix the quantile_tuning_curve methods of QuadraticDistribution and
NoisyQuadraticDistribution. Both methods use an incorrect formula
for the quantile tuning curve when minimize is True. The tests do
not catch this bug because they only test q = 0.5 and the incorrect
formula happens to work for this one case. In addition, the
test_quantile_tuning_curve tests actually check non-integral
arguments to the quantile tuning curve using an invariant which
would fail when this bug is present, except the invariant was also
entered into the test incorrectly.

To resolve these issues:

  * Add a regression test to QuadraticDistributionTestCase and
    NoisyQuadraticDistributionTestCase to catch similar bugs in the
    future: test_quantile_tuning_curve_with_different_quantiles.
  * Fix the invariant used to test non-integral arguments in
    test_quantile_tuning_curve on QuadraticDistributionTestCase and
    NoisyQuadraticDistributionTestCase so that the tests will pass
    when the quantile_tuning_curve methods are correct.
  * Fix the bug in QuadraticDistribution.quantile_tuning_curve and
    NoisyQuadraticDistribution.quantile_tuning_curve.

This bug does not affect EmpiricalDistribution.quantile_tuning_curve
or its tests as they all use the correct formula.
@nicholaslourie nicholaslourie merged commit a59a35e into main Aug 7, 2024
12 checks passed
@nicholaslourie nicholaslourie deleted the fix-bug-in-parametric-quantile-tuning-curves branch August 7, 2024 04:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant