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, along with a comprehensive fitting framework, symbolic analysis tools, and multiple solver backends.

Note

This library is under active development. Contributions are welcome.

Installation

pip install epimodels

For pandas DataFrame support:

pip install epimodels[dataframe]

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

from epimodels.continuous import SIR
from epimodels.fitting import fit_model, Dataset

model = SIR()
dataset = Dataset()
dataset.add_series("I", times=[0, 1, 2, 3, 5, 7, 10], values=[1, 3, 8, 20, 50, 80, 60])

result = fit_model(
    model, dataset,
    params={"beta": (0.1, 5.0), "gamma": (0.01, 1.0)},
    initial_conditions=[1000, 1, 0],
    time_range=[0, 10],
)
print(result.best_params)

Contents

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

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)

Fitting Module

  • ModelFitter - Full-featured parameter fitter

  • fit_model() - Convenience fitting function

  • Dataset - Observed data container

  • ScipyOptimizer - Scipy-based optimizer

  • JAXOptimizer - JAX/GPU optimizer

  • MultiStartOptimizer - Multi-start optimizer

Common Methods

All models inherit from BaseModel and share these methods:

Stochastic models (CTMC) also provide:

Indices and tables