pub struct MultiTaskGaussianProcessRegressor<S = Untrained> { /* private fields */ }Expand description
Multi-Task Gaussian Process Regressor
This implementation allows learning multiple related tasks simultaneously by sharing information through a shared latent function while maintaining task-specific variations.
§Mathematical Background
For each task t, the model assumes: f_t(x) = w_shared * f_shared(x) + w_task * f_task_t(x)
where the covariance between tasks i and j at points x and x’ is: cov[f_i(x), f_j(x’)] = w_shared² * k_shared(x, x’) + δ_{i,j} * w_task² * k_task(x, x’)
§Examples
use sklears_gaussian_process::{MultiTaskGaussianProcessRegressor, kernels::RBF};
use sklears_core::traits::{Fit, Predict};
// SciRS2 Policy - Use scirs2-autograd for ndarray types and operations
use scirs2_core::ndarray::array;
let X1 = array![[1.0], [2.0], [3.0], [4.0]];
let y1 = array![1.0, 4.0, 9.0, 16.0];
let X2 = array![[1.5], [2.5], [3.5], [4.5]];
let y2 = array![2.0, 6.0, 12.0, 20.0];
let shared_kernel = RBF::new(1.0);
let task_kernel = RBF::new(0.5);
let mtgp = MultiTaskGaussianProcessRegressor::new()
.shared_kernel(Box::new(shared_kernel))
.task_kernel(Box::new(task_kernel))
.alpha(1e-6);
let mut mtgp = mtgp.add_task("task1", &X1.view(), &y1.view()).unwrap();
mtgp = mtgp.add_task("task2", &X2.view(), &y2.view()).unwrap();
let fitted = mtgp.fit().unwrap();
let predictions = fitted.predict_task("task1", &X1.view()).unwrap();Implementations§
Source§impl MultiTaskGaussianProcessRegressor<Untrained>
impl MultiTaskGaussianProcessRegressor<Untrained>
Set the shared kernel function
Sourcepub fn task_kernel(self, kernel: Box<dyn Kernel>) -> Self
pub fn task_kernel(self, kernel: Box<dyn Kernel>) -> Self
Set the task-specific kernel function
Set the weight for the shared component
Sourcepub fn task_weight(self, weight: f64) -> Self
pub fn task_weight(self, weight: f64) -> Self
Set the weight for the task-specific components
Sourcepub fn add_task(
self,
task_name: &str,
X: &ArrayView2<'_, f64>,
y: &ArrayView1<'_, f64>,
) -> SklResult<Self>
pub fn add_task( self, task_name: &str, X: &ArrayView2<'_, f64>, y: &ArrayView1<'_, f64>, ) -> SklResult<Self>
Add a task with its training data
Sourcepub fn remove_task(self, task_name: &str) -> Self
pub fn remove_task(self, task_name: &str) -> Self
Remove a task
Sourcepub fn task_names(&self) -> Vec<String>
pub fn task_names(&self) -> Vec<String>
Get the list of task names
Source§impl MultiTaskGaussianProcessRegressor<Untrained>
impl MultiTaskGaussianProcessRegressor<Untrained>
Sourcepub fn fit(self) -> SklResult<MultiTaskGaussianProcessRegressor<MtgpTrained>>
pub fn fit(self) -> SklResult<MultiTaskGaussianProcessRegressor<MtgpTrained>>
Fit the multi-task Gaussian process
Source§impl MultiTaskGaussianProcessRegressor<MtgpTrained>
impl MultiTaskGaussianProcessRegressor<MtgpTrained>
Sourcepub fn trained_state(&self) -> &MtgpTrained
pub fn trained_state(&self) -> &MtgpTrained
Access the trained state
Sourcepub fn log_marginal_likelihood_task(&self, task_name: &str) -> Option<f64>
pub fn log_marginal_likelihood_task(&self, task_name: &str) -> Option<f64>
Get the log marginal likelihood for a specific task
Sourcepub fn log_marginal_likelihoods(&self) -> &HashMap<String, f64>
pub fn log_marginal_likelihoods(&self) -> &HashMap<String, f64>
Get all log marginal likelihoods
Sourcepub fn task_names(&self) -> Vec<String>
pub fn task_names(&self) -> Vec<String>
Get the list of available tasks
Sourcepub fn predict_task(
&self,
task_name: &str,
X: &ArrayView2<'_, f64>,
) -> SklResult<Array1<f64>>
pub fn predict_task( &self, task_name: &str, X: &ArrayView2<'_, f64>, ) -> SklResult<Array1<f64>>
Predict for a specific task
Sourcepub fn predict_task_components(
&self,
task_name: &str,
X: &ArrayView2<'_, f64>,
) -> SklResult<(Array1<f64>, Array1<f64>)>
pub fn predict_task_components( &self, task_name: &str, X: &ArrayView2<'_, f64>, ) -> SklResult<(Array1<f64>, Array1<f64>)>
Get shared and task-specific contributions separately
Trait Implementations§
Source§impl<S: Clone> Clone for MultiTaskGaussianProcessRegressor<S>
impl<S: Clone> Clone for MultiTaskGaussianProcessRegressor<S>
Source§fn clone(&self) -> MultiTaskGaussianProcessRegressor<S>
fn clone(&self) -> MultiTaskGaussianProcessRegressor<S>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<S: Debug> Debug for MultiTaskGaussianProcessRegressor<S>
impl<S: Debug> Debug for MultiTaskGaussianProcessRegressor<S>
Source§impl Estimator for MultiTaskGaussianProcessRegressor<Untrained>
impl Estimator for MultiTaskGaussianProcessRegressor<Untrained>
Source§type Config = MtgpConfig
type Config = MtgpConfig
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 MultiTaskGaussianProcessRegressor<MtgpTrained>
impl Estimator for MultiTaskGaussianProcessRegressor<MtgpTrained>
Source§type Config = MtgpConfig
type Config = MtgpConfig
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
Auto Trait Implementations§
impl<S> Freeze for MultiTaskGaussianProcessRegressor<S>where
S: Freeze,
impl<S = Untrained> !RefUnwindSafe for MultiTaskGaussianProcessRegressor<S>
impl<S> Send for MultiTaskGaussianProcessRegressor<S>where
S: Send,
impl<S> Sync for MultiTaskGaussianProcessRegressor<S>where
S: Sync,
impl<S> Unpin for MultiTaskGaussianProcessRegressor<S>where
S: Unpin,
impl<S = Untrained> !UnwindSafe for MultiTaskGaussianProcessRegressor<S>
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
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