Struct egobox_gp::GaussianProcess

source ·
pub struct GaussianProcess<F: Float, Mean: RegressionModel<F>, Corr: CorrelationModel<F>> { /* private fields */ }
Expand description

A GP regression is an interpolation method where the interpolated values are modeled by a Gaussian process with a mean and governed by a prior covariance kernel, which depends on some parameters to be determined.

The interpolated output is modeled as stochastic process as follows:

Y(x) = mu(x) + Z(x)

where:

  • mu(x) is the trend i.e. the mean of the gaussian process
  • Z(x) the realization of stochastic gaussian process ~ Normal(0, sigma^2)

which in turn is written as:

Y(x) = betas.regr(x) + sigma^2*corr(x, x')

where:

  • betas is a vector of linear regression parameters to be determined
  • regr(x) a vector of polynomial basis functions
  • sigma^2 is the process variance
  • corr(x, x') is a correlation function which depends on distance(x, x') and a set of unknown parameters thetas to be determined.

§Implementation

  • Based on ndarray and linfa and strive to follow linfa guidelines
  • GP mean model can be constant, linear or quadratic
  • GP correlation model can be build the following kernels: squared exponential, absolute exponential, matern 3/2, matern 5/2
    cf. SMT Kriging
  • For high dimensional problems, the classic GP algorithm does not perform well as it depends on the inversion of a correlation (n, n) matrix which is an O(n3) operation. To work around this problem the library implements dimension reduction using Partial Least Squares method upon Kriging method also known as KPLS algorithm (see Reference)
  • GP models can be saved and loaded using serde. See serializable feature section below.

§Features

§serializable

The serializable feature enables the serialization of GP models using the serde crate.

§blas

The blas feature enables the use of BLAS/LAPACK linear algebra backend available with ndarray-linalg.

§Example

use egobox_gp::{correlation_models::*, mean_models::*, GaussianProcess};
use linfa::prelude::*;
use ndarray::{arr2, concatenate, Array, Array2, Axis};

// one-dimensional test function to approximate
fn xsinx(x: &Array2<f64>) -> Array2<f64> {
    (x - 3.5) * ((x - 3.5) / std::f64::consts::PI).mapv(|v| v.sin())
}

// training data
let xt = arr2(&[[0.0], [5.0], [10.0], [15.0], [18.0], [20.0], [25.0]]);
let yt = xsinx(&xt);

// GP with constant mean model and squared exponential correlation model
// i.e. Oridinary Kriging model
let kriging = GaussianProcess::<f64, ConstantMean, SquaredExponentialCorr>::params(
                ConstantMean::default(),
                SquaredExponentialCorr::default())
                .fit(&Dataset::new(xt, yt))
                .expect("Kriging trained");

// Use trained model for making predictions
let xtest = Array::linspace(0., 25., 26).insert_axis(Axis(1));
let ytest = xsinx(&xtest);

let ypred = kriging.predict(&xtest).expect("Kriging prediction");
let yvariances = kriging.predict_var(&xtest).expect("Kriging prediction");  

§Reference:

Bouhlel, Mohamed Amine, et al. Improving kriging surrogates of high-dimensional design models by Partial Least Squares dimension reduction Structural and Multidisciplinary Optimization 53.5 (2016): 935-952.

Implementations§

source§

impl<F: Float, Mean: RegressionModel<F>, Corr: CorrelationModel<F>> GaussianProcess<F, Mean, Corr>

source

pub fn params<NewMean: RegressionModel<F>, NewCorr: CorrelationModel<F>>( mean: NewMean, corr: NewCorr ) -> GpParams<F, NewMean, NewCorr>

Gp parameters contructor

source

pub fn predict( &self, x: &ArrayBase<impl Data<Elem = F>, Ix2> ) -> Result<Array2<F>>

Predict output values at n given x points of nx components specified as a (n, nx) matrix. Returns n scalar output values as (n, 1) column vector.

source

pub fn predict_var( &self, x: &ArrayBase<impl Data<Elem = F>, Ix2> ) -> Result<Array2<F>>

Predict variance values at n given x points of nx components specified as a (n, nx) matrix. Returns n variance values as (n, 1) column vector.

source

pub fn sample_chol( &self, x: &ArrayBase<impl Data<Elem = F>, Ix2>, n_traj: usize ) -> Array2<F>

Sample the gaussian process for n_traj trajectories using cholesky decomposition

source

pub fn sample_eig( &self, x: &ArrayBase<impl Data<Elem = F>, Ix2>, n_traj: usize ) -> Array2<F>

Sample the gaussian process for n_traj trajectories using eigenvalues decomposition

source

pub fn sample( &self, x: &ArrayBase<impl Data<Elem = F>, Ix2>, n_traj: usize ) -> Array2<F>

Sample the gaussian process for n_traj trajectories using eigenvalues decomposition (alias of sample_eig)

source

pub fn theta(&self) -> &Array1<F>

Retrieve optimized hyperparameters theta

source

pub fn variance(&self) -> F

Estimated variance

source

pub fn likelihood(&self) -> F

Retrieve reduced likelihood value

source

pub fn kpls_dim(&self) -> Option<usize>

Retrieve number of PLS components 1 <= n <= x dimension

source

pub fn input_dim(&self) -> usize

Retrieve input dimension before kpls dimension reduction if any

source

pub fn output_dim(&self) -> usize

Retrieve output dimension

source

pub fn predict_kth_derivatives( &self, x: &ArrayBase<impl Data<Elem = F>, Ix2>, kx: usize ) -> Array1<F>

Predict derivatives of the output prediction wrt the kxth component at a set of n points x specified as a (n, nx) matrix where x has nx components.

source

pub fn predict_gradients( &self, x: &ArrayBase<impl Data<Elem = F>, Ix2> ) -> Array2<F>

Predict derivatives at a set of point x specified as a (n, nx) matrix where x has nx components. Returns a (n, nx) matrix containing output derivatives at x wrt each nx components

source

pub fn predict_jacobian( &self, x: &ArrayBase<impl Data<Elem = F>, Ix1> ) -> Array2<F>

Predict gradient at a given x point Note: output is one dimensional, named jacobian as result is given as a one-column matrix

source

pub fn predict_var_gradients_single( &self, x: &ArrayBase<impl Data<Elem = F>, Ix1> ) -> Array1<F>

Predict variance derivatives at a point x specified as a (nx,) vector where x has nx components. Returns a (nx,) vector containing variance derivatives at x wrt each nx components

source

pub fn predict_var_gradients( &self, x: &ArrayBase<impl Data<Elem = F>, Ix2> ) -> Array2<F>

Predict variance derivatives at a set of points x specified as a (n, nx) matrix where x has nx components. Returns a (n, nx) matrix containing variance derivatives at x wrt each nx components

Trait Implementations§

source§

impl<F: Float, Mean: RegressionModel<F>, Corr: CorrelationModel<F>> Clone for GaussianProcess<F, Mean, Corr>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<F: Debug + Float, Mean: Debug + RegressionModel<F>, Corr: Debug + CorrelationModel<F>> Debug for GaussianProcess<F, Mean, Corr>

source§

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

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

impl<F: Float, Mean: RegressionModel<F>, Corr: CorrelationModel<F>> Display for GaussianProcess<F, Mean, Corr>

source§

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

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

impl<F, D, Mean, Corr> PredictInplace<ArrayBase<D, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>> for GaussianProcess<F, Mean, Corr>
where F: Float, D: Data<Elem = F>, Mean: RegressionModel<F>, Corr: CorrelationModel<F>,

source§

fn predict_inplace(&self, x: &ArrayBase<D, Ix2>, y: &mut Array2<F>)

Predict something in place
source§

fn default_target(&self, x: &ArrayBase<D, Ix2>) -> Array2<F>

Create targets that predict_inplace works with.

Auto Trait Implementations§

§

impl<F, Mean, Corr> Freeze for GaussianProcess<F, Mean, Corr>
where F: Freeze, Mean: Freeze, Corr: Freeze,

§

impl<F, Mean, Corr> RefUnwindSafe for GaussianProcess<F, Mean, Corr>
where F: RefUnwindSafe, Mean: RefUnwindSafe, Corr: RefUnwindSafe,

§

impl<F, Mean, Corr> Send for GaussianProcess<F, Mean, Corr>
where Mean: Send, Corr: Send,

§

impl<F, Mean, Corr> Sync for GaussianProcess<F, Mean, Corr>

§

impl<F, Mean, Corr> Unpin for GaussianProcess<F, Mean, Corr>
where Mean: Unpin, Corr: Unpin,

§

impl<F, Mean, Corr> UnwindSafe for GaussianProcess<F, Mean, Corr>
where F: UnwindSafe + RefUnwindSafe, Mean: UnwindSafe, Corr: UnwindSafe,

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> 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<'a, F, D, DM, T, O> Predict<&'a ArrayBase<D, DM>, T> for O
where D: Data<Elem = F>, DM: Dimension, O: PredictInplace<ArrayBase<D, DM>, T>,

source§

fn predict(&self, records: &'a ArrayBase<D, DM>) -> T

source§

impl<'a, F, R, T, S, O> Predict<&'a DatasetBase<R, T>, S> for O
where R: Records<Elem = F>, O: PredictInplace<R, S>,

source§

fn predict(&self, ds: &'a DatasetBase<R, T>) -> S

source§

impl<F, D, E, T, O> Predict<ArrayBase<D, Dim<[usize; 2]>>, DatasetBase<ArrayBase<D, Dim<[usize; 2]>>, T>> for O
where D: Data<Elem = F>, T: AsTargets<Elem = E>, O: PredictInplace<ArrayBase<D, Dim<[usize; 2]>>, T>,

source§

fn predict( &self, records: ArrayBase<D, Dim<[usize; 2]>> ) -> DatasetBase<ArrayBase<D, Dim<[usize; 2]>>, T>

source§

impl<F, R, T, E, S, O> Predict<DatasetBase<R, T>, DatasetBase<R, S>> for O
where R: Records<Elem = F>, S: AsTargets<Elem = E>, O: PredictInplace<R, S>,

source§

fn predict(&self, ds: DatasetBase<R, T>) -> DatasetBase<R, S>

source§

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

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> SendAlias for T

source§

impl<T> SyncAlias for T