Skip to main content

GaussianProcess

Struct GaussianProcess 

Source
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: f64

Length scale ℓ.

§signal_variance: f64

Signal variance σ_f².

§noise_variance: f64

Observation noise variance σ_n².

Implementations§

Source§

impl GaussianProcess

Source

pub const fn new( length_scale: f64, signal_variance: f64, noise_variance: f64, ) -> Self

Create a GP with the given kernel hyperparameters.

Source

pub fn n_samples(&self) -> usize

Number of training samples.

Source

pub fn add_sample(&mut self, x: Vec<f64>, y: f64)

Add a training sample (x, y).

Source

pub fn set_hyperparameters( &mut self, length_scale: f64, signal_variance: f64, noise_variance: f64, )

Set kernel hyperparameters (all clamped to positive).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn min_eigenvalue(&self) -> f64

Minimum Cholesky eigenvalue during fit (diagnostic).

Trait Implementations§

Source§

impl Clone for GaussianProcess

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GaussianProcess

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GaussianProcess

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.