Skip to main content

linfa_logistic/
error.rs

1use thiserror::Error;
2pub type Result<T> = std::result::Result<T, Error>;
3
4#[derive(Error, Debug)]
5pub enum Error {
6    #[error(transparent)]
7    LinfaError(#[from] linfa::Error),
8    #[error("More than two classes for logistic regression")]
9    TooManyClasses,
10    #[error("Fewer than two classes for logistic regression")]
11    TooFewClasses,
12    #[error(transparent)]
13    ArgMinError(#[from] argmin::core::Error),
14    #[error("Expected `x` and `y` to have same number of rows, got {0} != {1}")]
15    MismatchedShapes(usize, usize),
16    #[error("Values must be finite and not `Inf`, `-Inf` or `NaN`")]
17    InvalidValues,
18    #[error("Rows of initial parameter ({rows}) must be the same as the number of features ({n_features})")]
19    InitialParameterFeaturesMismatch { rows: usize, n_features: usize },
20    #[error("Columns of initial parameter ({cols}) must be the same as the number of classes ({n_classes})")]
21    InitialParameterClassesMismatch { cols: usize, n_classes: usize },
22    #[error("gradient_tolerance must be a positive, finite number")]
23    InvalidGradientTolerance,
24    #[error("alpha must be a positive, finite number")]
25    InvalidAlpha,
26    #[error("Initial parameters must be finite")]
27    InvalidInitialParameters,
28    #[error("Offset must be finite")]
29    InvalidOffset,
30    #[error("Offset length ({offset_len}) must match the number of samples ({n_samples})")]
31    OffsetLengthMismatch { offset_len: usize, n_samples: usize },
32}