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¶
Getting Started:
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:
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 susceptibility
- 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)
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: