linfa_clustering/k_means/
errors.rs1use thiserror::Error;
2
3#[derive(Error, Debug)]
5pub enum KMeansParamsError {
6 #[error("n_clusters cannot be 0")]
7 NClusters,
8 #[error("n_runs cannot be 0")]
9 NRuns,
10 #[error("tolerance must be greater than 0")]
11 Tolerance,
12 #[error("max_n_iterations cannot be 0")]
13 MaxIterations,
14 #[error(
15 "only KMeansAlgorithm::Lloyd is supported by fit_with (Mini-Batch K-means); \
16 Hamerly requires a persistent dataset across iterations and cannot be used incrementally"
17 )]
18 IncrementalHamerly,
19}
20
21#[derive(Error, Debug)]
23pub enum KMeansError {
24 #[error("Invalid hyperparameter: {0}")]
26 InvalidParams(#[from] KMeansParamsError),
27 #[error("Fitting failed: No inertia improvement (-inf)")]
29 InertiaError,
30 #[error(transparent)]
31 LinfaError(#[from] linfa::error::Error),
32}
33
34#[derive(Error, Debug)]
35pub enum IncrKMeansError<M: std::fmt::Debug> {
36 #[error("Invalid hyperparameter: {0}")]
38 InvalidParams(#[from] KMeansParamsError),
39 #[error("Algorithm has not yet converged, Keep on running the algorithm.")]
42 NotConverged(M),
43 #[error(transparent)]
44 LinfaError(#[from] linfa::error::Error),
45}