absternator commited on
Commit
3afc149
·
verified ·
1 Parent(s): 60da385

update readme with preds

Browse files
Files changed (1) hide show
  1. README.md +86 -22
README.md CHANGED
@@ -53,7 +53,7 @@ They are not intended for direct clinical decision-making or for use on real-wor
53
  Install StateMINT and the Hugging Face Hub client:
54
 
55
  ```bash
56
- pip install stateMINT huggingface-hub
57
  ```
58
 
59
  If installing from source:
@@ -72,13 +72,13 @@ Recommended high-level API:
72
  ```python
73
  from stateMINT.model import Mamba2Regressor
74
 
75
- model = Mamba2Regressor.from_pretrained(
76
  "dide-ic/stateMINT",
77
  predictor="prevalence",
78
  revision="v1.0.0",
79
  )
80
 
81
- model.eval()
82
  ```
83
 
84
  To load the cases model:
@@ -86,37 +86,110 @@ To load the cases model:
86
  ```python
87
  from stateMINT.model import Mamba2Regressor
88
 
89
- model = Mamba2Regressor.from_pretrained(
90
  "dide-ic/stateMINT",
91
  predictor="cases",
92
  revision="v1.0.0",
93
  )
94
 
95
- model.eval()
96
  ```
97
 
98
- If you need the preprocessing metadata as well:
 
 
 
 
 
 
 
 
 
 
99
 
100
  ```python
 
 
101
  artifact = Mamba2Regressor.from_pretrained(
102
  "dide-ic/stateMINT",
103
  predictor="prevalence",
104
  revision="v1.0.0",
105
- return_artifact=True,
106
  )
107
 
108
- model = artifact.model
109
- preprocessing = artifact.preprocessing
110
- scaler = artifact.scaler
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  ```
112
 
113
- The model expects already-prepared arrays with shape:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
 
115
  ```text
116
  (batch, time, input_size)
117
  ```
118
 
119
- For the exported artifacts in this repository, `input_size` is `15`.
 
 
 
 
 
 
 
120
 
121
  ## Preprocessing Contract
122
 
@@ -149,13 +222,7 @@ lsm
149
  routine
150
  ```
151
 
152
- The intervention day is:
153
-
154
- ```text
155
- 3285
156
- ```
157
-
158
- each timestep uses:
159
 
160
  ```text
161
  time_normalized, scaled_static_covariates, post_intervention_flag, years_since_intervention
@@ -193,6 +260,3 @@ StateMINT utilities may perform this inverse transform for you depending on the
193
 
194
  - The `prevalence` and `cases` folders have separate checkpoints and separate fitted scalers. Always load the folder corresponding to the target being predicted.
195
 
196
- ## Citation
197
-
198
- If you use StateMINT in research, please cite the StateMINT repository and the underlying `malariasimulation` work used to generate the training data.
 
53
  Install StateMINT and the Hugging Face Hub client:
54
 
55
  ```bash
56
+ pip install stateMINT
57
  ```
58
 
59
  If installing from source:
 
72
  ```python
73
  from stateMINT.model import Mamba2Regressor
74
 
75
+ artifact = Mamba2Regressor.from_pretrained(
76
  "dide-ic/stateMINT",
77
  predictor="prevalence",
78
  revision="v1.0.0",
79
  )
80
 
81
+ model = artifact.model
82
  ```
83
 
84
  To load the cases model:
 
86
  ```python
87
  from stateMINT.model import Mamba2Regressor
88
 
89
+ artifact = Mamba2Regressor.from_pretrained(
90
  "dide-ic/stateMINT",
91
  predictor="cases",
92
  revision="v1.0.0",
93
  )
94
 
95
+ model = artifact.model
96
  ```
97
 
