Skip to content

Commit 9d26c71

Browse files
author
Aaron Meyer
committed
Test the competing-risks emission through the package cross validation
Covers rand_init, array censoring, hide_observation and the at-once M step in one pass, and confirms two states beat one on held-out likelihood.
1 parent 0d85037 commit 9d26c71

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

‎lineage/tests/test_StateDistributionCR.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,35 @@ def test_phase_estimator_recovers_parameters():
158158
fitted.estimator(obs, np.ones(obs.shape[0]))
159159

160160
np.testing.assert_allclose(fitted.params[2:], truth.params[2:], rtol=0.15)
161+
162+
163+
def test_works_through_crossval():
164+
"""The competing-risks emission drops into the package's own cross validation.
165+
166+
Two well-separated states should beat one on held-out likelihood, and the run
167+
exercises rand_init, censoring, hide_observation and the at-once M step.
168+
"""
169+
from lineage.BaumWelch import calculate_stationary
170+
from lineage.crossval import crossval, hide_observation
171+
from lineage.LineageTree import LineageTree
172+
173+
T = np.array([[0.9, 0.1], [0.1, 0.9]])
174+
E = [
175+
StateDistributionPhase(8.0, 7.0, 4.0, 2.0, death_scale1=400.0, death_a2=3.0, death_scale2=200.0),
176+
StateDistributionPhase(6.0, 4.0, 3.0, 5.0, death_scale1=20.0, death_a2=3.0, death_scale2=12.0),
177+
]
178+
rng = np.random.default_rng(3)
179+
180+
populations = [
181+
[
182+
LineageTree.rand_init(
183+
calculate_stationary(T), T, E, 31, censor_condition=3, desired_experiment_time=150, rng=rng
184+
)
185+
for _ in range(20)
186+
]
187+
for _ in range(3)
188+
]
189+
train = [hide_observation(pop, 0.25, rng=rng) for pop in populations]
190+
191+
ll = crossval(train, np.arange(1, 3), rng=rng)
192+
assert ll[0] < ll[1]

0 commit comments

Comments
 (0)