nhra_gt.domain.validation¶
Classes¶
MechanismValidator
¶
Verifies that model sensitivity aligns with mechanistic/historical narratives.
Source code in src/nhra_gt/domain/validation.py
Functions¶
verify_rank(parameter, expected_rank)
¶
Check if parameter holds a specific rank.
Source code in src/nhra_gt/domain/validation.py
verify_top_n(parameter, n)
¶
Check if parameter is within the top N drivers.
verify_magnitude(parameter, threshold, comparison='>')
¶
Check if parameter influence (mu_star) meets a threshold.
Source code in src/nhra_gt/domain/validation.py
verify_inequality(param_a, param_b)
¶
Check if param_a has greater influence than param_b.
Source code in src/nhra_gt/domain/validation.py
RecursiveResult
¶
Bases: BaseModel
Container for the results of a single backtest step.
Source code in src/nhra_gt/domain/validation.py
RecursiveBacktest
¶
Engine for running recursive rolling horizon validation.
Source code in src/nhra_gt/domain/validation.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
Functions¶
generate_windows()
¶
Generator for (train_df, test_df) pairs.
Source code in src/nhra_gt/domain/validation.py
run_step(train_df, test_df)
¶
Run a single validation step.
In a real scenario, this would involve: 1. Calibrating parameters to train_df. 2. Running the model for test_df years. 3. Comparing results.
Source code in src/nhra_gt/domain/validation.py
run_all()
¶
Execute the full backtest loop.
save_results(results, path)
¶
Save backtest results to a JSON file.
Source code in src/nhra_gt/domain/validation.py
BlindReveal
¶
Performs blind holdout validation (e.g., train on <2024, test on 2024-2025).
Source code in src/nhra_gt/domain/validation.py
Functions¶
run_prediction()
¶
Run the model for the holdout period using default (or calibrated) params.
Source code in src/nhra_gt/domain/validation.py
Functions¶
calculate_rmse(actual, predicted)
¶
calculate_mape(actual, predicted)
¶
Calculate Mean Absolute Percentage Error.
Source code in src/nhra_gt/domain/validation.py
calculate_theil_u(actual, predicted)
¶
Calculate Theil's U1 inequality coefficient.
U = 0: Perfect fit U = 1: Worst possible fit
Source code in src/nhra_gt/domain/validation.py
calculate_hit_rate(actual, predicted)
¶
Calculate Directional Accuracy (Hit Rate).
Percentage of steps where predicted change direction matches actual change direction.
Source code in src/nhra_gt/domain/validation.py
calculate_theil_decomposition(actual, predicted)
¶
Calculate Theil Inequality Decomposition (UM, US, UC).
UM: Bias proportion (due to mean difference) US: Variance proportion (due to standard deviation difference) UC: Covariance proportion (due to imperfect correlation)
UM + US + UC = 1.0
Source code in src/nhra_gt/domain/validation.py
aggregate_metrics(results)
¶
Calculate summary statistics across all backtest steps.