Skip to content

correct_distribution builtin

correct_distribution(
    values,
    reference,
    *,
    weights=None,
    strength=1.0,
    realizations=None,
)

Realizations, or an estimate, corrected to a target distribution.

Each realization's values are ranked and the value ranked i of m is mapped to the reference quantile at (i + 0.5) / m, then moved strength of the way from its original value: at 1 every realization takes the reference histogram exactly, at 0 nothing changes. Ranks are kept, ties in the order of the targets, so the spatial pattern of each realization stays; the correction is exact in distribution only, its variogram moves with the values. Realizations are corrected in parallel, identically on any number of threads.

Parameters:

Name Type Description Default
values SimulationSummary or array_like

A summary simulated with keep=, its (len(kept), targets) realizations, or one (targets,) estimate; NaN stays NaN.

required
reference (array_like, KernelDensity or GaussianMixture)

Data values, whose weighted distribution is the target (quantiles interpolate between the midpoints of the cumulative weights, NaN dropped), or a fitted one-variable distribution.

required
weights array_like

Declustering weights of the reference data.

None
strength float

Share of the correction applied, in [0, 1].

1.0
realizations sequence of int

The realizations to correct, e.g. those a check_realizations shows outside a tolerance; the others are returned unchanged. Default all.

None

Returns:

Type Description
ndarray

The corrected values, shaped as values ((n, targets) for a summary).

Raises:

Type Description
InvalidInput

If a summary holds no realizations, strength is outside [0, 1], a realization index is out of range, or the reference is empty.

used in