Skip to content

Multinomial mode: initial conditions rounded per compartment, totals not conserved, seeds below one vanish #557

Open

Description

@RomeshA

Found in review of #539.

Problem

Population.initialize_compartments() applies stochastic_rounding() to each compartment independently. Consequences:

  • Totals no longer match the characteristics in the databook (a population of 1000 split 60/40 across two compartments can initialise to 999 or 1001).
  • Any compartment initialised below one person is usually rounded to zero. With the SIR demo scaled to ten people, the deterministic model keeps a fraction of an infection alive while every one of 300 stochastic runs went extinct. Users who scale down a model to explore small-population behaviour will see silent extinction with no warning.

Implementation plan

  1. Round so that totals are preserved: compute the deterministic solution x, round the population total with stochastic_rounding, then allocate it across compartments with rng.multinomial(total, x / x.sum()). For frameworks with multiple population types or disconnected characteristic groups, do this per connected group of the initialisation system.
  2. Emit a logger.warning when any compartment's deterministic initial value is between 0 and 1 in multinomial mode, naming the compartment, since this is the seed-infection case.
  3. Add a test on the SIR demo that the initial total matches the databook exactly and that the warning fires when the infected seed is below one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions