mixle.reason.core module¶
The reasoning front door: fuse modality evidence into a belief, query it with native UQ.
reason(prior, evidence) folds a sequence of linear-Gaussian observations into a belief state
by exact Kalman assimilation, tracking how many nats of uncertainty each modality removed. The
returned ReasonedAnswer is the posterior belief plus the tools a scientific answer needs:
credible intervals, per-modality attribution, and an epistemic/aleatoric split of any prediction.
- class Latent[source]
Bases:
objectFactories for the shared latent’s prior belief (the starting point of assimilation).
- static gaussian(mean, cov)[source]
A Gaussian prior
N(mean, cov)over the latent.
- static vector(dim, *, mean=0.0, var=1.0)[source]
An isotropic Gaussian prior over a
dim-vector latent:N(mean*1, var*I).
- static mechanistic(A, steps, *, x0_mean=None, x0_cov=None, process_cov=None)[source]
A physics-constrained prior over a latent trajectory
z_0 .. z_{steps-1}.The trajectory follows a linear dynamical law
z_{t+1} = A z_t + w_t,w_t ~ N(0, Q)– a discretized linear ODE/PDE (Ais the state-transition operator; take it from amixle_pdeDynamicsOperatorfor real physics). The returned belief is the exact joint Gaussian over the stacked trajectory(steps * d,)(blocktisz_t); its block-tridiagonal precision is the mechanistic prior. Because the states are coupled, evidence at any one time informs all times through the dynamics – fusing observations viareason()is then exact Kalman smoothing, so a sparsely-observed field is filled in by the physics, not by a generic smoothness assumption.- Parameters:
A (Any) –
(d, d)linear state-transition operator (one discrete step).steps (int) – number of time steps
Tin the trajectory.x0_mean (Any) – mean of
z_0(default zeros).x0_cov (Any) – covariance of
z_0(default identity).process_cov (Any) – process-noise covariance
Q(default zeros – deterministic dynamics).
- Return type:
GaussianBelief
- class LinearGaussianEvidence(H, y, R, name='')[source]
Bases:
objectOne modality’s evidence about the latent
z:y = H z + noise,noise ~ N(0, R).His the (possibly linearized) forward operator mapping the latent to this modality’s measurement space,ythe observed data,Rits noise covariance (matrix, diagonal, or scalar). Application forward models (e.g.mixle_pdegeophysics operators) produce these.- H: Any
- y: Any
- R: Any
- name: str = ''
- Evidence
Short alias –
Evidence(H, y, R, name).
- class NonlinearEvidence(h, y, R, jacobian=None, iterations=2, name='')[source]
Bases:
objectOne modality’s evidence through a NONLINEAR forward model:
y = h(z) + noise.Assimilated by (iterated) extended-Kalman linearization: at the current belief mean
mthe forward is replaced by its tangenth(z) ~ h(m) + J(m)(z - m)and the exact linear update runs on that tangent; withiterations > 1the linearization point is refined at the updated mean and the update repeats FROM THE PRE-UPDATE BELIEF (the iterated EKF), which matters when the prior mean is far from the truth.jacobianis analytic when you have it; otherwise a central finite difference is used. Honest caveat: this is a Gaussian approximation around the linearization point – for strongly multimodal posteriors it reports one mode’s belief, not the mixture.- h: Any
- y: Any
- R: Any
- jacobian: Any = None
- iterations: int = 2
- name: str = ''
- block_selector(step, n_blocks, block_dim, within=None)[source]
An observation matrix that reads time-block
stepof a stacked trajectory latent.For a latent built by
Latent.mechanistic()(shape(n_blocks * block_dim,)), returns theHselecting blockstep– use it to buildLinearGaussianEvidencefor an observation at that time.withinoptionally reads only part of the block (a(k, block_dim)local readout); by default the whole block is read (identity).
- class ReasonedAnswer(belief, prior_entropy, contributions)[source]
Bases:
objectA posterior belief about a query, with the UQ a scientific answer needs.
Beyond
mean/interval/entropy(delegated to the belief), it exposesattribution()– the nats of uncertainty each modality removed – andpredict(), which splits a prediction’s uncertainty into epistemic (from latent uncertainty) and aleatoric (observation noise) via the law of total variance.- property mean: ndarray
- interval(level=0.9)[source]
Per-coordinate central credible interval at
level(an(d, 2)array of[lo, hi]).
- information_gain()[source]
Total nats of uncertainty the evidence removed from the prior (
H[prior] - H[posterior]).- Return type:
- attribution(*, normalize=False)[source]
Per-modality information gain in nats – which modality sharpened the belief, and by how much.
With
normalize=True, values are the fraction of the total gain (they then sum to ~1).
- predict(H, R=0.0)[source]
Split the uncertainty of a new prediction
y* = H z + noise(R)(law of total variance).epistemic = diag(H P Hᵀ)(from the latent’s remaining uncertainty, reducible by more data) andaleatoric = diag(R)(irreducible observation noise). Exact for the Gaussian belief.
- reason(prior, evidence, *, query=None)[source]
Fuse
evidenceintopriorby exact Kalman assimilation; return the queried posterior.- Parameters:
prior (Any) – the latent’s prior belief (
GaussianBelief; build one withLatent).evidence (Any) – a sequence of
LinearGaussianEvidenceand/orNonlinearEvidence– one per modality / observation. Nonlinear items assimilate by iterated-EKF linearization (a Gaussian approximation; seeNonlinearEvidence). They are folded in one at a time (order does not affect the result), and the nats each removes are recorded forReasonedAnswer.attribution().query (Any) – optional latent coordinate indices to restrict the answer to.
- Returns:
A
ReasonedAnswer– the posterior belief plus attribution and prediction UQ.- Return type:
ReasonedAnswer