You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Multinomial mode: ResidualJunctionCompartment.initial_flush() double counts the residual link #552
numpy treats the last entry of pvals as the remainder probability, so when the residual link is last in outlinks the drawn residual column already holds the residual people. Dividing by n * sum(fractions) (where the residual fraction is 0) then renormalises so the fractions sum to 2. The residual destination receives n - sum(n * fractions), which is negative.
Reproduced: framework_junction_remainder_test.xlsx loses 13 of 100 people at t0 in multinomial mode; framework_junction_remainder_test_2.xlsx crashes with ValueError: n < 0 inside the first multinomial draw because a compartment was initialised negative.
The same latent issue applies to JunctionCompartment.initial_flush() if any outflow fraction is zero and the ordering of outlinks changes, since correctness currently depends on where numpy places the remainder.
Implementation plan
Build the probability vector explicitly: for a residual junction set the residual link's probability to max(0, 1 - sum(others)), and for a plain junction normalise to sum to 1. Never rely on numpy's implicit remainder handling.
Draw integer counts once and assign them directly to link.dest[0] += counts[i], bypassing the fraction arithmetic entirely in multinomial mode.
Reuse the helper from the balance() fix so initial_flush() and balance() share one code path for probability construction.
Add a regression test that initialises a residual junction with a nonzero value in multinomial mode and asserts all downstream values are non-negative integers summing to the initial value.
Activity