Skip to main content

🦠 SIR Epidemic Simulator

Python Version License Tests Security Tests Status Streamlit Platform

A Complete Epidemic Modeling Suite with 5 Integrated Features


📋 Table of Contents


🔭 Overview

The SIR Epidemic Simulator is a comprehensive epidemic modeling toolkit combining classical compartmental models with modern machine learning. It provides researchers, students, and public health professionals with tools to simulate, analyze, and predict epidemic dynamics.

Key Capabilities

Feature Description
SIR Model Basic Susceptible-Infected-Recovered dynamics
SEIR Model Adds Exposed/incubation compartment
Network Simulation Fake news spread on social graphs
Parameter Optimization Fit models to real-world data
ML Prediction Forecast future cases with XGBoost/Random Forest
Scenario Comparison Evaluate quarantine vs vaccination

🚀 Installation

Prerequisites

  • Python 3.8 or higher
  • pip package manager

Steps

# Clone repository
git clone https://github.com/miladrezanezhad/sir_simulator.git
cd sir_simulator

# Install dependencies
pip install -r requirements.txt

# Verify installation
python -c "import streamlit, numpy, pandas; print('✅ Success!')"

🎮 Quick Start

streamlit run user_interface/app.py

Run CLI

python user_interface/cli.py --beta 0.5 --gamma 0.2 --tmax 100

Run All Tests

python run_all_tests.py

Interactive Menu

python main.py

📁 Project Structure

sir_simulator/
│
├── core_models/              # Core mathematical models
│   ├── sir_model.py          # Basic SIR implementation
│   ├── seir_model.py         # SEIR with exposed compartment
│   └── network_model.py      # Social network spread simulation
│
├── advanced_features/        # Advanced capabilities
│   ├── parameter_optimization.py  # Curve fitting
│   ├── ml_prediction.py           # ML forecasting
│   └── scenario_comparison.py     # Intervention analysis
│
├── user_interface/           # UI applications
│   ├── app.py                # Streamlit dashboard
│   └── cli.py                # Command-line interface
│
├── tests/                    # Test suite (57+ tests)
│   ├── test_seir.py          # SEIR model tests
│   ├── test_network.py       # Network simulation tests
│   ├── test_optimization.py  # Parameter optimization tests
│   ├── test_ml.py            # ML prediction tests
│   ├── test_scenarios.py     # Scenario comparison tests
│   └── security/             # Security test suite
│       ├── test_dos_attack.py
│       ├── test_memory_exhaustion.py
│       ├── test_unicode_attacks.py
│       └── test_xss_prevention.py
│
├── docs/                     # Documentation
│   └── notebook.ipynb        # Educational Jupyter notebook
│
├── screenshots/              # Application screenshots
│   ├── SIR Epidemic Model.png
│   ├── SEIR Model with Exposed Compartment.png
│   ├── Fake News Spread on Social Network.png
│   ├── Parameter Optimization.png
│   ├── Machine Learning Prediction.png
│   ├── Scenario Comparison.png
│   └── dashboard.png
│
├── .github/workflows/        # CI/CD pipelines
│   ├── test.yml              # Test automation
│   └── security.yml          # Security scan pipeline
│
├── config/                   # Configuration files
├── outputs/                  # CSV export folder
│
├── README.md                 # This file
├── TESTING.md                # Testing guide
├── SECURITY_TESTS.md         # Security testing guide
├── LICENSE                   # MIT License
├── requirements.txt     # Python dependencies
├── run_all_tests.py          # Master test runner
└── .gitignore

📊 Usage Guide

1. SIR Model

from core_models.sir_model import run_sir_simulation

df = run_sir_simulation(
    beta=0.5, gamma=0.2,
    S0=990, I0=10, R0=0,
    t_max=100, steps=500
)

2. SEIR Model

from core_models.seir_model import run_seir_simulation

df = run_seir_simulation(
    beta=0.5, sigma=0.2, gamma=0.1,
    S0=990, E0=0, I0=10, R0=0,
    t_max=100, steps=500
)

3. Network Simulation

from core_models.network_model import SocialNetworkSimulator

sim = SocialNetworkSimulator(num_nodes=200, network_type='scale_free')
df = sim.simulate_spread(transmission_prob=0.4, recovery_prob=0.1)

