Epimodels

Epimodels is a Python library of mathematical models for epidemiology, designed for simulation studies and parameter inference. It contains deterministic models in both continuous (ODE-based) and discrete (difference equation) time, stochastic CTMC and network models, SDE extensions, a comprehensive fitting and Bayesian inference framework, symbolic analysis tools, Rt estimation, and multiple solver backends.

Note

This library is under active development. Contributions are welcome.

Installation

pip install epimodels

Optional extras:

pip install epimodels[plot]       # matplotlib plotting
pip install epimodels[dataframe]  # pandas DataFrame support
pip install epimodels[jax]        # diffrax/JAX GPU solvers and SDEs
pip install epimodels[network]    # network models (networkx)
pip install epimodels[yaml]       # YAML model files

Quick Start

from epimodels.continuous import SIR

model = SIR()
model([1000, 1, 0], [0, 50], 1001, {'beta': 0.3, 'gamma': 0.1})

print(f"R0 = {model.R0}")  # Basic reproduction number
print(model.summary())      # Epidemic statistics
model.plot_traces()         # Plot results

Parameter Fitting

The sugar API fits any model in one call, either by maximum likelihood or Bayesian inference:

from epimodels.continuous import SIR

model = SIR()
result = model.fit(
    {"I": [1, 3, 8, 20, 50, 80, 60]},
    times=[0, 1, 2, 3, 5, 7, 10],
    params_to_fit={"beta": (0.1, 5.0), "gamma": (0.01, 1.0)},
    total_population=10000,
)
print(result.best_params)

Contents

Getting Started:

Examples:

API Overview

Solvers

ODE Solvers (Unified interface)
  • ScipySolver - Scipy-based solver (CPU)

  • DiffraxSolver - JAX-accelerated solver (GPU)

CTMC Solvers (Stochastic simulation)
  • GillespieSolver - Gillespie Direct Method (SSA)

Model Classes

Continuous Models (ODE-based)
  • SIR - Susceptible-Infectious-Removed

  • SIS - Susceptible-Infectious-Susceptible

  • SIRS - Susceptible-Infectious-Removed-Susceptible

  • SEIR - Susceptible-Exposed-Infectious-Removed

  • SEQIAHR - COVID-19 model with quarantine

  • Dengue4Strain - 4-strain dengue model

  • SIRSEI - Malaria vector-host with climate forcing

  • SIRSEIData - Malaria with real climate data

  • SEIRS_SEI - Vector-borne with environmental effects

  • SIR2Strain - Two-strain SIR with cross-immunity

  • SIR1D - 1D reduced SIR (beta/gamma tracking)

  • SISLogistic - SIS with logistic population growth

  • SIRSNonAutonomous - SIRS with time-dependent parameters

  • NeipelHeterogeneousSIR - Heterogeneous susceptibility

  • EbolaSEIHFRV - Ebola with hospital and funeral transmission

Discrete Models (Difference equations)
  • SIR - Susceptible-Infectious-Removed

  • SIS - Susceptible-Infectious-Susceptible

  • SEIR - Susceptible-Exposed-Infectious-Removed

  • SEIS - Susceptible-Exposed-Infectious-Susceptible

  • SIRS - Susceptible-Infectious-Removed-Susceptible

  • SEQIAHR - COVID-19 model with quarantine

  • Influenza - Age-structured influenza model

  • SIpRpS - Partial immunity waning

  • SEIpRpS - Exposed + partial immunity

  • SIpR - Secondary infections from recovered

  • SEIpR - Exposed + secondary infections from R

Stochastic Models (CTMC / Gillespie SSA)
  • SIR - Stochastic SIR

  • SIS - Stochastic SIS

  • SIRS - Stochastic SIRS (waning immunity)

  • SEIR - Stochastic SEIR (with latent period)

Network Models (event-driven, graph-based)
  • NetworkSIR - SIR on networkx graphs, adjacency dicts or matrices

  • NetworkSIS - SIS on networks (infection can become endemic)

Stochastic Differential Equations
  • SDEModel - Demographic-noise SDE wrapper for any continuous model

Analysis and Inference Tools

  • estimate_rt() - Time-varying reproduction number from incidence (Cori/EpiEstim)

  • SDEModel - SDE simulation

  • simulate_ensemble() - Parameter-uncertainty ensembles

  • TraceEnsemble - Ensemble results with quantile bands

  • Intervention - Time-bounded parameter change

  • Scenario - Model + parameters + interventions

  • ScenarioComparison - Side-by-side scenario runs

  • fit_model_bayesian() - Bayesian (DE-MCMC) inference

  • BayesianFitResult - Posterior samples, credible intervals, ArviZ export

Registry and Serialization

Fitting Module

  • ModelFitter - Full-featured parameter fitter

  • fit_model() - Convenience fitting function

  • Dataset - Observed data container

  • ScipyOptimizer - Scipy-based optimizer

  • JAXOptimizer - Projected gradient optimizer

  • MultiStartOptimizer - Multi-start optimizer

Common Methods

All models inherit from BaseModel and share these methods:

Stochastic models (CTMC) also provide:

Indices and tables