Skip to main content

Gallery

🧠0% 🤖100%

Complete models, each on a page of its own with the same parts: what the model is and why a modeler would build it this way, its state-transition diagram, its parameters, the code, a result with a plot, and where to go next. They cover a range of diseases and structures, rather than building one model up step by step as the tutorials do. Each page runs as it is.

Short examples

Each of these is one model and one result, and runs in seconds.

Model What it shows
SIR, four ways The four ways of writing a model, which give the same model; the same model as an ODE, two kinds of stochastic model, and agents
SEIR with a realistic infectious period A latent period; an infectious period with Erlang stages against an exponential one
Hospitalization and death A split on entry (who goes to hospital) and competing hazards (death or discharge); severity by age as a Python function, run as compartments and as agents
Cholera with a water reservoir A state that is not people (bacteria in the water), with flows in from and out to outside the model
Age groups and contacts An age-stratified SIR with a contact matrix; the United Kingdom’s population with contacts by setting, and a school closure that removes one setting
Vaccination as a stratification Vaccinated and unvaccinated groups, and a campaign that moves people between them
Cases, hospitalizations, and deaths, fitted to data Outcomes with delays; data made from the model; fitting β with sim.fit()
An STI on a sexual network Transmission per sex act over partnerships; many runs as agents

Case studies

Longer pages, each with more than one model or many runs.

Model What it shows
Checks against theory The final size against the Kermack–McKendrick equation, as an ODE; the chance of a major outbreak against 1 − 1/R0, with 1,500 stochastic runs
Measles in London, three ways He et al. (2010)’s stochastic measles model with school terms and cohort entry: declared with a little code, written as code, and declared with noise; a likelihood of its own, a compiled loop, and a particle filter at the published parameters. About a minute to run
Beyond disease Agent-based models with no disease: wealth that becomes unequal, and birds that flock, with an animation

Models from other frameworks

Each framework that Starsim can import from, from Atomica and EpiModel to odin and summer2, has a page in the Lingua Franca docs with a showcase model written in that framework and in Starsim, and how their results and run times compare; Comparison with other frameworks lists them all.

Library modules

The Starsim library (import starsim.library as ssl) has more examples: diseases (HIV, cholera, malaria, TB, and others), networks (households, space, and theoretical networks), maternal-child health, and health economics. They are illustrative rather than validated, and meant to be copied and adapted.

Scripts in the repository

A few longer examples are kept as scripts in the docs/examples folder of the repository, to read and adapt:

  • An embedding network (networks/embedding.py): pairs people by their closeness in a continuous space of traits.
  • One model in several languages (translations/): the same simple SIS model written in plain Python, Numba, JAX, Julia, and Rust, next to the Starsim version, for comparing their speed.
  • LASER (laser/): a LASER example and its Starsim equivalents, with scripts to time them.