98
+ `from_pretrained` returns a `ModelArtifact` containing:
99
+
100
+ - `artifact.model`: the restored `Mamba2Regressor`.
101
+ - `artifact.preprocessing_config`: the exported preprocessing metadata.
102
+ - `artifact.scaler`: the fitted static covariate scaler.
103
+ - `artifact.prepare_inputs(...)`: converts raw static covariate dictionaries into model inputs.
104
+ - `artifact.predict(...)`: predicts directly from raw static covariate dictionaries.
105
+
106
+ ## Example Use Case
107
+
108
+ Use the prevalence model to emulate malaria prevalence trajectories for two intervention scenarios. Provide one raw static covariate dictionary per trajectory:
109
 
110
  ```python
111
+ from stateMINT.model import Mamba2Regressor
112
+
113
  artifact = Mamba2Regressor.from_pretrained(
114
  "dide-ic/stateMINT",
115
  predictor="prevalence",
116
  revision="v1.0.0",
 
117
  )
118
 
119
+ static_covars = [
120
+ {
121
+ "eir": 50.0,
122
+ "dn0_use": 0.3,
123
+ "dn0_future": 0.4,
124
+ "Q0": 0.8,
125
+ "phi_bednets": 0.7,
126
+ "seasonal": 1.0,
127
+ "routine": 0.5,
128
+ "itn_use": 0.2,
129
+ "irs_use": 0.1,
130
+ "itn_future": 0.3,
131
+ "irs_future": 0.2,
132
+ "lsm": 0.0,
133
+ },
134
+ {
135
+ "eir": 120.0,
136
+ "dn0_use": 0.2,
137
+ "dn0_future": 0.2,
138
+ "Q0": 0.9,
139
+ "phi_bednets": 0.6,
140
+ "seasonal": 1.0,
141
+ "routine": 0.4,
142
+ "itn_use": 0.3,
143
+ "irs_use": 0.0,
144
+ "itn_future": 0.5,
145
+ "irs_future": 0.1,
146
+ "lsm": 0.2,
147
+ },
148
+ ]
149
+
150
+ predicted_prevalence = artifact.predict(static_covars)
151
+
152
+ print(predicted_prevalence.shape) # (2, n_steps)
153
+ print(predicted_prevalence[0]) # prevalence trajectory for the first scenario
154
  ```
155
 
156
+ For case-count predictions, load `predictor="cases"` and call the same `.predict(...)` method:
157
+
158
+ ```python
159
+ artifact = Mamba2Regressor.from_pretrained(
160
+ "dide-ic/stateMINT",
161
+ predictor="cases",
162
+ revision="v1.0.0",
163
+ )
164
+
165
+ predicted_cases = artifact.predict(static_covars)
166
+ ```
167
+
168
+ By default, `.predict(...)` returns predictions on the original target scale:
169
+
170
+ - prevalence predictions are probabilities in `[0, 1]`;
171
+ - cases predictions are case counts.
172
+
173
+ To get predictions in the model's transformed training space, pass `transformed=True`:
174
+
175
+ ```python
176
+ raw_predictions = artifact.predict(static_covars, transformed=True)
177
+ ```
178
+
179
+ If you use the low-level model directly, it expects already-prepared arrays with shape:
180
 
181
  ```text
182
  (batch, time, input_size)
183
  ```
184
 
185
+ For the exported artifacts in this repository, `input_size` is `15`. You can build those arrays with:
186
+
187
+ ```python
188
+ import jax.numpy as jnp
189
+
190
+ X = artifact.prepare_inputs(static_covars)
191
+ raw_predictions = artifact.model(jnp.asarray(X))
192
+ ```
193
 
194
  ## Preprocessing Contract
195
 
 
222
  routine
223
  ```
224
 
225
+ Each timestep uses:
 
 
 
 
 
 
226
 
227
  ```text
228
  time_normalized, scaled_static_covariates, post_intervention_flag, years_since_intervention
 
260
 
261
  - The `prevalence` and `cases` folders have separate checkpoints and separate fitted scalers. Always load the folder corresponding to the target being predicted.
262