linfa_clustering/gaussian_mixture/
errors.rs

1use crate::k_means::KMeansError;
2#[cfg(not(feature = "blas"))]
3use linfa_linalg::LinalgError;
4#[cfg(feature = "blas")]
5use ndarray_linalg::error::LinalgError;
6use thiserror::Error;
7
8/// An error when modeling a GMM algorithm
9#[derive(Error, Debug)]
10pub enum GmmError {
11    /// When any of the hyperparameters are set the wrong value
12    #[error("Invalid value encountered: {0}")]
13    InvalidValue(String),
14    /// Errors encountered during linear algebra operations
15    #[error(
16        "Linalg Error: \
17    Fitting the mixture model failed because some components have \
18    ill-defined empirical covariance (for instance caused by singleton \
19    or collapsed samples). Try to decrease the number of components, \
20    or increase reg_covar. Error: {0}"
21    )]
22    LinalgError(#[from] LinalgError),
23    /// When a cluster has no more data point while fitting GMM
24    #[error("Fitting failed: {0}")]
25    EmptyCluster(String),
26    /// When lower bound computation fails
27    #[error("Fitting failed: {0}")]
28    LowerBoundError(String),
29    /// When fitting EM algorithm does not converge
30    #[error("Fitting failed: {0}")]
31    NotConverged(String),
32    /// When initial KMeans fails
33    #[error("Initial KMeans failed: {0}")]
34    KMeansError(#[from] KMeansError),
35    #[error(transparent)]
36    LinfaError(#[from] linfa::error::Error),
37    #[error(transparent)]
38    MinMaxError(#[from] ndarray_stats::errors::MinMaxError),
39}