minte 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- minte-1.0.0/.gitignore +10 -0
- minte-1.0.0/PKG-INFO +374 -0
- minte-1.0.0/README.md +336 -0
- minte-1.0.0/pyproject.toml +92 -0
minte-1.0.0/.gitignore
ADDED
minte-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: minte
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Malaria Intervention Emulator (MINTe) - Neural network-based malaria scenario predictions
|
|
5
|
+
Project-URL: Homepage, https://github.com/CosmoNaught/minte
|
|
6
|
+
Project-URL: Documentation, https://github.com/CosmoNaught/minte#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/CosmoNaught/minte
|
|
8
|
+
Project-URL: Issues, https://github.com/CosmoNaught/minte/issues
|
|
9
|
+
Author-email: Cosmo Santoni <cosmo.santoni@imperial.ac.uk>
|
|
10
|
+
License: MIT
|
|
11
|
+
Keywords: emulator,malaria,neural-network,public-health,simulation
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: estimint>=1.0.0
|
|
22
|
+
Requires-Dist: joblib>=1.3.0
|
|
23
|
+
Requires-Dist: matplotlib>=3.7.0
|
|
24
|
+
Requires-Dist: numpy>=1.24.0
|
|
25
|
+
Requires-Dist: pandas>=2.0.0
|
|
26
|
+
Requires-Dist: scikit-learn==1.6.1
|
|
27
|
+
Requires-Dist: scipy>=1.10.0
|
|
28
|
+
Requires-Dist: torch>=2.0.0
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: black>=23.0.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: mypy>=1.0.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
33
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
35
|
+
Provides-Extra: xgboost
|
|
36
|
+
Requires-Dist: xgboost>=2.0.0; extra == 'xgboost'
|
|
37
|
+
Description-Content-Type: text/markdown
|
|
38
|
+
|
|
39
|
+
# MINTe - Malaria Intervention Emulator
|
|
40
|
+
|
|
41
|
+
A Python package for neural network-based malaria scenario predictions, enabling rapid evaluation of intervention strategies including ITNs (Insecticide-Treated Nets), IRS (Indoor Residual Spraying), and LSM (Larval Source Management).
|
|
42
|
+
|
|
43
|
+
## Features
|
|
44
|
+
|
|
45
|
+
- **Fast Scenario Predictions**: Run thousands of malaria intervention scenarios in seconds using pre-trained LSTM models
|
|
46
|
+
- **Multiple Predictors**: Predict both prevalence and clinical cases
|
|
47
|
+
- **Flexible Net Types**: Support for various ITN types (pyrethroid-only, PBO, pyrrole, PPF)
|
|
48
|
+
- **Model Caching**: Efficient caching of loaded models for faster subsequent runs
|
|
49
|
+
- **Visualization**: Built-in plotting utilities for results visualization
|
|
50
|
+
- **Web Interface Support**: Lightweight controller for web application integration
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
### Using uv (Recommended)
|
|
55
|
+
|
|
56
|
+
[uv](https://github.com/astral-sh/uv) is a fast Python package manager. Install it first:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# On macOS/Linux
|
|
60
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
61
|
+
|
|
62
|
+
# On Windows
|
|
63
|
+
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Then create a new project and install MINTer:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# Create a new project directory
|
|
70
|
+
mkdir my-malaria-project
|
|
71
|
+
cd my-malaria-project
|
|
72
|
+
|
|
73
|
+
# Initialize a new Python project with uv
|
|
74
|
+
uv init
|
|
75
|
+
|
|
76
|
+
# Add MINTer as a dependency (from local path)
|
|
77
|
+
uv add /path/to/minte
|
|
78
|
+
|
|
79
|
+
# Or if published to PyPI (future):
|
|
80
|
+
# uv add minte
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Development Installation
|
|
84
|
+
|
|
85
|
+
For development, clone the repository and install in editable mode:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Clone the repository
|
|
89
|
+
git clone https://github.com/CosmoNaught/minte.git
|
|
90
|
+
cd minte
|
|
91
|
+
|
|
92
|
+
# Create virtual environment and install with uv
|
|
93
|
+
uv venv
|
|
94
|
+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
|
95
|
+
uv pip install -e ".[dev]"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Using pip
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
pip install minte
|
|
102
|
+
|
|
103
|
+
# Or for development:
|
|
104
|
+
pip install -e ".[dev]"
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Quick Start
|
|
108
|
+
|
|
109
|
+
### Basic Usage
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
import numpy as np
|
|
113
|
+
from minte import run_minter_scenarios
|
|
114
|
+
|
|
115
|
+
# Define a single scenario
|
|
116
|
+
results = run_minter_scenarios(
|
|
117
|
+
res_use=[0.3], # Current resistance level
|
|
118
|
+
py_only=[0.4], # Pyrethroid-only net coverage
|
|
119
|
+
py_pbo=[0.3], # PBO net coverage
|
|
120
|
+
py_pyrrole=[0.2], # Pyrrole net coverage
|
|
121
|
+
py_ppf=[0.1], # PPF net coverage
|
|
122
|
+
prev=[0.25], # Current prevalence
|
|
123
|
+
Q0=[0.92], # Indoor biting proportion
|
|
124
|
+
phi=[0.85], # Bednet usage proportion
|
|
125
|
+
season=[1], # Seasonality indicator
|
|
126
|
+
routine=[0.1], # Routine treatment coverage
|
|
127
|
+
irs=[0.0], # Current IRS coverage
|
|
128
|
+
irs_future=[0.3], # Future IRS coverage
|
|
129
|
+
lsm=[0.0], # LSM coverage
|
|
130
|
+
predictor=["prevalence", "cases"],
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
# Access results
|
|
134
|
+
print(results.prevalence.head())
|
|
135
|
+
print(results.cases.head())
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Running Multiple Scenarios
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
import numpy as np
|
|
142
|
+
from minte import run_minter_scenarios
|
|
143
|
+
|
|
144
|
+
# Define multiple scenarios
|
|
145
|
+
n_scenarios = 100
|
|
146
|
+
results = run_minter_scenarios(
|
|
147
|
+
res_use=np.random.uniform(0.1, 0.8, n_scenarios),
|
|
148
|
+
py_only=np.random.uniform(0, 0.5, n_scenarios),
|
|
149
|
+
py_pbo=np.random.uniform(0, 0.3, n_scenarios),
|
|
150
|
+
py_pyrrole=np.random.uniform(0, 0.2, n_scenarios),
|
|
151
|
+
py_ppf=np.random.uniform(0, 0.1, n_scenarios),
|
|
152
|
+
prev=np.random.uniform(0.1, 0.5, n_scenarios),
|
|
153
|
+
Q0=np.full(n_scenarios, 0.92),
|
|
154
|
+
phi=np.full(n_scenarios, 0.85),
|
|
155
|
+
season=np.ones(n_scenarios),
|
|
156
|
+
routine=np.full(n_scenarios, 0.1),
|
|
157
|
+
irs=np.zeros(n_scenarios),
|
|
158
|
+
irs_future=np.random.uniform(0, 0.5, n_scenarios),
|
|
159
|
+
lsm=np.zeros(n_scenarios),
|
|
160
|
+
scenario_tag=[f"Scenario_{i}" for i in range(n_scenarios)],
|
|
161
|
+
benchmark=True,
|
|
162
|
+
)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Using the Emulator Directly
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
import pandas as pd
|
|
169
|
+
from minte import run_malaria_emulator, create_scenarios
|
|
170
|
+
|
|
171
|
+
# Create scenarios DataFrame
|
|
172
|
+
scenarios = create_scenarios(
|
|
173
|
+
eir=[50, 100, 150],
|
|
174
|
+
dn0_use=[0.5, 0.4, 0.3],
|
|
175
|
+
dn0_future=[0.6, 0.5, 0.4],
|
|
176
|
+
Q0=[0.92, 0.92, 0.92],
|
|
177
|
+
phi_bednets=[0.85, 0.85, 0.85],
|
|
178
|
+
seasonal=[1, 1, 1],
|
|
179
|
+
routine=[0.1, 0.1, 0.1],
|
|
180
|
+
itn_use=[0.6, 0.5, 0.4],
|
|
181
|
+
irs_use=[0.0, 0.0, 0.0],
|
|
182
|
+
itn_future=[0.7, 0.6, 0.5],
|
|
183
|
+
irs_future=[0.3, 0.3, 0.3],
|
|
184
|
+
lsm=[0.0, 0.0, 0.0],
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
# Run emulator
|
|
188
|
+
results = run_malaria_emulator(
|
|
189
|
+
scenarios=scenarios,
|
|
190
|
+
predictor="prevalence",
|
|
191
|
+
benchmark=True,
|
|
192
|
+
)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Visualization
|
|
196
|
+
|
|
197
|
+
```python
|
|
198
|
+
from minte import create_scenario_plots
|
|
199
|
+
|
|
200
|
+
# Create plots from results
|
|
201
|
+
plots = create_scenario_plots(
|
|
202
|
+
results.prevalence,
|
|
203
|
+
output_dir="plots/",
|
|
204
|
+
plot_type="both",
|
|
205
|
+
)
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Web Controller
|
|
209
|
+
|
|
210
|
+
For web applications, use the simplified controller:
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
from minte import run_mintweb_controller
|
|
214
|
+
|
|
215
|
+
results = run_mintweb_controller(
|
|
216
|
+
res_use=[0.3],
|
|
217
|
+
py_only=[0.4],
|
|
218
|
+
py_pbo=[0.3],
|
|
219
|
+
py_pyrrole=[0.2],
|
|
220
|
+
py_ppf=[0.1],
|
|
221
|
+
prev=[0.25],
|
|
222
|
+
Q0=[0.92],
|
|
223
|
+
phi=[0.85],
|
|
224
|
+
season=[1],
|
|
225
|
+
routine=[0.1],
|
|
226
|
+
irs=[0.0],
|
|
227
|
+
irs_future=[0.3],
|
|
228
|
+
lsm=[0.0],
|
|
229
|
+
clean_output=True,
|
|
230
|
+
tabulate=True,
|
|
231
|
+
)
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Model Files
|
|
235
|
+
|
|
236
|
+
The package requires trained model files to run predictions. These should be placed in the `src/minte/models/` directory (or specify a custom path) with the following structure:
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
models/
|
|
240
|
+
├── prevalence/
|
|
241
|
+
│ ├── lstm_best.pt # PyTorch LSTM checkpoint
|
|
242
|
+
│ ├── gru_best.pt # (optional) GRU checkpoint
|
|
243
|
+
│ ├── static_scaler.pkl # sklearn StandardScaler
|
|
244
|
+
│ └── args.json # Training arguments
|
|
245
|
+
└── cases/
|
|
246
|
+
├── lstm_best.pt
|
|
247
|
+
├── gru_best.pt # (optional)
|
|
248
|
+
├── static_scaler.pkl
|
|
249
|
+
└── args.json
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Converting from R Package Files
|
|
253
|
+
|
|
254
|
+
If you have the original R package files, you'll need to:
|
|
255
|
+
|
|
256
|
+
1. **Model files (`.pt`, `.pkl`)**: These are already Python-compatible and can be copied directly.
|
|
257
|
+
|
|
258
|
+
2. **RDS data files** (e.g., `itn_dn0.rds`): Convert to CSV using one of these methods:
|
|
259
|
+
|
|
260
|
+
**Method 1: Using the included script (requires rpy2)**
|
|
261
|
+
```bash
|
|
262
|
+
pip install rpy2
|
|
263
|
+
python scripts/convert_rds.py path/to/itn_dn0.rds src/minte/data/itn_dn0.csv
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
**Method 2: Using R directly**
|
|
267
|
+
```r
|
|
268
|
+
# In R console:
|
|
269
|
+
data <- readRDS("path/to/itn_dn0.rds")
|
|
270
|
+
write.csv(data, "src/minte/data/itn_dn0.csv", row.names = FALSE)
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Expected Data File Locations
|
|
274
|
+
|
|
275
|
+
```
|
|
276
|
+
src/minte/
|
|
277
|
+
├── data/
|
|
278
|
+
│ └── itn_dn0.csv # ITN parameters (resistance vs dn0)
|
|
279
|
+
└── models/
|
|
280
|
+
├── prevalence/
|
|
281
|
+
│ └── ...
|
|
282
|
+
└── cases/
|
|
283
|
+
└── ...
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## Configuration
|
|
287
|
+
|
|
288
|
+
### Model Caching
|
|
289
|
+
|
|
290
|
+
Models are cached by default for faster subsequent runs:
|
|
291
|
+
|
|
292
|
+
```python
|
|
293
|
+
from minte import preload_all_models, clear_cache, get_cache_info
|
|
294
|
+
|
|
295
|
+
# Preload all models
|
|
296
|
+
preload_all_models(verbose=True)
|
|
297
|
+
|
|
298
|
+
# Check what's cached
|
|
299
|
+
print(get_cache_info())
|
|
300
|
+
|
|
301
|
+
# Clear cache if needed
|
|
302
|
+
clear_cache()
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### Device Selection
|
|
306
|
+
|
|
307
|
+
By default, the package uses CUDA if available:
|
|
308
|
+
|
|
309
|
+
```python
|
|
310
|
+
from minte import load_emulator_models
|
|
311
|
+
|
|
312
|
+
# Force CPU
|
|
313
|
+
models = load_emulator_models(device="cpu")
|
|
314
|
+
|
|
315
|
+
# Force CUDA
|
|
316
|
+
models = load_emulator_models(device="cuda")
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## API Reference
|
|
320
|
+
|
|
321
|
+
### Main Functions
|
|
322
|
+
|
|
323
|
+
- `run_minter_scenarios()`: Main entry point for running intervention scenarios
|
|
324
|
+
- `run_malaria_emulator()`: Direct emulator interface for scenario predictions
|
|
325
|
+
- `run_mintweb_controller()`: Simplified web interface controller
|
|
326
|
+
- `create_scenario_plots()`: Create visualizations from results
|
|
327
|
+
|
|
328
|
+
### Utility Functions
|
|
329
|
+
|
|
330
|
+
- `calculate_overall_dn0()`: Calculate net effectiveness from resistance and coverage
|
|
331
|
+
- `preload_all_models()`: Pre-load models into cache
|
|
332
|
+
- `create_scenarios()`: Helper to create scenarios DataFrame
|
|
333
|
+
|
|
334
|
+
## Development
|
|
335
|
+
|
|
336
|
+
### Running Tests
|
|
337
|
+
|
|
338
|
+
```bash
|
|
339
|
+
uv run pytest
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### Code Formatting
|
|
343
|
+
|
|
344
|
+
```bash
|
|
345
|
+
uv run black src/
|
|
346
|
+
uv run ruff check src/
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### Type Checking
|
|
350
|
+
|
|
351
|
+
```bash
|
|
352
|
+
uv run mypy src/
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
## License
|
|
356
|
+
|
|
357
|
+
MIT License - see LICENSE file for details.
|
|
358
|
+
|
|
359
|
+
## Citation
|
|
360
|
+
|
|
361
|
+
If you use MINTer in your research, please cite:
|
|
362
|
+
|
|
363
|
+
```bibtex
|
|
364
|
+
@software{minte,
|
|
365
|
+
title = {MINTer: Malaria Intervention Emulator},
|
|
366
|
+
author = {Cosmo Santoni},
|
|
367
|
+
year = {2025},
|
|
368
|
+
url = {https://github.com/CosmoNaught/minte}
|
|
369
|
+
}
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
## Contributing
|
|
373
|
+
|
|
374
|
+
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
|
minte-1.0.0/README.md
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
# MINTe - Malaria Intervention Emulator
|
|
2
|
+
|
|
3
|
+
A Python package for neural network-based malaria scenario predictions, enabling rapid evaluation of intervention strategies including ITNs (Insecticide-Treated Nets), IRS (Indoor Residual Spraying), and LSM (Larval Source Management).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Fast Scenario Predictions**: Run thousands of malaria intervention scenarios in seconds using pre-trained LSTM models
|
|
8
|
+
- **Multiple Predictors**: Predict both prevalence and clinical cases
|
|
9
|
+
- **Flexible Net Types**: Support for various ITN types (pyrethroid-only, PBO, pyrrole, PPF)
|
|
10
|
+
- **Model Caching**: Efficient caching of loaded models for faster subsequent runs
|
|
11
|
+
- **Visualization**: Built-in plotting utilities for results visualization
|
|
12
|
+
- **Web Interface Support**: Lightweight controller for web application integration
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
### Using uv (Recommended)
|
|
17
|
+
|
|
18
|
+
[uv](https://github.com/astral-sh/uv) is a fast Python package manager. Install it first:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# On macOS/Linux
|
|
22
|
+
curl -LsSf https://astral.sh/uv/install.sh | sh
|
|
23
|
+
|
|
24
|
+
# On Windows
|
|
25
|
+
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Then create a new project and install MINTer:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# Create a new project directory
|
|
32
|
+
mkdir my-malaria-project
|
|
33
|
+
cd my-malaria-project
|
|
34
|
+
|
|
35
|
+
# Initialize a new Python project with uv
|
|
36
|
+
uv init
|
|
37
|
+
|
|
38
|
+
# Add MINTer as a dependency (from local path)
|
|
39
|
+
uv add /path/to/minte
|
|
40
|
+
|
|
41
|
+
# Or if published to PyPI (future):
|
|
42
|
+
# uv add minte
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Development Installation
|
|
46
|
+
|
|
47
|
+
For development, clone the repository and install in editable mode:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Clone the repository
|
|
51
|
+
git clone https://github.com/CosmoNaught/minte.git
|
|
52
|
+
cd minte
|
|
53
|
+
|
|
54
|
+
# Create virtual environment and install with uv
|
|
55
|
+
uv venv
|
|
56
|
+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
|
57
|
+
uv pip install -e ".[dev]"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Using pip
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install minte
|
|
64
|
+
|
|
65
|
+
# Or for development:
|
|
66
|
+
pip install -e ".[dev]"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Quick Start
|
|
70
|
+
|
|
71
|
+
### Basic Usage
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import numpy as np
|
|
75
|
+
from minte import run_minter_scenarios
|
|
76
|
+
|
|
77
|
+
# Define a single scenario
|
|
78
|
+
results = run_minter_scenarios(
|
|
79
|
+
res_use=[0.3], # Current resistance level
|
|
80
|
+
py_only=[0.4], # Pyrethroid-only net coverage
|
|
81
|
+
py_pbo=[0.3], # PBO net coverage
|
|
82
|
+
py_pyrrole=[0.2], # Pyrrole net coverage
|
|
83
|
+
py_ppf=[0.1], # PPF net coverage
|
|
84
|
+
prev=[0.25], # Current prevalence
|
|
85
|
+
Q0=[0.92], # Indoor biting proportion
|
|
86
|
+
phi=[0.85], # Bednet usage proportion
|
|
87
|
+
season=[1], # Seasonality indicator
|
|
88
|
+
routine=[0.1], # Routine treatment coverage
|
|
89
|
+
irs=[0.0], # Current IRS coverage
|
|
90
|
+
irs_future=[0.3], # Future IRS coverage
|
|
91
|
+
lsm=[0.0], # LSM coverage
|
|
92
|
+
predictor=["prevalence", "cases"],
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
# Access results
|
|
96
|
+
print(results.prevalence.head())
|
|
97
|
+
print(results.cases.head())
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Running Multiple Scenarios
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
import numpy as np
|
|
104
|
+
from minte import run_minter_scenarios
|
|
105
|
+
|
|
106
|
+
# Define multiple scenarios
|
|
107
|
+
n_scenarios = 100
|
|
108
|
+
results = run_minter_scenarios(
|
|
109
|
+
res_use=np.random.uniform(0.1, 0.8, n_scenarios),
|
|
110
|
+
py_only=np.random.uniform(0, 0.5, n_scenarios),
|
|
111
|
+
py_pbo=np.random.uniform(0, 0.3, n_scenarios),
|
|
112
|
+
py_pyrrole=np.random.uniform(0, 0.2, n_scenarios),
|
|
113
|
+
py_ppf=np.random.uniform(0, 0.1, n_scenarios),
|
|
114
|
+
prev=np.random.uniform(0.1, 0.5, n_scenarios),
|
|
115
|
+
Q0=np.full(n_scenarios, 0.92),
|
|
116
|
+
phi=np.full(n_scenarios, 0.85),
|
|
117
|
+
season=np.ones(n_scenarios),
|
|
118
|
+
routine=np.full(n_scenarios, 0.1),
|
|
119
|
+
irs=np.zeros(n_scenarios),
|
|
120
|
+
irs_future=np.random.uniform(0, 0.5, n_scenarios),
|
|
121
|
+
lsm=np.zeros(n_scenarios),
|
|
122
|
+
scenario_tag=[f"Scenario_{i}" for i in range(n_scenarios)],
|
|
123
|
+
benchmark=True,
|
|
124
|
+
)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Using the Emulator Directly
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
import pandas as pd
|
|
131
|
+
from minte import run_malaria_emulator, create_scenarios
|
|
132
|
+
|
|
133
|
+
# Create scenarios DataFrame
|
|
134
|
+
scenarios = create_scenarios(
|
|
135
|
+
eir=[50, 100, 150],
|
|
136
|
+
dn0_use=[0.5, 0.4, 0.3],
|
|
137
|
+
dn0_future=[0.6, 0.5, 0.4],
|
|
138
|
+
Q0=[0.92, 0.92, 0.92],
|
|
139
|
+
phi_bednets=[0.85, 0.85, 0.85],
|
|
140
|
+
seasonal=[1, 1, 1],
|
|
141
|
+
routine=[0.1, 0.1, 0.1],
|
|
142
|
+
itn_use=[0.6, 0.5, 0.4],
|
|
143
|
+
irs_use=[0.0, 0.0, 0.0],
|
|
144
|
+
itn_future=[0.7, 0.6, 0.5],
|
|
145
|
+
irs_future=[0.3, 0.3, 0.3],
|
|
146
|
+
lsm=[0.0, 0.0, 0.0],
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
# Run emulator
|
|
150
|
+
results = run_malaria_emulator(
|
|
151
|
+
scenarios=scenarios,
|
|
152
|
+
predictor="prevalence",
|
|
153
|
+
benchmark=True,
|
|
154
|
+
)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Visualization
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
from minte import create_scenario_plots
|
|
161
|
+
|
|
162
|
+
# Create plots from results
|
|
163
|
+
plots = create_scenario_plots(
|
|
164
|
+
results.prevalence,
|
|
165
|
+
output_dir="plots/",
|
|
166
|
+
plot_type="both",
|
|
167
|
+
)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Web Controller
|
|
171
|
+
|
|
172
|
+
For web applications, use the simplified controller:
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
from minte import run_mintweb_controller
|
|
176
|
+
|
|
177
|
+
results = run_mintweb_controller(
|
|
178
|
+
res_use=[0.3],
|
|
179
|
+
py_only=[0.4],
|
|
180
|
+
py_pbo=[0.3],
|
|
181
|
+
py_pyrrole=[0.2],
|
|
182
|
+
py_ppf=[0.1],
|
|
183
|
+
prev=[0.25],
|
|
184
|
+
Q0=[0.92],
|
|
185
|
+
phi=[0.85],
|
|
186
|
+
season=[1],
|
|
187
|
+
routine=[0.1],
|
|
188
|
+
irs=[0.0],
|
|
189
|
+
irs_future=[0.3],
|
|
190
|
+
lsm=[0.0],
|
|
191
|
+
clean_output=True,
|
|
192
|
+
tabulate=True,
|
|
193
|
+
)
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Model Files
|
|
197
|
+
|
|
198
|
+
The package requires trained model files to run predictions. These should be placed in the `src/minte/models/` directory (or specify a custom path) with the following structure:
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
models/
|
|
202
|
+
├── prevalence/
|
|
203
|
+
│ ├── lstm_best.pt # PyTorch LSTM checkpoint
|
|
204
|
+
│ ├── gru_best.pt # (optional) GRU checkpoint
|
|
205
|
+
│ ├── static_scaler.pkl # sklearn StandardScaler
|
|
206
|
+
│ └── args.json # Training arguments
|
|
207
|
+
└── cases/
|
|
208
|
+
├── lstm_best.pt
|
|
209
|
+
├── gru_best.pt # (optional)
|
|
210
|
+
├── static_scaler.pkl
|
|
211
|
+
└── args.json
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Converting from R Package Files
|
|
215
|
+
|
|
216
|
+
If you have the original R package files, you'll need to:
|
|
217
|
+
|
|
218
|
+
1. **Model files (`.pt`, `.pkl`)**: These are already Python-compatible and can be copied directly.
|
|
219
|
+
|
|
220
|
+
2. **RDS data files** (e.g., `itn_dn0.rds`): Convert to CSV using one of these methods:
|
|
221
|
+
|
|
222
|
+
**Method 1: Using the included script (requires rpy2)**
|
|
223
|
+
```bash
|
|
224
|
+
pip install rpy2
|
|
225
|
+
python scripts/convert_rds.py path/to/itn_dn0.rds src/minte/data/itn_dn0.csv
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
**Method 2: Using R directly**
|
|
229
|
+
```r
|
|
230
|
+
# In R console:
|
|
231
|
+
data <- readRDS("path/to/itn_dn0.rds")
|
|
232
|
+
write.csv(data, "src/minte/data/itn_dn0.csv", row.names = FALSE)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Expected Data File Locations
|
|
236
|
+
|
|
237
|
+
```
|
|
238
|
+
src/minte/
|
|
239
|
+
├── data/
|
|
240
|
+
│ └── itn_dn0.csv # ITN parameters (resistance vs dn0)
|
|
241
|
+
└── models/
|
|
242
|
+
├── prevalence/
|
|
243
|
+
│ └── ...
|
|
244
|
+
└── cases/
|
|
245
|
+
└── ...
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Configuration
|
|
249
|
+
|
|
250
|
+
### Model Caching
|
|
251
|
+
|
|
252
|
+
Models are cached by default for faster subsequent runs:
|
|
253
|
+
|
|
254
|
+
```python
|
|
255
|
+
from minte import preload_all_models, clear_cache, get_cache_info
|
|
256
|
+
|
|
257
|
+
# Preload all models
|
|
258
|
+
preload_all_models(verbose=True)
|
|
259
|
+
|
|
260
|
+
# Check what's cached
|
|
261
|
+
print(get_cache_info())
|
|
262
|
+
|
|
263
|
+
# Clear cache if needed
|
|
264
|
+
clear_cache()
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Device Selection
|
|
268
|
+
|
|
269
|
+
By default, the package uses CUDA if available:
|
|
270
|
+
|
|
271
|
+
```python
|
|
272
|
+
from minte import load_emulator_models
|
|
273
|
+
|
|
274
|
+
# Force CPU
|
|
275
|
+
models = load_emulator_models(device="cpu")
|
|
276
|
+
|
|
277
|
+
# Force CUDA
|
|
278
|
+
models = load_emulator_models(device="cuda")
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## API Reference
|
|
282
|
+
|
|
283
|
+
### Main Functions
|
|
284
|
+
|
|
285
|
+
- `run_minter_scenarios()`: Main entry point for running intervention scenarios
|
|
286
|
+
- `run_malaria_emulator()`: Direct emulator interface for scenario predictions
|
|
287
|
+
- `run_mintweb_controller()`: Simplified web interface controller
|
|
288
|
+
- `create_scenario_plots()`: Create visualizations from results
|
|
289
|
+
|
|
290
|
+
### Utility Functions
|
|
291
|
+
|
|
292
|
+
- `calculate_overall_dn0()`: Calculate net effectiveness from resistance and coverage
|
|
293
|
+
- `preload_all_models()`: Pre-load models into cache
|
|
294
|
+
- `create_scenarios()`: Helper to create scenarios DataFrame
|
|
295
|
+
|
|
296
|
+
## Development
|
|
297
|
+
|
|
298
|
+
### Running Tests
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
uv run pytest
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### Code Formatting
|
|
305
|
+
|
|
306
|
+
```bash
|
|
307
|
+
uv run black src/
|
|
308
|
+
uv run ruff check src/
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### Type Checking
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
uv run mypy src/
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
## License
|
|
318
|
+
|
|
319
|
+
MIT License - see LICENSE file for details.
|
|
320
|
+
|
|
321
|
+
## Citation
|
|
322
|
+
|
|
323
|
+
If you use MINTer in your research, please cite:
|
|
324
|
+
|
|
325
|
+
```bibtex
|
|
326
|
+
@software{minte,
|
|
327
|
+
title = {MINTer: Malaria Intervention Emulator},
|
|
328
|
+
author = {Cosmo Santoni},
|
|
329
|
+
year = {2025},
|
|
330
|
+
url = {https://github.com/CosmoNaught/minte}
|
|
331
|
+
}
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
## Contributing
|
|
335
|
+
|
|
336
|
+
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "minte"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
description = "Malaria Intervention Emulator (MINTe) - Neural network-based malaria scenario predictions"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
license = { text = "MIT" }
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Cosmo Santoni", email = "cosmo.santoni@imperial.ac.uk" }
|
|
10
|
+
]
|
|
11
|
+
keywords = ["malaria", "simulation", "emulator", "neural-network", "public-health"]
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 4 - Beta",
|
|
14
|
+
"Intended Audience :: Science/Research",
|
|
15
|
+
"License :: OSI Approved :: MIT License",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3.10",
|
|
18
|
+
"Programming Language :: Python :: 3.11",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Topic :: Scientific/Engineering :: Bio-Informatics",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
dependencies = [
|
|
24
|
+
"numpy>=1.24.0",
|
|
25
|
+
"pandas>=2.0.0",
|
|
26
|
+
"torch>=2.0.0",
|
|
27
|
+
"scikit-learn==1.6.1",
|
|
28
|
+
"matplotlib>=3.7.0",
|
|
29
|
+
"scipy>=1.10.0",
|
|
30
|
+
"joblib>=1.3.0",
|
|
31
|
+
"estimint>=1.0.0",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
dev = [
|
|
36
|
+
"pytest>=7.0.0",
|
|
37
|
+
"pytest-cov>=4.0.0",
|
|
38
|
+
"black>=23.0.0",
|
|
39
|
+
"ruff>=0.1.0",
|
|
40
|
+
"mypy>=1.0.0",
|
|
41
|
+
]
|
|
42
|
+
xgboost = [
|
|
43
|
+
"xgboost>=2.0.0",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
[project.urls]
|
|
47
|
+
Homepage = "https://github.com/CosmoNaught/minte"
|
|
48
|
+
Documentation = "https://github.com/CosmoNaught/minte#readme"
|
|
49
|
+
Repository = "https://github.com/CosmoNaught/minte"
|
|
50
|
+
Issues = "https://github.com/CosmoNaught/minte/issues"
|
|
51
|
+
|
|
52
|
+
[build-system]
|
|
53
|
+
requires = ["hatchling"]
|
|
54
|
+
build-backend = "hatchling.build"
|
|
55
|
+
|
|
56
|
+
[tool.hatch.build.targets.wheel]
|
|
57
|
+
packages = ["src/minte"]
|
|
58
|
+
|
|
59
|
+
[tool.hatch.build.targets.wheel.sources]
|
|
60
|
+
"src" = ""
|
|
61
|
+
|
|
62
|
+
[tool.hatch.build]
|
|
63
|
+
include = [
|
|
64
|
+
"src/minte/**/*.py",
|
|
65
|
+
"src/minte/**/*.csv",
|
|
66
|
+
"src/minte/**/*.json",
|
|
67
|
+
"src/minte/**/*.pkl",
|
|
68
|
+
"src/minte/**/*.pt",
|
|
69
|
+
"src/minte/py.typed",
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
[tool.ruff]
|
|
73
|
+
line-length = 100
|
|
74
|
+
target-version = "py310"
|
|
75
|
+
|
|
76
|
+
[tool.ruff.lint]
|
|
77
|
+
select = ["E", "F", "W", "I", "UP", "B", "C4"]
|
|
78
|
+
ignore = ["E501"]
|
|
79
|
+
|
|
80
|
+
[tool.black]
|
|
81
|
+
line-length = 100
|
|
82
|
+
target-version = ["py310", "py311", "py312"]
|
|
83
|
+
|
|
84
|
+
[tool.mypy]
|
|
85
|
+
python_version = "3.10"
|
|
86
|
+
warn_return_any = true
|
|
87
|
+
warn_unused_ignores = true
|
|
88
|
+
ignore_missing_imports = true
|
|
89
|
+
|
|
90
|
+
[tool.pytest.ini_options]
|
|
91
|
+
testpaths = ["tests"]
|
|
92
|
+
python_files = ["test_*.py"]
|