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:
- Getting Started
- Model Overview
- Custom Models
- Choosing a model family
- A custom ODE model
- Symbolic analysis of your model
- A custom discrete-time model
- A custom stochastic (CTMC) model
- A custom network model
- A custom SDE
- Registering and sharing custom models
- Rich validation for custom models
- Analyses on your custom model
- Pitfalls and tips
- References
- Solvers
- Parameter Validation System Implementation Guide
- Model Fitting
- Bayesian Inference
- Stochastic CTMC Models
- Stochastic Differential Equation Models
- Network Models
- Scenario Analysis: Interventions and Ensembles
- Rt Estimation
- Phase Space Analysis
- Model Registry
- Saving and Loading Models
- VFGen XML Exporter
Examples:
- Simulating Continuous models
- Stochastic CTMC Models
- 1. Running a Single Replicate
- 2. Multiple Replicates and Uncertainty Quantification
- 3. Accessing Results
- 4. Summary Statistics
- 5. Quantiles and Variance
- 6. Event Tracking
- 7. Comparison with Deterministic ODE Model
- 8. Other Stochastic Models
- 9. Exporting Results
- 10. Reproducibility
- 11. Model Properties
- Simulating Discrete models
- API Features
- Phase Space Analysis Tools
- Model Fitting Tutorial
- Parameter Inference for Time-Dependent SIRS Model
- SIRS Autonomous Model with Time-Dependent Parameters
- Neipel Heterogeneous SIR Model Example
- Validation Framework Tutorial
- Advanced Analytical Features
Reference:
About:
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-RemovedSIS- Susceptible-Infectious-SusceptibleSIRS- Susceptible-Infectious-Removed-SusceptibleSEIR- Susceptible-Exposed-Infectious-RemovedSEQIAHR- COVID-19 model with quarantineDengue4Strain- 4-strain dengue modelSIRSEI- Malaria vector-host with climate forcingSIRSEIData- Malaria with real climate dataSEIRS_SEI- Vector-borne with environmental effectsSIR2Strain- Two-strain SIR with cross-immunitySIR1D- 1D reduced SIR (beta/gamma tracking)SISLogistic- SIS with logistic population growthSIRSNonAutonomous- SIRS with time-dependent parametersNeipelHeterogeneousSIR- Heterogeneous susceptibilityEbolaSEIHFRV- Ebola with hospital and funeral transmission
- Discrete Models (Difference equations)
SIR- Susceptible-Infectious-RemovedSIS- Susceptible-Infectious-SusceptibleSEIR- Susceptible-Exposed-Infectious-RemovedSEIS- Susceptible-Exposed-Infectious-SusceptibleSIRS- Susceptible-Infectious-Removed-SusceptibleSEQIAHR- COVID-19 model with quarantineInfluenza- Age-structured influenza modelSIpRpS- Partial immunity waningSEIpRpS- Exposed + partial immunitySIpR- Secondary infections from recoveredSEIpR- Exposed + secondary infections from R
- Stochastic Models (CTMC / Gillespie SSA)
SIR- Stochastic SIRSIS- Stochastic SISSIRS- Stochastic SIRS (waning immunity)SEIR- Stochastic SEIR (with latent period)
- Network Models (event-driven, graph-based)
NetworkSIR- SIR on networkx graphs, adjacency dicts or matricesNetworkSIS- 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¶
get_model()- Look up models by name and family
list_models()- List registered models
save_model()/load_model()- JSON/YAML model files
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: