Calibration methods and metrics#
Every search method a calibration file can name, and every metric an objective block can score with. Both lists are read from the code at each build: the optimizer registry, the options model and the declared traits of each engine, the metric kernels and their formulas. Why the objective is built this way is in The inverse problem of a calibration.
Methods#
A file names a method with calibration.method, or per phase with
calibration.phases.method. Left unset, the search gets the first method whose
conditions it meets: hmp calibrate FILE --list-phases prints the choice and the reason, for
each phase or for the one search of a file without phases. A name that is not registered is refused before anything is prepared, at the start of
every launch and by hmp check, with the list of the names that are.
Method |
What it does |
Parameters |
Stops on |
Parallel |
|---|---|---|---|---|
A root search on one parameter: a coarse log sweep, then the bracket is halved. |
One, in log space only |
precision |
yes |
|
Covariance matrix adaptation evolution strategy, from the |
Any number |
budget |
yes |
|
A Gaussian-process surrogate of the cost, refined where the expected improvement is highest. |
Any number |
budget |
yes |
|
Every point of a regular grid, in the space each parameter is sampled in. |
Any number |
design |
yes |
|
One Latin hypercube design, drawn before any solve and evaluated whole. |
Any number |
design |
yes |
|
Latin hypercubes in turn, each one in the zone the trials so far leave open. |
One |
design |
yes |
|
An Optuna study driven trial by trial, with the TPE sampler by default. |
Any number |
budget |
yes |
|
Independent draws from the sampling of each parameter. |
Any number |
budget |
yes |
|
Differential evolution, |
Any number |
budget |
yes |
|
A local simplex, |
Any number |
precision |
yes |
bisection#
A root search on one parameter: a coarse log sweep, then the bracket is halved.
It reads a signed residual, so every block it scores must use distance_gap, and the parameter must be searched in log space. It stops on the width of the bracket, never on the size of the residual. It is the method a search that names none gets when those conditions hold. Use it for the stream-network stage: one conductivity against a mapped network.
Options, written under calibration.method_options with method beside them, or in the method_options of a phase:
Option |
Type |
Default |
What it sets |
|---|---|---|---|
|
float |
|
Relative width of the bracket at which the search stops, on the calibrated parameter. The paper’s one per cent. The criterion is never the size of the residual: it steps over zero and would never get small enough. |
|
str |
|
Name of the component carrying the signed residual whose sign the search brackets. Left at ‘J_signed’, a network output scored on two bounds is searched on J_signed_minimal and J_signed_maximal, one root each, and the value returned is their weighted geometric mean. Any other name is one root. |
|
int |
|
Points of the coarse log sweep run before the bisection. It checks the monotonicity the paper assumes instead of supposing it, sees every crossing, and produces the crossing curves for free. Zero gives the pure bisection of the paper. |
|
int |
|
How many times the interval may be widened by one decade when no sign change is found. Beyond that the search raises rather than returning the better of the two ends. |
Parameters: One, in log space only
Criterion: A signed one only: every block it scores reads a signed residual,
distance_gap.Stops: On a precision on the parameter:
calibration.precisionwritesrel_tol, a relative precision on the parameter, passed through as is.Budget:
max_trials = "auto"counts the evaluations its rule needs before the first solve. A smaller number is refused or warned before anything is prepared, at every launch and byhmp check.Parallel trials: Yes, with
calibration.parallel.Starts from an earlier phase: No.
Restarts: Refused by the
multistartuncertainty: it returns the same answer every time.Without a method: Chosen first, when the search meets every condition above.
cma_es#
Covariance matrix adaptation evolution strategy, from the cma package.
It needs the calibration extra. It can start from the value an earlier phase passed on. Use it on several parameters with a broad box and a cost with plateaus.
Options, written under calibration.method_options with method beside them, or in the method_options of a phase:
Option |
Type |
Default |
What it sets |
|---|---|---|---|
|
float |
|
Initial step size, in the unit cube when normalize is true, else in the space the search walks. |
|
int |
|
Points evaluated per generation. |
|
bool |
|
Rescale the box to the unit cube before the strategy runs. |
|
int |
|
Fresh strategies started from a perturbed point when one stops before the budget is spent. Zero keeps one strategy. |
Parameters: Any number
Stops: On its budget, or on a rule of its own options. Spending the budget is not convergence: the search says it spent its budget, and a phase freezes its best saying it froze the best of a budget-only search.
calibration.precisionis refused.Budget:
max_trials = "auto"gives 100 evaluations.Parallel trials: Yes, with
calibration.parallel.Starts from an earlier phase: Yes: a parameter an earlier phase passed on starts at that value.
Restarts: Accepted by the
multistartuncertainty.
gp_mapping#
A Gaussian-process surrogate of the cost, refined where the expected improvement is highest.
Every candidate it returns was run through the real model. It needs scikit-learn, which the base install carries. Use it when each run is expensive and the parameters are few.
Options, written under calibration.method_options with method beside them, or in the method_options of a phase:
Option |
Type |
Default |
What it sets |
|---|---|---|---|
|
int |
|
Random points of the initial design, drawn from the sampling of each parameter. |
|
float |
|
Expected improvement under which an iteration counts as converged. |
|
int |
|
Iterations in a row under ei_tol before the search stops. |
|
float |
|
Exploration margin of the expected improvement. |
|
int |
|
Starts of the optimiser that maximizes the acquisition. |
|
int or None |
not set |
Refinement rounds after the initial design. When set, the design is sized so that n_init + n_refine * batch_size evaluations fit in the search budget max_trials. |
|
int |
|
Candidates proposed per refinement round. |
|
float |
|
When not zero, the acquisition is the lower confidence bound mu - kappa * sigma instead of the expected improvement. |
|
float |
|
Noise floor of the Gaussian-process regressor. |
|
float |
|
Added to alpha: the nugget of the regressor is alpha + jitter. |
Parameters: Any number
Stops: On its budget, or on a rule of its own options. Spending the budget is not convergence: the search says it spent its budget, and a phase freezes its best saying it froze the best of a budget-only search.
calibration.precisionis refused.Budget:
max_trials = "auto"gives 100 evaluations.Parallel trials: Yes, with
calibration.parallel.Starts from an earlier phase: No.
Restarts: Accepted by the
multistartuncertainty.
grid#
Every point of a regular grid, in the space each parameter is sampled in.
A log parameter gets a log axis. The grid is the same whatever the seed, so the search is a deterministic map of the cost. Use it on one or two parameters, for a first look at the cost or a reference to judge another method against.
Options, written under calibration.method_options with method beside them, or in the method_options of a phase:
Option |
Type |
Default |
What it sets |
|---|---|---|---|
|
int or list of int or None |
not set |
Points sampled per dimension. Scalar applies to every axis; a list must match the parameter-space dimension. |
Parameters: Any number
Stops: When every point of its design is solved: a budget below the design is refused.
calibration.precisionis refused.Budget:
max_trials = "auto"counts the evaluations its rule needs before the first solve. A smaller number is refused or warned before anything is prepared, at every launch and byhmp check.Parallel trials: Yes, with
calibration.parallel.Starts from an earlier phase: No.
Restarts: Refused by the
multistartuncertainty: it returns the same answer every time.
lhs#
One Latin hypercube design, drawn before any solve and evaluated whole.
Each stratum of each parameter is hit once. Use it for an even scan with a fixed budget on more parameters than a grid affords.
Options, written under calibration.method_options with method beside them, or in the method_options of a phase:
Option |
Type |
Default |
What it sets |
|---|---|---|---|
|
‘random-cd’ | ‘lloyd’ or None |
not set |
Post-processing passed to scipy.stats.qmc.LatinHypercube: None keeps the raw stratified draw and ‘random-cd’ spread the points further apart while still hitting every stratum exactly once; ‘lloyd’ can spread points further apart too, but is a best-effort relaxation that is not guaranteed to keep the one-point-per-stratum property. |
|
int |
required |
Points drawn in the design. Required. |
Parameters: Any number
Stops: When every point of its design is solved: a budget below the design is refused.
calibration.precisionis refused.Budget:
max_trials = "auto"counts the evaluations its rule needs before the first solve. A smaller number is refused or warned before anything is prepared, at every launch and byhmp check.Parallel trials: Yes, with
calibration.parallel.Starts from an earlier phase: No.
Restarts: Accepted by the
multistartuncertainty.
lhs_zoom#
Latin hypercubes in turn, each one in the zone the trials so far leave open.
Level 1 covers the bounds of the phase. Each next level covers the range of the trials whose cost stays within the phase margin of the best one, widened to the solved trial on each side and by at least one stratum of the level before. It moves one parameter, whose cost curve it reads. Use it to find a flat bottom and its width with a fixed budget.
Options, written under calibration.method_options with method beside them, or in the method_options of a phase:
Option |
Type |
Default |
What it sets |
|---|---|---|---|
|
‘random-cd’ | ‘lloyd’ or None |
not set |
Post-processing passed to scipy.stats.qmc.LatinHypercube: None keeps the raw stratified draw and ‘random-cd’ spread the points further apart while still hitting every stratum exactly once; ‘lloyd’ can spread points further apart too, but is a best-effort relaxation that is not guaranteed to keep the one-point-per-stratum property. |
|
list of int |
|
Points of each level, in order. Each level is a Latin hypercube. At least two levels of at least two points. The budget is their sum. A multiple of |
Parameters: One
Stops: When every point of its design is solved: a budget below the design is refused.
calibration.precisionis refused.Budget:
max_trials = "auto"counts the evaluations its rule needs before the first solve. A smaller number is refused or warned before anything is prepared, at every launch and byhmp check.Parallel trials: Yes, with
calibration.parallel.Starts from an earlier phase: No.
Restarts: Accepted by the
multistartuncertainty.
optuna#
An Optuna study driven trial by trial, with the TPE sampler by default.
Use it for a first adaptive search on a few parameters. Set calibration.seed so a re-run proposes the same trials.
Options, written under calibration.method_options with method beside them, or in the method_options of a phase:
Option |
Type |
Default |
What it sets |
|---|---|---|---|
|
‘tpe’ | ‘random’ | ‘cmaes’ | ‘nsga’ |
|
Optuna sampler. ‘tpe’, ‘random’ and ‘nsga’ come with the base install; ‘cmaes’ needs the calibration extra. |
|
‘minimize’ |
|
Direction of the study. The calibration cost is always minimised. |
Parameters: Any number
Stops: On its budget, or on a rule of its own options. Spending the budget is not convergence: the search says it spent its budget, and a phase freezes its best saying it froze the best of a budget-only search.
calibration.precisionis refused.Budget:
max_trials = "auto"gives 100 evaluations.Parallel trials: Yes, with
calibration.parallel.Starts from an earlier phase: No.
Restarts: Accepted by the
multistartuncertainty.
random_search#
Independent draws from the sampling of each parameter.
It never decides it has converged, so it runs to its budget. Use it as a cheap baseline to judge another method against.
It takes no option.
Parameters: Any number
Stops: On its budget, or on a rule of its own options. Spending the budget is not convergence: the search says it spent its budget, and a phase freezes its best saying it froze the best of a budget-only search.
calibration.precisionis refused.Budget:
max_trials = "auto"gives 100 evaluations.Parallel trials: Yes, with
calibration.parallel.Starts from an earlier phase: No.
Restarts: Accepted by the
multistartuncertainty.
scipy_de#
Differential evolution, scipy.optimize.differential_evolution.
A population search over the whole box. It scores a generation at once, so parallel helps up to the size of the population. It follows another path from the one it follows at a width of one. Use it for a robust global search.
Options, written under calibration.method_options with method beside them, or in the method_options of a phase:
Option |
Type |
Default |
What it sets |
|---|---|---|---|
|
int |
|
Population size, as a multiple of the number of parameters, SciPy’s popsize. |
|
float |
|
Relative spread of the population costs at which SciPy stops, its tol. |
Parameters: Any number
Stops: On its budget, or on a rule of its own options. Spending the budget is not convergence: the search says it spent its budget, and a phase freezes its best saying it froze the best of a budget-only search.
calibration.precisionis refused.Budget:
max_trials = "auto"gives 100 evaluations.Parallel trials: Yes, with
calibration.parallel.Starts from an earlier phase: No.
Restarts: Accepted by the
multistartuncertainty.
scipy_nelder_mead#
A local simplex, scipy.optimize.minimize(method='Nelder-Mead').
It starts from the center of the sampling, or from the value an earlier phase passed on. It is the method a search that names none gets when its cost has no sign to bracket. Use it when the range is already narrow, or to refine the result of a coarse search.
Options, written under calibration.method_options with method beside them, or in the method_options of a phase:
Option |
Type |
Default |
What it sets |
|---|---|---|---|
|
float or None |
not set |
Width of the simplex at which it stops, in the space the search walks (log10 units for a log parameter). Written from calibration.precision; set one or the other. |
|
float or None |
not set |
Spread of the costs over the simplex at which it stops, SciPy’s fatol. None leaves SciPy’s default. |
Parameters: Any number
Stops: On a precision on the parameter:
calibration.precisionwritesxatol, a width in the space the search walks, converted from the relative precision.Budget:
max_trials = "auto"gives 100 evaluations.Parallel trials: Yes, with
calibration.parallel.Starts from an earlier phase: Yes: a parameter an earlier phase passed on starts at that value.
Restarts: Accepted by the
multistartuncertainty.Without a method: Chosen when the methods before it do not fit.
Metrics#
An objective block names one metric with calibration.objective_blocks.metric. The
search always minimizes a cost: the Cost minimized column gives how the score of each metric
enters it. In the formulas of a metric that reads a series, \(s_t\) is the simulated value and
\(o_t\) the observed one at the same date, over the \(n\) dated pairs the scoring window keeps. A
metric that reads a network defines its own terms under its formula.
Metric |
Family |
Cost minimised |
Unit of the cost |
Reads |
Signed |
|
|---|---|---|---|---|---|---|
|
error |
score |
none |
series output |
no |
refused |
|
network distance |
score |
m |
network output |
yes |
validity length of the output |
|
network distance |
score |
m |
network output |
no |
validity length of the output |
|
efficiency |
1 - score |
none |
series output |
no |
refused |
|
error |
score |
unit of the observation |
series output |
no |
standard deviation of the observations |
|
efficiency |
1 - score |
none |
series output |
no |
refused |
|
efficiency |
1 - score |
none |
series output |
no |
refused |
|
efficiency |
1 - score |
none |
series output |
no |
refused |
|
efficiency |
1 - score |
none |
series output |
no |
refused |
|
efficiency |
1 - score |
none |
series output |
no |
refused |
|
error |
score |
unit of the observation |
series output |
no |
standard deviation of the observations |
bfi_errorWhether the simulated stream is fed by its aquifer in the share the gauge shows, whatever its volume and its timing.
\[\left\lvert \dfrac{\sum_t b^s_t}{\sum_t s_t} - \dfrac{\sum_t b^o_t}{\sum_t o_t} \right\rvert\]where \(b^x_t = \text{Wallingford baseflow of } x \text{ on day } t\).
Lower is better; the search minimises it as it is.
The Wallingford filter (Gustard et al. 1992) takes the minimum of each block of five days and joins the minima below 1/0.9 of their neighbours. Both series are filtered on the same days, cut at the gaps of the record, and summed only where both baselines exist. Daily series only: a coarser step scores NaN. The index is the one of the whole window, not ESPERE’s lowest yearly index.
distance_gapEq. 1 of the stream-network method: zero where the simulated network reaches as far as the mapped one.
\[\lvert D_{so} - D_{os} \rvert\]where \(J = D_{so} - D_{os}\).
Lower is better; the search minimises it as it is.
D_so is the mean downslope distance from the simulated network to the mapped one, D_os the reverse. J is the signed residual a root search brackets. With two bounds, the cost sums the weighted gap of each bound.
distance_meanEq. 2 of the stream-network method: the mean mismatch of the two networks.
\[\tfrac{1}{2}\,(D_{so} + D_{os})\]Lower is better; the search minimises it as it is.
A diagnostic, and a cost only to choose between structures already balanced by distance_gap. With two bounds, the cost sums the weighted mean of each bound.
kgeCorrelation, variability and bias in one number.
\[1 - \sqrt{(r - 1)^2 + (\alpha - 1)^2 + (\beta - 1)^2}\]where \(r = \mathrm{corr}(s, o),\quad \alpha = \sigma_s / \sigma_o,\quad \beta = \textstyle\sum_t s_t \big/ \sum_t o_t\).
Higher is better; the search minimises one minus the score.
The 2009 form of Gupta et al.: alpha is the ratio of the standard deviations and beta the ratio of the sums. The 2012 form, which takes alpha as a ratio of coefficients of variation, is not used and scores the same series differently.
maeThe typical miss, less driven by a few large ones.
\[\tfrac{1}{n}\sum_t \lvert s_t - o_t \rvert\]Lower is better; the search minimises it as it is.
nseThe fit against a model that always predicts the observed mean.
\[1 - \dfrac{\sum_t (s_t - o_t)^2}{\sum_t (o_t - \bar{o})^2}\]Higher is better; the search minimises one minus the score.
nse_deltaThe fit of the change from one sample to the next, blind to the absolute level.
\[\mathrm{NSE}(\Delta s,\ \Delta o)\]where \(\Delta x_t = x_{t+1} - x_t\).
Higher is better; the search minimises one minus the score.
Pair it with a metric on the level. An increment never spans a gap in the dates of the series.
nse_logThe NSE of the logarithms: recessions and low flows weigh as much as the peaks.
\[\mathrm{NSE}\big(\ln(s + \varepsilon),\ \ln(o + \varepsilon)\big)\]where \(\varepsilon = \max\big(10^{-9},\ 0.01\,\mathrm{median}\{o_t > 0\}\big)\).
Higher is better; the search minimises one minus the score.
Negative values are clipped to zero first, and the trial counts them.
nse_seasonalThe fit beyond the seasonal cycle of the observations. Below zero, the model does worse than that cycle alone.
\[1 - \dfrac{\sum_t (s_t - o_t)^2}{\sum_t (o_t - c_t)^2}\]where \(c_t = a_0 + \textstyle\sum_{k=1}^{2} \big(a_k \cos\tfrac{2\pi k t}{P} + b_k \sin\tfrac{2\pi k t}{P}\big),\ \text{fitted to } o \text{ by least squares},\ P = 365.25\,\text{days} / \Delta t\).
Higher is better; the search minimises one minus the score.
P is one year counted in samples of the series, whose step Delta t is read from its dates, and t is the date of each sample in the same steps, so a gap in the record keeps the cycle in phase. Two years are needed: a shorter series scores NaN. A series with no dates is taken as daily.
reservoirBuilt for an impounded level: the seasonal half keeps the level honest, the increment half makes the water balance count.
\[\tfrac{1}{2}\,\mathrm{NSE}_{\mathrm{seasonal}}(s, o) + \tfrac{1}{2}\,\mathrm{NSE}(\Delta_{n} s,\ \Delta_{n} o)\]where \(\Delta_{n} x_t = x_{t+n} - x_t,\ n = \max(1,\ \mathrm{round}(10\,\text{days} / \Delta t))\).
Higher is better; the search minimises one minus the score.
The seasonal half reads the dates as nse_seasonal does. The increments span ten days, or one sample on a coarser series, and never a gap in the dates.
rmseLarge misses weigh more than many small ones.
\[\sqrt{\tfrac{1}{n}\sum_t (s_t - o_t)^2}\]Lower is better; the search minimises it as it is.