pub struct VariationalBayesianGMM<S = Untrained> { /* private fields */ }Expand description
Variational Bayesian Gaussian Mixture Model
This implementation uses variational inference to perform Bayesian parameter estimation for Gaussian mixture models. Unlike standard EM, this approach provides uncertainty estimates and automatic model selection by effectively “turning off” unnecessary components.
§Parameters
n_components- Maximum number of mixture components (actual number determined automatically)covariance_type- Type of covariance parameterstol- Convergence thresholdreg_covar- Regularization added to the diagonal of covariancemax_iter- Maximum number of variational iterationsrandom_state- Random state for reproducibilityweight_concentration_prior- Prior on the weight concentration parametermean_precision_prior- Prior precision for component meansdegrees_of_freedom_prior- Prior degrees of freedom for covariance matrices
§Examples
use sklears_mixture::{VariationalBayesianGMM, CovarianceType};
use sklears_core::traits::{Predict, Fit};
use scirs2_core::ndarray::array;
let X = array![[0.0, 0.0], [1.0, 1.0], [2.0, 2.0], [10.0, 10.0], [11.0, 11.0], [12.0, 12.0]];
let vbgmm = VariationalBayesianGMM::new()
.n_components(5) // Will automatically determine optimal number
.covariance_type(CovarianceType::Diagonal)
.max_iter(100);
let fitted = vbgmm.fit(&X.view(), &()).unwrap();
let labels = fitted.predict(&X.view()).unwrap();Implementations§
Source§impl VariationalBayesianGMM<Untrained>
impl VariationalBayesianGMM<Untrained>
Sourcepub fn builder() -> Self
pub fn builder() -> Self
Create a new VariationalBayesianGMM instance using builder pattern (alias for new)
Sourcepub fn n_components(self, n_components: usize) -> Self
pub fn n_components(self, n_components: usize) -> Self
Set the maximum number of components
Sourcepub fn covariance_type(self, covariance_type: CovarianceType) -> Self
pub fn covariance_type(self, covariance_type: CovarianceType) -> Self
Set the covariance type
Sourcepub fn random_state(self, random_state: u64) -> Self
pub fn random_state(self, random_state: u64) -> Self
Set the random state
Sourcepub fn weight_concentration_prior(self, prior: f64) -> Self
pub fn weight_concentration_prior(self, prior: f64) -> Self
Set the weight concentration prior
Sourcepub fn mean_precision_prior(self, prior: f64) -> Self
pub fn mean_precision_prior(self, prior: f64) -> Self
Set the mean precision prior
Sourcepub fn degrees_of_freedom_prior(self, prior: f64) -> Self
pub fn degrees_of_freedom_prior(self, prior: f64) -> Self
Set the degrees of freedom prior
Source§impl VariationalBayesianGMM<VariationalBayesianGMMTrained>
impl VariationalBayesianGMM<VariationalBayesianGMMTrained>
Sourcepub fn covariances(&self) -> &[Array2<f64>] ⓘ
pub fn covariances(&self) -> &[Array2<f64>] ⓘ
Get the fitted covariances
Sourcepub fn lower_bound(&self) -> f64
pub fn lower_bound(&self) -> f64
Get the variational lower bound
Sourcepub fn effective_components(&self) -> usize
pub fn effective_components(&self) -> usize
Get the number of effective components
Sourcepub fn weight_concentration(&self) -> &Array1<f64>
pub fn weight_concentration(&self) -> &Array1<f64>
Get the weight concentration parameters
Sourcepub fn mean_precision(&self) -> &Array1<f64>
pub fn mean_precision(&self) -> &Array1<f64>
Get the mean precision parameters
Sourcepub fn degrees_of_freedom(&self) -> &Array1<f64>
pub fn degrees_of_freedom(&self) -> &Array1<f64>
Get the degrees of freedom parameters
Trait Implementations§
Source§impl<S: Clone> Clone for VariationalBayesianGMM<S>
impl<S: Clone> Clone for VariationalBayesianGMM<S>
Source§fn clone(&self) -> VariationalBayesianGMM<S>
fn clone(&self) -> VariationalBayesianGMM<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 VariationalBayesianGMM<S>
impl<S: Debug> Debug for VariationalBayesianGMM<S>
Source§impl Default for VariationalBayesianGMM<Untrained>
impl Default for VariationalBayesianGMM<Untrained>
Source§impl Estimator for VariationalBayesianGMM<Untrained>
impl Estimator for VariationalBayesianGMM<Untrained>
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<ArrayBase<ViewRepr<&f64>, Dim<[usize; 2]>>, ()> for VariationalBayesianGMM<Untrained>
impl Fit<ArrayBase<ViewRepr<&f64>, Dim<[usize; 2]>>, ()> for VariationalBayesianGMM<Untrained>
Source§type Fitted = VariationalBayesianGMM<VariationalBayesianGMMTrained>
type Fitted = VariationalBayesianGMM<VariationalBayesianGMMTrained>
Source§fn fit(self, X: &ArrayView2<'_, Float>, _y: &()) -> SklResult<Self::Fitted>
fn fit(self, X: &ArrayView2<'_, Float>, _y: &()) -> 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,
Source§impl Predict<ArrayBase<ViewRepr<&f64>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<i32>, Dim<[usize; 1]>>> for VariationalBayesianGMM<VariationalBayesianGMMTrained>
impl Predict<ArrayBase<ViewRepr<&f64>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<i32>, Dim<[usize; 1]>>> for VariationalBayesianGMM<VariationalBayesianGMMTrained>
Source§fn predict(&self, X: &ArrayView2<'_, Float>) -> SklResult<Array1<i32>>
fn predict(&self, X: &ArrayView2<'_, Float>) -> SklResult<Array1<i32>>
Source§fn predict_with_uncertainty(
&self,
x: &X,
) -> Result<(Output, UncertaintyMeasure), SklearsError>
fn predict_with_uncertainty( &self, x: &X, ) -> Result<(Output, UncertaintyMeasure), SklearsError>
Auto Trait Implementations§
impl<S> Freeze for VariationalBayesianGMM<S>where
S: Freeze,
impl<S> RefUnwindSafe for VariationalBayesianGMM<S>where
S: RefUnwindSafe,
impl<S> Send for VariationalBayesianGMM<S>where
S: Send,
impl<S> Sync for VariationalBayesianGMM<S>where
S: Sync,
impl<S> Unpin for VariationalBayesianGMM<S>where
S: Unpin,
impl<S> UnwindSafe for VariationalBayesianGMM<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
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