Skip to main content

A complete epidemic modeling suite with SIR/SEIR models, network simulation, ML prediction, and Streamlit dashboard

Project description

๐Ÿฆ  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

Launch Web Dashboard (Recommended)

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sir_epidemic_simulator_milad-1.0.0.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sir_epidemic_simulator_milad-1.0.0-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file sir_epidemic_simulator_milad-1.0.0.tar.gz.

File metadata

File hashes

Hashes for sir_epidemic_simulator_milad-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8eb46a5bb11b79dc73b26ef41feb434f33e0ebfdf20ae777baba6c29b6a13365
MD5 f5e622e88c4972dc05cd2cdcc3d3db06
BLAKE2b-256 e75e8c26155a422ccb4b163ea1b3a0fbd9e2b25f20ba815624db973c9815d638

See more details on using hashes here.

File details

Details for the file sir_epidemic_simulator_milad-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sir_epidemic_simulator_milad-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2f3402b003e30b9487abc09af88e78b99afdca875fb96f011592b989cd2de79a
MD5 4432fce7392b7322bf8809c765848465
BLAKE2b-256 082414e4975d208bb6b47b4d1d6745b9ec9a3083a58554c09b9ade2deff46b2e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page