Skip to content

makeweight: always use geometric mean for default gain_mid#147

Merged
baggepinnen merged 1 commit into
masterfrom
fix-makeweight-default-gain-mid
May 16, 2026
Merged

makeweight: always use geometric mean for default gain_mid#147
baggepinnen merged 1 commit into
masterfrom
fix-makeweight-default-gain-mid

Conversation

@baggepinnen
Copy link
Copy Markdown
Member

@baggepinnen baggepinnen commented May 15, 2026

Summary

  • makeweight(low, mid::Number, high) previously fell back to a hard-coded gain_mid = 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.
  • Conservative fix: use sqrt(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. This preserves user-facing behavior for cases like makeweight(1e-3, 10, 10) (low<1<high) which downstream H∞/LQG examples rely on.

Test plan

  • Updated existing test for makeweight(0.1, 1, 2) to assert the mid-frequency magnitude is 1 (straddle case, back-compat).
  • New regression test: makeweight(2, 1, 3) (both > 1) produces real coefficients and the mid magnitude is sqrt(2*3).
  • New symmetric test: makeweight(0.5, 1, 0.1) (both < 1) also uses sqrt(low*high).
  • test_manual_hinf.jl and test_weights.jl pass locally with the change.

🤖 Generated with Claude Code

… 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>
@baggepinnen baggepinnen force-pushed the fix-makeweight-default-gain-mid branch from 97795ab to e6a2ac3 Compare May 16, 2026 04:14
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.77%. Comparing base (14a7deb) to head (e6a2ac3).
⚠️ Report is 4 commits behind head on master.

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     
Flag Coverage Δ
unittests 91.77% <100.00%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@baggepinnen baggepinnen merged commit 67eef51 into master May 16, 2026
2 checks passed
@baggepinnen baggepinnen deleted the fix-makeweight-default-gain-mid branch May 16, 2026 04:54
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.

2 participants