pub struct BayesianGaussianMixture<S = Untrained> { /* private fields */ }Expand description
Bayesian Gaussian Mixture Model
A Bayesian variant of Gaussian mixture model that uses variational inference to automatically determine the effective number of components. This implementation provides uncertainty quantification and automatic model selection capabilities.
The model uses variational Bayesian inference with proper priors on the mixture weights, means, and covariances to enable automatic component selection.
§Parameters
n_components- Maximum number of mixture componentscovariance_type- Type of covariance parameters (currently supports “full”)tol- Convergence threshold for the variational lower boundreg_covar- Regularization added to the diagonal of covariancemax_iter- Maximum number of variational EM iterationsrandom_state- Random state for reproducibilitywarm_start- Whether to use previous fit as initializationweight_concentration_prior_type- Type of prior on mixture weightsweight_concentration_prior- Prior concentration parameter for mixture weightsmean_precision_prior- Prior precision for component meansmean_prior- Prior mean for component meansdegrees_of_freedom_prior- Prior degrees of freedom for covariance matricescovariance_prior- Prior scale for covariance matrices
§Examples
use sklears_mixture::{BayesianGaussianMixture, 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 bgmm = BayesianGaussianMixture::new()
.n_components(4) // Will automatically select effective number
.max_iter(100);
let fitted = bgmm.fit(&X.view(), &()).unwrap();
let labels = fitted.predict(&X.view()).unwrap();
println!("Effective components: {}", fitted.n_components_effective());Implementations§
Source§impl BayesianGaussianMixture<Untrained>
impl BayesianGaussianMixture<Untrained>
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: String) -> Self
pub fn covariance_type(self, covariance_type: String) -> 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 warm_start(self, warm_start: bool) -> Self
pub fn warm_start(self, warm_start: bool) -> Self
Set warm start
Sourcepub fn weight_concentration_prior_type(self, prior_type: String) -> Self
pub fn weight_concentration_prior_type(self, prior_type: String) -> Self
Set weight concentration prior type
Sourcepub fn weight_concentration_prior(self, prior: f64) -> Self
pub fn weight_concentration_prior(self, prior: f64) -> Self
Set weight concentration prior
Sourcepub fn mean_precision_prior(self, prior: f64) -> Self
pub fn mean_precision_prior(self, prior: f64) -> Self
Set mean precision prior
Source§impl BayesianGaussianMixture<BayesianGaussianMixtureTrained>
impl BayesianGaussianMixture<BayesianGaussianMixtureTrained>
Sourcepub fn covariances(&self) -> &[Array2<f64>] ⓘ
pub fn covariances(&self) -> &[Array2<f64>] ⓘ
Get the component covariances
Sourcepub fn n_components_effective(&self) -> usize
pub fn n_components_effective(&self) -> usize
Get the effective number of components
Sourcepub fn lower_bound(&self) -> f64
pub fn lower_bound(&self) -> f64
Get the lower bound on the log likelihood
Sourcepub fn predict_proba(&self, X: &ArrayView2<'_, Float>) -> SklResult<Array2<f64>>
pub fn predict_proba(&self, X: &ArrayView2<'_, Float>) -> SklResult<Array2<f64>>
Predict probabilities for each component
Sourcepub fn score_samples(&self, X: &ArrayView2<'_, Float>) -> SklResult<Array1<f64>>
pub fn score_samples(&self, X: &ArrayView2<'_, Float>) -> SklResult<Array1<f64>>
Compute the per-sample log-likelihood
Trait Implementations§
Source§impl<S: Clone> Clone for BayesianGaussianMixture<S>
impl<S: Clone> Clone for BayesianGaussianMixture<S>
Source§fn clone(&self) -> BayesianGaussianMixture<S>
fn clone(&self) -> BayesianGaussianMixture<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 BayesianGaussianMixture<S>
impl<S: Debug> Debug for BayesianGaussianMixture<S>
Source§impl Default for BayesianGaussianMixture<Untrained>
impl Default for BayesianGaussianMixture<Untrained>
Source§impl Estimator for BayesianGaussianMixture<Untrained>
impl Estimator for BayesianGaussianMixture<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 BayesianGaussianMixture<Untrained>
impl Fit<ArrayBase<ViewRepr<&f64>, Dim<[usize; 2]>>, ()> for BayesianGaussianMixture<Untrained>
Source§type Fitted = BayesianGaussianMixture<BayesianGaussianMixtureTrained>
type Fitted = BayesianGaussianMixture<BayesianGaussianMixtureTrained>
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 BayesianGaussianMixture<BayesianGaussianMixtureTrained>
impl Predict<ArrayBase<ViewRepr<&f64>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<i32>, Dim<[usize; 1]>>> for BayesianGaussianMixture<BayesianGaussianMixtureTrained>
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 BayesianGaussianMixture<S>where
S: Freeze,
impl<S> RefUnwindSafe for BayesianGaussianMixture<S>where
S: RefUnwindSafe,
impl<S> Send for BayesianGaussianMixture<S>where
S: Send,
impl<S> Sync for BayesianGaussianMixture<S>where
S: Sync,
impl<S> Unpin for BayesianGaussianMixture<S>where
S: Unpin,
impl<S> UnwindSafe for BayesianGaussianMixture<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