robust_rs_core/error.rs
1//! Error type for the `robust-rs-core` crate.
2
3use thiserror::Error;
4
5/// Errors returned by robust estimation routines.
6#[derive(Debug, Clone, PartialEq, Error)]
7pub enum RobustError {
8 /// An iterative solver failed to converge within the iteration cap.
9 #[error("solver did not converge within {iters} iterations")]
10 NonConvergence {
11 /// Iterations performed before giving up.
12 iters: usize,
13 },
14 /// The (weighted) design matrix is singular or rank-deficient.
15 #[error("design matrix is singular or rank-deficient")]
16 SingularDesign,
17 /// The robust scale collapsed to zero (e.g. more than half the data tied).
18 #[error("scale estimate is zero or non-finite (degenerate data)")]
19 DegenerateScale,
20 /// Not enough observations for the requested estimator.
21 #[error("insufficient data: needed {needed}, got {got}")]
22 InsufficientData {
23 /// Minimum number of observations required.
24 needed: usize,
25 /// Number of observations supplied.
26 got: usize,
27 },
28 /// A tuning constant was outside its valid range.
29 #[error("invalid tuning constant: {value}")]
30 InvalidTuning {
31 /// The offending value.
32 value: f64,
33 },
34 /// Subsampling (FAST-MCD / FAST-LTS) failed to find a valid subset.
35 #[error("subsampling failed to produce a valid subset")]
36 SubsampleFailure,
37 /// Input arrays have inconsistent lengths.
38 #[error("dimension mismatch: expected length {expected}, got {got}")]
39 DimensionMismatch {
40 /// The length that was required.
41 expected: usize,
42 /// The length that was supplied.
43 got: usize,
44 },
45 /// A weight was negative or non-finite.
46 #[error("invalid weight: {value} (weights must be finite and non-negative)")]
47 InvalidWeight {
48 /// The offending weight.
49 value: f64,
50 },
51 /// A scale that requires a bounded loss (the S-scale) was given a loss with
52 /// unbounded `ρ` (`rho_sup() == None`), which cannot define a high-breakdown
53 /// scale.
54 #[error("loss has unbounded ρ (rho_sup is None); it cannot define an S-scale")]
55 UnboundedLoss,
56}