4. Parameter Optimization

from advanced_features.parameter_optimization import ParameterOptimizer

optimizer = ParameterOptimizer(model_type='sir')
results = optimizer.fit(observed_data, t, [990, 10, 0])
print(f"β={results['beta']:.3f}, γ={results['gamma']:.3f}, R0={results['R0']:.3f}")

5. ML Prediction

from advanced_features.ml_prediction import EpidemicPredictor

predictor = EpidemicPredictor(model_type='random_forest')
metrics, predictions, _ = predictor.train(historical_data)
future = predictor.predict_future(historical_data, days=30)

6. Scenario Comparison

from advanced_features.scenario_comparison import ScenarioComparator

comp = ScenarioComparator()
scenarios, metrics = comp.compare_all_scenarios(days=120)
print(metrics)

🧪 Testing

Run all tests (35 unit tests + 22 security tests):

python run_all_tests.py
python -m unittest discover tests/security

Or run individual test files:

python tests/test_seir.py
python tests/test_network.py
python tests/test_optimization.py
python tests/test_ml.py
python tests/test_scenarios.py
python tests/security/test_dos_attack.py

Test Coverage

Module Tests Status
SEIR Model 7 ✅
Network Model 10 ✅
Parameter Optimization 6 ✅
ML Prediction 2 (active) + 2 (skip) ✅
Scenario Comparison 8 ✅
Security (DoS, Memory, Unicode, XSS) 22 ✅
Total 57 ✅ All Passing

For detailed testing documentation, see:


🔒 Security

This project includes comprehensive security testing:

  • ✅ DoS attack prevention
  • ✅ Memory exhaustion protection
  • ✅ Unicode/UTF-8 attack mitigation
  • ✅ XSS prevention for Streamlit dashboard

All security tests pass with no vulnerabilities detected.


📸 Screenshots

SIR Model SEIR Model
SIR SEIR
Network Simulation Parameter Optimization
Network Optimization
ML Prediction Scenario Comparison
ML Scenarios

📊 Streamlit Dashboard

Dashboard


📚 Documentation


🔧 Requirements

numpy>=1.21.0
scipy>=1.7.0
pandas>=1.3.0
matplotlib>=3.4.0
streamlit>=1.20.0
networkx>=2.8
scikit-learn>=1.0.0
xgboost>=1.6.0

Install all dependencies with:

pip install -r requirements.txt

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Please ensure all tests pass before submitting:

python run_all_tests.py
python -m unittest discover tests/security

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


🙏 Acknowledgments

  • Classical SIR/SEIR models from Kermack-McKendrick theory
  • Network science algorithms from NetworkX library
  • Machine learning models from scikit-learn and XGBoost

Built with ❤️ for epidemic modeling and public health research

⬆ Back to Top

Metadata

Release files for sir-epidemic 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sir-epidemic 1.0.1
File Size Uploaded Provenance Actions
sir_epidemic-1.0.1.tar.gz 18.3 kB Without provenance Details for sir_epidemic-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sir-epidemic 1.0.1
File Interpreter ABI Platform Actions
sir_epidemic-1.0.1-py3-none-any.whl Python 3 none any Details for sir_epidemic-1.0.1-py3-none-any.whl

Total release size: 37.5 kB

Release files / sir_epidemic-1.0.1.tar.gz

Download URL sir_epidemic-1.0.1.tar.gz
Size 18.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d6fb1c6810880af752ef894cf0024b2dfb875df2c3ce88d61c50a70728d21221
BLAKE2b-256 checksum
How to use checksums
74f5dcbbf0e9d8c40c69205d2303d8dbd023faaeb0cbedc960a955132dfab5ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / sir_epidemic-1.0.1-py3-none-any.whl

Download URL sir_epidemic-1.0.1-py3-none-any.whl
Size 19.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c1c9ad0760f06e5de3f3a48c371aeb995eb97bb6116f5a0fe94c428cea40c0ad
BLAKE2b-256 checksum
How to use checksums
ed3c69595cf41088831fcd5678dc5db3acc83b52ae47efdac055ef9559479037
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Security for sir-epidemic 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page