feat: add alpha optimization for normalized min-sum
Add optimize_alpha() function that sweeps hardware-friendly alpha values to find the best DE threshold with normalized min-sum. Add alpha-sweep CLI subcommand and --z/--cn-mode/--alpha options to the full pipeline. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -281,3 +281,31 @@ class TestNormalizedMinSumDE:
|
||||
assert thresh_norm != thresh_offset, (
|
||||
f"Thresholds should differ: offset={thresh_offset}, normalized={thresh_norm}"
|
||||
)
|
||||
|
||||
|
||||
class TestAlphaOptimization:
|
||||
"""Tests for alpha sweep optimization."""
|
||||
|
||||
def test_optimize_alpha_returns_best(self):
|
||||
"""Alpha sweep for optimized degrees should find threshold < 3.5."""
|
||||
from density_evolution import optimize_alpha
|
||||
np.random.seed(42)
|
||||
best_alpha, best_threshold = optimize_alpha(
|
||||
[7, 4, 4, 4, 4, 3, 3, 3], m_base=7, lam_b=0.1,
|
||||
z_pop=10000, tol=0.5
|
||||
)
|
||||
assert best_alpha is not None, "Should find a best alpha"
|
||||
assert 0.5 <= best_alpha <= 1.0, f"Alpha {best_alpha} out of range"
|
||||
# Normalized should be competitive with offset threshold (3.05)
|
||||
assert best_threshold < 4.0, f"Best threshold {best_threshold} too high"
|
||||
|
||||
def test_alpha_sweep_range(self):
|
||||
"""All alpha values in range should produce valid thresholds."""
|
||||
from density_evolution import optimize_alpha, build_de_profile, compute_threshold
|
||||
np.random.seed(42)
|
||||
profile = build_de_profile([7, 4, 4, 4, 4, 3, 3, 3], m_base=7)
|
||||
alpha_range = [0.5, 0.75, 1.0]
|
||||
for alpha in alpha_range:
|
||||
t = compute_threshold(profile, lam_b=0.1, z_pop=5000, tol=1.0,
|
||||
cn_mode='normalized', alpha=alpha)
|
||||
assert 0.1 < t < 20.0, f"alpha={alpha}: threshold {t} out of valid range"
|
||||
|
||||
Reference in New Issue
Block a user