monte_carlo

petrophys.evaluation.uncertainty.monte_carlo

Also available as petrophys.evaluation.monte_carlo

monte_carlo(
function,
inputs,
*,
n=5000,
seed=0,
percentiles=(10, 50, 90),
correlated_depths=(),
)[source]

Propagate input uncertainty through function by Monte Carlo sampling.

Parameters:
  • function (callable) – Called once with keyword arguments of arrays: each scalar input is an array of shape (n,) broadcast as (n, 1) when any input is a curve, each curve input (m,) becomes (n, m). It must be vectorised (numpy operations) and return the output for every realisation.

  • inputs (mapping) – Keyword name to a fixed value or a distribution (module docstring). Distribution parameters may themselves be arrays over depth.

  • n (int) – Realisations.

  • seed (int, optional) – Random seed; the default 0 makes runs repeatable, None draws fresh.

  • percentiles (sequence of float) – Percentiles of the output to report (p10, p50, p90).

  • correlated_depths (sequence of str) – Curve inputs whose error is one shift per realisation (the same at every depth), e.g. a porosity calibration offset.

Return type:

MonteCarloResult

Examples

Archie Sw at one point with uncertain Rw, m and porosity:

>>> from petrophys.interpretation.saturation import archie
>>> result = monte_carlo(
...     lambda rt, rw, phi, m: archie(rt=rt, rw=rw, phi=phi, a=1.0, m=m, n=2.0),
...     {"rt": 20.0, "rw": ("triangular", 0.05, 0.07, 0.09),
...      "phi": ("normal", 0.20, 0.015), "m": ("uniform", 1.8, 2.2)},
...     n=2000)
>>> 0.2 < float(result.percentiles["p50"]) < 0.35
True