A complete epidemic modeling suite with SIR/SEIR models, network simulation, ML prediction, and Streamlit dashboard
Project description
๐ฆ SIR Epidemic Simulator
A Complete Epidemic Modeling Suite with 5 Integrated Features
๐ Table of Contents
- Overview
- Features
- Installation
- Quick Start
- Project Structure
- Usage Guide
- Testing
- Security
- Screenshots
- Documentation
- License
๐ญ 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:
- Testing Guide - Complete testing documentation
- Security Testing Guide - Security test suite documentation
๐ 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 |
|---|---|
| Network Simulation | Parameter Optimization |
|---|---|
| ML Prediction | Scenario Comparison |
|---|---|
๐ Streamlit Dashboard
๐ Documentation
- Testing Guide - How to run and understand tests
- Security Testing Guide - Security test suite documentation
- Jupyter Notebook - Interactive educational notebook
๐ง 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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sir_epidemic-1.0.1.tar.gz.
File metadata
- Download URL: sir_epidemic-1.0.1.tar.gz
- Upload date:
- Size: 18.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6fb1c6810880af752ef894cf0024b2dfb875df2c3ce88d61c50a70728d21221
|
|
| MD5 |
c48fa15a37dd51cb1912ea9f70bb5917
|
|
| BLAKE2b-256 |
74f5dcbbf0e9d8c40c69205d2303d8dbd023faaeb0cbedc960a955132dfab5ec
|
File details
Details for the file sir_epidemic-1.0.1-py3-none-any.whl.
File metadata
- Download URL: sir_epidemic-1.0.1-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1c9ad0760f06e5de3f3a48c371aeb995eb97bb6116f5a0fe94c428cea40c0ad
|
|
| MD5 |
7bd441de6a5a6369d19877d7a1f27dee
|
|
| BLAKE2b-256 |
ed3c69595cf41088831fcd5678dc5db3acc83b52ae47efdac055ef9559479037
|