pub struct Gaussian {
pub mean: Vec<f64>,
pub cov: Vec<f64>,
/* private fields */
}Fields§
§mean: Vec<f64>Posterior mean — length D.
cov: Vec<f64>Posterior covariance, row-major D×D.
Implementations§
Source§impl Gaussian
impl Gaussian
Sourcepub fn new(mean: Vec<f64>, cov: Vec<f64>) -> Result<Self, BLRError>
pub fn new(mean: Vec<f64>, cov: Vec<f64>) -> Result<Self, BLRError>
Create a new Gaussian, validating dimensions.
Sourcepub fn marginal(&self, i: usize) -> (f64, f64)
pub fn marginal(&self, i: usize) -> (f64, f64)
Marginal distribution at index i: returns (mean[i], std[i]).
Sourcepub fn log_pdf(&self, x: &[f64]) -> f64
pub fn log_pdf(&self, x: &[f64]) -> f64
Log probability density log N(x; mean, cov).
Uses Cholesky of cov for numerical stability.
Sourcepub fn condition(
self,
a: &[f64],
n_obs: usize,
d_feat: usize,
y: &[f64],
noise_variance: f64,
) -> Result<Self, BLRError>
pub fn condition( self, a: &[f64], n_obs: usize, d_feat: usize, y: &[f64], noise_variance: f64, ) -> Result<Self, BLRError>
Bayesian update: computes p(self | y) where y = A·self + ε,
ε ~ N(0, σ²·I_N) (homoscedastic noise).
a is the measurement matrix A (n_obs × d_feat), row-major flat slice.
noise_variance is the scalar observation noise variance σ² > 0.
§Adaptive dispatch
Two algebraically equivalent forms are available; this method selects whichever minimises the size of the required Cholesky factorisation:
| Condition | Form chosen | Cholesky size |
|---|---|---|
n_obs < d_feat | Gram / Kalman-gain (observation-space) | N×N |
n_obs >= d_feat | Precision / Woodbury (parameter-space) | D×D |
The two forms are related by the Woodbury matrix identity; see
dev/blog/blr-and-ard.md Appendix A for the derivation.
The precision form derives Σ_prior⁻¹ directly from self.cov — no
isotropic approximation is made, and the forms agree within floating-point
rounding error.
Returns the updated Gaussian representing the posterior distribution.