makeweight: always use geometric mean for default gain_mid#147
Merged
Conversation
… the same side of 1 The default-gain branch in `makeweight(low, mid::Number, high)` previously returned 1 whenever `high >= 1`. That violates the downstream formula's `low < mag < high` precondition whenever both `low > 1` and `high > 1` (e.g. `makeweight(2, 1, 3)`), silently producing a weight with complex/NaN poles. Use `√(low*high)` only when `low` and `high` lie on the same side of 1 — the previously-broken case. When `low` and `high` straddle 1 (the typical case) keep the historical default `gain_mid = 1`, which preserves user-facing behavior for, e.g., `makeweight(1e-3, 10, 10)` (low<1<high) and the H∞ / LQG synthesis tests that depend on it. Adds regression tests for both same-side cases (`makeweight(2, 1, 3)` and `makeweight(0.5, 1, 0.1)`). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
97795ab to
e6a2ac3
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #147 +/- ##
==========================================
- Coverage 91.84% 91.77% -0.07%
==========================================
Files 20 20
Lines 3064 3065 +1
==========================================
- Hits 2814 2813 -1
- Misses 250 252 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
makeweight(low, mid::Number, high)previously fell back to a hard-codedgain_mid = 1wheneverhigh >= 1. That violates the downstream formula'slow < mag < highprecondition whenever bothlow > 1andhigh > 1(e.g.makeweight(2, 1, 3)), silently producing a weight with complex/NaN poles.sqrt(low*high)only whenlowandhighlie on the same side of 1 — the previously-broken case. Whenlowandhighstraddle 1 (the typical case) keep the historical defaultgain_mid = 1. This preserves user-facing behavior for cases likemakeweight(1e-3, 10, 10)(low<1<high) which downstream H∞/LQG examples rely on.Test plan
makeweight(0.1, 1, 2)to assert the mid-frequency magnitude is 1 (straddle case, back-compat).makeweight(2, 1, 3)(both > 1) produces real coefficients and the mid magnitude issqrt(2*3).makeweight(0.5, 1, 0.1)(both < 1) also usessqrt(low*high).test_manual_hinf.jlandtest_weights.jlpass locally with the change.🤖 Generated with Claude Code