pub struct ConvolutionProcess<S = Untrained> { /* private fields */ }Expand description
Convolution Process (a.k.a. Convolved / Dependent Gaussian Process) for multi-output regression.
See the module documentation for the generative model and the closed-form
induced covariance this type trains against. Use the builder methods below to
configure it, then call Fit::fit with one input matrix and one target vector
per output.
§Examples
use sklears_gaussian_process::ConvolutionProcess;
use sklears_core::traits::{Fit, Predict};
use scirs2_core::ndarray::array;
let x1 = array![[0.0], [1.0], [2.0], [3.0]];
let y1 = array![0.0, 1.0, 4.0, 9.0];
let x2 = array![[0.5], [2.5]];
let y2 = array![2.0, 17.0];
let cp = ConvolutionProcess::new().n_latent(1).noise_variance(1e-6);
let fitted = cp
.fit(&vec![x1, x2], &vec![y1, y2])
.expect("fit should succeed with valid training data");
let predictions = fitted
.predict(&vec![array![[1.5]], array![[1.0]]])
.expect("predict should succeed on a trained model");
assert_eq!(predictions.len(), 2);Implementations§
Source§impl ConvolutionProcess<Untrained>
impl ConvolutionProcess<Untrained>
Sourcepub fn default_length_scale(self, length_scale: f64) -> Self
pub fn default_length_scale(self, length_scale: f64) -> Self
Set the default per-dimension length scale used when Self::length_scales
is not supplied explicitly.
Sourcepub fn noise_variance(self, noise_variance: f64) -> Self
pub fn noise_variance(self, noise_variance: f64) -> Self
Set the default (uniform, per-output) noise variance used when
Self::noise_variances is not supplied explicitly.
Sourcepub fn length_scales(self, length_scales: Vec<Vec<Array1<f64>>>) -> Self
pub fn length_scales(self, length_scales: Vec<Vec<Array1<f64>>>) -> Self
Explicitly set the [output][latent] -> per-dimension length scale table.
The outer Vec must have one entry per output (matching the length of the
X passed to Fit::fit), each inner Vec one entry per latent process
(matching Self::n_latent), and each Array1 one length scale per input
dimension. Validated (and defaulted, if omitted) at fit time.
Sourcepub fn output_variances(self, output_variances: Vec<Vec<f64>>) -> Self
pub fn output_variances(self, output_variances: Vec<Vec<f64>>) -> Self
Explicitly set the [output][latent] -> signal variance table (same outer/
inner shape as Self::length_scales, minus the per-dimension axis).
Sourcepub fn noise_variances(self, noise_variances: Vec<f64>) -> Self
pub fn noise_variances(self, noise_variances: Vec<f64>) -> Self
Explicitly set a per-output noise variance (one entry per output).
Source§impl ConvolutionProcess<ConvolutionProcessTrained>
impl ConvolutionProcess<ConvolutionProcessTrained>
Sourcepub fn trained_state(&self) -> &ConvolutionProcessTrained
pub fn trained_state(&self) -> &ConvolutionProcessTrained
Access the full trained state.
Sourcepub fn log_marginal_likelihood(&self) -> f64
pub fn log_marginal_likelihood(&self) -> f64
Log marginal likelihood of the training data under the fitted model.
Sourcepub fn noise_variances(&self) -> &[f64]
pub fn noise_variances(&self) -> &[f64]
Resolved per-output noise variance actually used for training (one entry per output, in fit order).
Sourcepub fn induced_covariance(
&self,
output_d: usize,
output_dp: usize,
x: &ArrayView1<'_, f64>,
xp: &ArrayView1<'_, f64>,
) -> SklResult<f64>
pub fn induced_covariance( &self, output_d: usize, output_dp: usize, x: &ArrayView1<'_, f64>, xp: &ArrayView1<'_, f64>, ) -> SklResult<f64>
Evaluate the model’s induced covariance k_{d,d'}(x, x') between output
output_d and output output_dp (which may be equal) at arbitrary points,
using the fitted (or defaulted) hyperparameters. See the module
documentation for the closed-form formula being evaluated.
This is the direct, low-level way to inspect whether – and how strongly –
the model represents correlation between two outputs: for two genuinely
independent single-output GPs this would be identically zero everywhere,
whereas a convolution process sharing at least one latent process between
output_d and output_dp gives a nontrivial value.
Sourcepub fn training_covariance_matrix(&self) -> Array2<f64>
pub fn training_covariance_matrix(&self) -> Array2<f64>
Rebuild the full (noise-free) stacked multi-output covariance matrix over the training points, using the fitted hyperparameters. This is the matrix whose positive semi-definiteness is the key theoretical guarantee of the convolution-process construction (see module docs); exposed for diagnostics and testing.
Sourcepub fn predict_with_std(
&self,
X_test: &[Array2<f64>],
) -> SklResult<Vec<(Array1<f64>, Array1<f64>)>>
pub fn predict_with_std( &self, X_test: &[Array2<f64>], ) -> SklResult<Vec<(Array1<f64>, Array1<f64>)>>
Predict the posterior mean and standard deviation for each output at the
given per-output test points. X_test must have exactly n_outputs()
entries (one design matrix per output, in the same order as at fit time);
pass a zero-row matrix for any output you are not interested in predicting.
Trait Implementations§
Source§impl<S: Clone> Clone for ConvolutionProcess<S>
impl<S: Clone> Clone for ConvolutionProcess<S>
Source§impl<S: Debug> Debug for ConvolutionProcess<S>
impl<S: Debug> Debug for ConvolutionProcess<S>
Source§impl Default for ConvolutionProcess<Untrained>
impl Default for ConvolutionProcess<Untrained>
Source§impl Estimator for ConvolutionProcess<Untrained>
impl Estimator for ConvolutionProcess<Untrained>
Source§type Config = ConvolutionProcessConfig
type Config = ConvolutionProcessConfig
Source§type Error = SklearsError
type Error = SklearsError
Source§fn validate_config(&self) -> Result<(), SklearsError>
fn validate_config(&self) -> Result<(), SklearsError>
Source§fn check_compatibility(
&self,
n_samples: usize,
n_features: usize,
) -> Result<(), SklearsError>
fn check_compatibility( &self, n_samples: usize, n_features: usize, ) -> Result<(), SklearsError>
Source§fn metadata(&self) -> EstimatorMetadata
fn metadata(&self) -> EstimatorMetadata
Source§impl Estimator for ConvolutionProcess<ConvolutionProcessTrained>
impl Estimator for ConvolutionProcess<ConvolutionProcessTrained>
Source§type Config = ConvolutionProcessConfig
type Config = ConvolutionProcessConfig
Source§type Error = SklearsError
type Error = SklearsError
Source§fn validate_config(&self) -> Result<(), SklearsError>
fn validate_config(&self) -> Result<(), SklearsError>
Source§fn check_compatibility(
&self,
n_samples: usize,
n_features: usize,
) -> Result<(), SklearsError>
fn check_compatibility( &self, n_samples: usize, n_features: usize, ) -> Result<(), SklearsError>
Source§fn metadata(&self) -> EstimatorMetadata
fn metadata(&self) -> EstimatorMetadata
Source§impl Fit<Vec<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>>, Vec<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>>> for ConvolutionProcess<Untrained>
impl Fit<Vec<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>>, Vec<ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>>> for ConvolutionProcess<Untrained>
Source§type Fitted = ConvolutionProcess<ConvolutionProcessTrained>
type Fitted = ConvolutionProcess<ConvolutionProcessTrained>
Source§fn fit(
self,
X: &Vec<Array2<f64>>,
Y: &Vec<Array1<f64>>,
) -> SklResult<Self::Fitted>
fn fit( self, X: &Vec<Array2<f64>>, Y: &Vec<Array1<f64>>, ) -> SklResult<Self::Fitted>
Source§fn fit_with_validation(
self,
x: &X,
y: &Y,
_x_val: Option<&X>,
_y_val: Option<&Y>,
) -> Result<(Self::Fitted, FitMetrics), SklearsError>where
Self: Sized,
fn fit_with_validation(
self,
x: &X,
y: &Y,
_x_val: Option<&X>,
_y_val: Option<&Y>,
) -> Result<(Self::Fitted, FitMetrics), SklearsError>where
Self: Sized,
Auto Trait Implementations§
impl<S> Freeze for ConvolutionProcess<S>where
S: Freeze,
impl<S> RefUnwindSafe for ConvolutionProcess<S>where
S: RefUnwindSafe,
impl<S> Send for ConvolutionProcess<S>where
S: Send,
impl<S> Sync for ConvolutionProcess<S>where
S: Sync,
impl<S> Unpin for ConvolutionProcess<S>where
S: Unpin,
impl<S> UnsafeUnpin for ConvolutionProcess<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for ConvolutionProcess<S>where
S: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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