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 y on x when 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.0 is 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 DemingFit with the unbiased slope / intercept and the recovered latent x*.

Return type:

DemingFit

class DemingFit(slope, intercept, variance_ratio, x, y)[source]

Bases: object

Result of deming_regression(): slope/intercept plus the recovered latent predictor values.

conditional_mean(x_star)[source]

The conditional mean E[y | x*] = a + b x* at true predictor values x*.

Parameters:

x_star (ndarray)

Return type:

ndarray

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 x is observed as x = x* + u with u ~ N(0, sigma_u^2), naive estimates are biased (attenuation). SIMEX adds further noise of variance lambda sigma_u^2 for a grid of lambda >= 0, refits at each level (averaging over n_sims noise draws), then extrapolates the estimate back to lambda = -1 (zero measurement error). Works for any estimator returning a parameter vector.

Parameters:
  • fit_fn (Callable[[ndarray, ndarray], ndarray]) – f(x, y) -> theta returning 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 in lambda.

  • seed (int | RandomState | None) – RNG seed.

Returns:

{'estimate', 'naive', 'lambdas', 'curve'} – the SIMEX-corrected parameter vector, the naive lambda=0 estimate, and the per-level averaged estimates.

Return type:

dict

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 func and summarises the output distribution – the general “what is the uncertainty of g(theta)?” operation. func may be vectorised (accept the whole (n, ...) array) or act on a single draw; both are detected.

Parameters:
  • func (Callable[[ndarray], ndarray]) – the functional to propagate. Returns a scalar or fixed-length vector per input draw.

  • samples (ndarray) – (n, ...) input draws (rows are draws).

  • quantiles (tuple[float, ...]) – output quantiles to report.

Returns:

{'mean', 'std', 'quantiles', 'levels', 'samples'} over the propagated outputs.

Return type:

dict