mixle.inference.errors_in_variables module¶
Errors-in-variables regression: fit a relationship when the predictor is itself measured with error.
When you regress a property on a position/depth/another measurement that carries its own uncertainty –
uncertain well locations, picked stratigraphic depths, one noisy proxy against another – ordinary least
squares is biased: input noise attenuates the slope toward zero (regression dilution). The
errors-in-variables model y = a + b x* + e_y, x = x* + e_x corrects this. With a known noise
variance ratio it is Deming regression (total least squares when the ratio is 1); it also recovers the
latent true predictor values x* (the denoised positions). Part of the earth-science/UQ work (Phase 6).
- deming_regression(x, y, variance_ratio=1.0)[source]
Errors-in-variables (Deming) regression of
yonxwhen both are noisy.- Parameters:
x – paired measurements; both may carry error.
y – paired measurements; both may carry error.
variance_ratio (float) –
var(e_y) / var(e_x)– the ratio of output to input noise variance.1.0is total least squares (orthogonal regression); a large value -> ordinary least squares (no input error); a small value -> inverse regression (predictor dominated by error).
- Returns:
A
DemingFitwith the unbiasedslope/interceptand the recovered latentx*.- Return type:
DemingFit
- class DemingFit(slope, intercept, variance_ratio, x, y)[source]
Bases:
objectResult of
deming_regression(): slope/intercept plus the recovered latent predictor values.
- simex(fit_fn, x, y, sigma_u, *, lambdas=None, n_sims=100, extrapolation='quadratic', seed=0)[source]
SIMEX: simulation–extrapolation correction for a predictor measured with known error.
When a predictor
xis observed asx = x* + uwithu ~ N(0, sigma_u^2), naive estimates are biased (attenuation). SIMEX adds further noise of variancelambda sigma_u^2for a grid oflambda >= 0, refits at each level (averaging overn_simsnoise draws), then extrapolates the estimate back tolambda = -1(zero measurement error). Works for any estimator returning a parameter vector.- Parameters:
fit_fn (Callable[[ndarray, ndarray], ndarray]) –
f(x, y) -> thetareturning the parameter vector for (possibly multi-column)x.x (ndarray) –
(n,)or(n, p)error-prone predictor(s).y (ndarray) –
(n,)response.sigma_u (float | ndarray) – measurement-error standard deviation (scalar, or per-column for matrix
x).lambdas (ndarray | None) – extra-noise levels (defaults to
0, 0.5, 1.0, 1.5, 2.0).n_sims (int) – noise replications per level.
extrapolation (str) –
"quadratic"or"linear"extrapolant inlambda.seed (int | RandomState | None) – RNG seed.
- Returns:
{'estimate', 'naive', 'lambdas', 'curve'}– the SIMEX-corrected parameter vector, the naivelambda=0estimate, and the per-level averaged estimates.- Return type:
- propagate_uncertainty(func, samples, *, quantiles=(0.025, 0.5, 0.975))[source]
Monte-Carlo propagation of an uncertainty set through an arbitrary functional.
Pushes input draws (a posterior sample, a bootstrap set, any uncertainty representation) through
funcand summarises the output distribution – the general “what is the uncertainty ofg(theta)?” operation.funcmay be vectorised (accept the whole(n, ...)array) or act on a single draw; both are detected.- Parameters:
- Returns:
{'mean', 'std', 'quantiles', 'levels', 'samples'}over the propagated outputs.- Return type: