pub struct BayesianLinearRegression {
pub alpha_prior: f64,
pub beta_noise: f64,
pub posterior_mean: Vec<f64>,
pub posterior_cov: Vec<Vec<f64>>,
}Expand description
Bayesian linear regression with conjugate Gaussian prior on weights.
Model: y = X w + ε, ε ~ N(0, σ² I). Prior: w ~ N(w₀, α⁻¹ I).
Fields§
§alpha_prior: f64Prior precision α (= 1/σ_prior²).
beta_noise: f64Noise precision β (= 1/σ_noise²).
posterior_mean: Vec<f64>Posterior mean weights (set after fitting).
posterior_cov: Vec<Vec<f64>>Posterior covariance matrix (row-major, set after fitting).
Implementations§
Source§impl BayesianLinearRegression
impl BayesianLinearRegression
Sourcepub fn new(alpha_prior: f64, beta_noise: f64) -> Self
pub fn new(alpha_prior: f64, beta_noise: f64) -> Self
Creates a new Bayesian linear regression model.
§Arguments
alpha_prior- Prior precision (inverse variance) on weights.beta_noise- Noise precision.
Sourcepub fn fit(&mut self, x_mat: &[Vec<f64>], y: &[f64])
pub fn fit(&mut self, x_mat: &[Vec<f64>], y: &[f64])
Fits the model to design matrix x_mat (n × d) and targets y (n).
Computes the posterior mean and covariance analytically.
Sourcepub fn predict_mean(&self, x_new: &[f64]) -> f64
pub fn predict_mean(&self, x_new: &[f64]) -> f64
Returns the predictive mean for a new input vector x_new.
Sourcepub fn predict_variance(&self, x_new: &[f64]) -> f64
pub fn predict_variance(&self, x_new: &[f64]) -> f64
Returns the predictive variance for a new input x_new.
σ²_pred = 1/β + x^T S_N x.
Trait Implementations§
Source§impl Clone for BayesianLinearRegression
impl Clone for BayesianLinearRegression
Source§fn clone(&self) -> BayesianLinearRegression
fn clone(&self) -> BayesianLinearRegression
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for BayesianLinearRegression
impl RefUnwindSafe for BayesianLinearRegression
impl Send for BayesianLinearRegression
impl Sync for BayesianLinearRegression
impl Unpin for BayesianLinearRegression
impl UnsafeUnpin for BayesianLinearRegression
impl UnwindSafe for BayesianLinearRegression
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.