feat: add threshold computation via binary search
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -50,3 +50,45 @@ class TestDensityEvolution:
|
||||
# Run one step
|
||||
beliefs = density_evolution_step(beliefs, msg_memory, ORIGINAL_STAIRCASE_PROFILE, z_pop)
|
||||
assert beliefs.shape == (n_base, z_pop), f"Shape changed after step: {beliefs.shape}"
|
||||
|
||||
|
||||
class TestThresholdComputation:
|
||||
"""Tests for threshold binary search."""
|
||||
|
||||
def test_threshold_original_staircase(self):
|
||||
"""Threshold for original staircase [7,2,2,2,2,2,2,1] should be ~3-6 photons."""
|
||||
from density_evolution import compute_threshold_for_profile
|
||||
np.random.seed(42)
|
||||
threshold = compute_threshold_for_profile(
|
||||
[7, 2, 2, 2, 2, 2, 2, 1], m_base=7, lam_b=0.1,
|
||||
z_pop=10000, tol=0.5
|
||||
)
|
||||
assert 2.0 < threshold < 8.0, f"Expected threshold ~3-6, got {threshold}"
|
||||
|
||||
def test_threshold_peg_ring(self):
|
||||
"""PEG ring [7,3,3,3,2,2,2,2] should have lower or equal threshold than original."""
|
||||
from density_evolution import compute_threshold_for_profile
|
||||
np.random.seed(42)
|
||||
thresh_orig = compute_threshold_for_profile(
|
||||
[7, 2, 2, 2, 2, 2, 2, 1], m_base=7, lam_b=0.1,
|
||||
z_pop=15000, tol=0.25
|
||||
)
|
||||
np.random.seed(123)
|
||||
thresh_peg = compute_threshold_for_profile(
|
||||
[7, 3, 3, 3, 2, 2, 2, 2], m_base=7, lam_b=0.1,
|
||||
z_pop=15000, tol=0.25
|
||||
)
|
||||
assert thresh_peg <= thresh_orig, (
|
||||
f"PEG threshold {thresh_peg} should be <= original {thresh_orig}"
|
||||
)
|
||||
|
||||
def test_profile_to_hbase(self):
|
||||
"""build_de_profile should produce valid profile with correct column degrees."""
|
||||
from density_evolution import build_de_profile
|
||||
profile = build_de_profile([7, 3, 2, 2, 2, 2, 2, 2], m_base=7)
|
||||
assert profile['n_base'] == 8
|
||||
assert profile['m_base'] == 7
|
||||
assert profile['vn_degrees'] == [7, 3, 2, 2, 2, 2, 2, 2]
|
||||
# Every row should have at least 2 connections
|
||||
for r, conns in enumerate(profile['connections']):
|
||||
assert len(conns) >= 2, f"Row {r} has only {len(conns)} connections"
|
||||
|
||||
Reference in New Issue
Block a user