pub struct GaussianProcess {
pub length_scale: f64,
pub signal_variance: f64,
pub noise_variance: f64,
/* private fields */
}Expand description
Gaussian Process regression with an RBF kernel.
Hyperparameters are settable; the kernel is
k(x, x') = σ_f² · exp(−||x−x'||² / 2ℓ²) with observation noise σ_n.
Fields§
§length_scale: f64Length scale ℓ.
signal_variance: f64Signal variance σ_f².
noise_variance: f64Observation noise variance σ_n².
Implementations§
Source§impl GaussianProcess
impl GaussianProcess
Sourcepub const fn new(
length_scale: f64,
signal_variance: f64,
noise_variance: f64,
) -> Self
pub const fn new( length_scale: f64, signal_variance: f64, noise_variance: f64, ) -> Self
Create a GP with the given kernel hyperparameters.
Sourcepub fn add_sample(&mut self, x: Vec<f64>, y: f64)
pub fn add_sample(&mut self, x: Vec<f64>, y: f64)
Add a training sample (x, y).
Sourcepub fn set_hyperparameters(
&mut self,
length_scale: f64,
signal_variance: f64,
noise_variance: f64,
)
pub fn set_hyperparameters( &mut self, length_scale: f64, signal_variance: f64, noise_variance: f64, )
Set kernel hyperparameters (all clamped to positive).
Sourcepub fn log_marginal_likelihood(&self) -> Result<f64, String>
pub fn log_marginal_likelihood(&self) -> Result<f64, String>
Log marginal likelihood of the training data under the current
hyperparameters: −½ yᵀK⁻¹y − ½ log|K| − ½ n log 2π.
Requires a successful fit. Used for hyperparameter
optimization — higher is better.
Sourcepub fn fit_hyperparameters(
&mut self,
n_initial: usize,
iterations: usize,
n_candidates: usize,
seed: u64,
) -> Result<(), String>
pub fn fit_hyperparameters( &mut self, n_initial: usize, iterations: usize, n_candidates: usize, seed: u64, ) -> Result<(), String>
Optimize the kernel hyperparameters (length scale, signal variance, noise variance) by maximizing the log marginal likelihood.
Uses the crate’s own BayesianOptimizer over log-space
hyperparameters (dogfooding). iterations GP refits after the
initial random search; n_candidates EI candidates per iteration.
Sourcepub fn fit(&mut self) -> Result<(), String>
pub fn fit(&mut self) -> Result<(), String>
Fit the GP: compute L = cholesky(K + σ_n² I) and α = K⁻¹ y.
Returns an error if fewer than 2 samples are present.
Sourcepub fn predict(&self, x: &[f64]) -> Result<(f64, f64), String>
pub fn predict(&self, x: &[f64]) -> Result<(f64, f64), String>
Predict mean and variance at a query point.
Returns (mean, variance); variance includes observation noise.
Errors if not fitted.
Sourcepub const fn min_eigenvalue(&self) -> f64
pub const fn min_eigenvalue(&self) -> f64
Minimum Cholesky eigenvalue during fit (diagnostic).
Trait Implementations§
Source§impl Clone for GaussianProcess
impl Clone for GaussianProcess
Source§fn clone(&self) -> GaussianProcess
fn clone(&self) -> GaussianProcess
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more