-
Notifications
You must be signed in to change notification settings - Fork 1
tighter test checks #4
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -777,13 +777,13 @@ def objfn(xy): | |||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Check constraint is active | ||||||||||||||||||||||||||||
| self.assertLess( | ||||||||||||||||||||||||||||
| abs(c_val[0, 0]), 0.1, msg="Constraint should be approximately active" | ||||||||||||||||||||||||||||
| abs(c_val[0, 0]), 0.05, msg="Constraint should be approximately active" | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Check multiplier is positive | ||||||||||||||||||||||||||||
| self.assertGreater( | ||||||||||||||||||||||||||||
| lm.general_constraints[0, 0], | ||||||||||||||||||||||||||||
| 0.1, | ||||||||||||||||||||||||||||
| 0.01, | ||||||||||||||||||||||||||||
| msg="Active constraint should have positive multiplier", | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -883,7 +883,7 @@ def objfn(xy): | |||||||||||||||||||||||||||
| # Stationarity: ∇f - ξ should be small | ||||||||||||||||||||||||||||
| self.assertLess( | ||||||||||||||||||||||||||||
| residual_norm, | ||||||||||||||||||||||||||||
| 0.5, | ||||||||||||||||||||||||||||
| 0.01, | ||||||||||||||||||||||||||||
| msg=f"Stationarity at bounds violated: ||∇f - ξ|| = {residual_norm}", | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -968,7 +968,7 @@ def objfn(xy): | |||||||||||||||||||||||||||
| # Stationarity: ∇f + η should be small | ||||||||||||||||||||||||||||
| self.assertLess( | ||||||||||||||||||||||||||||
| residual_norm, | ||||||||||||||||||||||||||||
| 0.5, | ||||||||||||||||||||||||||||
| 0.01, | ||||||||||||||||||||||||||||
| msg=f"Stationarity at upper bounds violated: ||∇f + η|| = {residual_norm}", | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -1134,14 +1134,13 @@ def objfn(x): | |||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Check scaling relationship | ||||||||||||||||||||||||||||
| base_lambda = results[0]["lambda_lower"] | ||||||||||||||||||||||||||||
| for i, r in enumerate(results[1:], start=1): | ||||||||||||||||||||||||||||
| for _, r in enumerate(results[1:], start=1): | ||||||||||||||||||||||||||||
| expected_lambda = base_lambda * (r["scale"] / results[0]["scale"]) | ||||||||||||||||||||||||||||
| actual_lambda = r["lambda_lower"] | ||||||||||||||||||||||||||||
| relative_error = abs(actual_lambda - expected_lambda) / max(expected_lambda, 1e-6) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| self.assertLess( | ||||||||||||||||||||||||||||
| relative_error, | ||||||||||||||||||||||||||||
| 0.2, # 20% tolerance | ||||||||||||||||||||||||||||
| 0.01, # 1% tolerance | ||||||||||||||||||||||||||||
| msg=f"Multiplier should scale with objective. " | ||||||||||||||||||||||||||||
| f"Expected {expected_lambda:.4f}, got {actual_lambda:.4f}", | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
|
|
@@ -1253,7 +1252,7 @@ def objfn(xy): | |||||||||||||||||||||||||||
| relative_deviation = abs(prod - mean_product) / mean_product | ||||||||||||||||||||||||||||
| self.assertLess( | ||||||||||||||||||||||||||||
| relative_deviation, | ||||||||||||||||||||||||||||
| 0.3, # 30% tolerance | ||||||||||||||||||||||||||||
| 0.01, # 1% tolerance | ||||||||||||||||||||||||||||
| msg="λ * scale should be approximately constant", | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
|
Comment on lines
1252
to
1257
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For improved readability and to follow common testing patterns with NumPy, consider using
Suggested change
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the manual calculation of relative error works, using
np.testing.assert_allcloseis more idiomatic and robust for comparing floating-point numbers in NumPy-based tests. It clearly expresses the intent of checking for approximate equality with a relative tolerance and handles edge cases around zero more gracefully.