Skip to main content

hyprstream_calibration/
error.rs

1//! Error type for metric and conformal computations.
2
3use thiserror::Error;
4
5/// Errors returned by metric, conformal, and protocol computations.
6#[derive(Debug, Error, Clone, PartialEq)]
7pub enum MetricError {
8    /// An input slice was empty where at least one observation is required.
9    #[error("empty input: {0} requires at least one observation")]
10    EmptyInput(&'static str),
11
12    /// Parallel input slices had different lengths.
13    #[error("length mismatch: {left_name} has {left} rows but {right_name} has {right}")]
14    LengthMismatch {
15        /// Name of the first input.
16        left_name: &'static str,
17        /// Length of the first input.
18        left: usize,
19        /// Name of the second input.
20        right_name: &'static str,
21        /// Length of the second input.
22        right: usize,
23    },
24
25    /// A probability vector failed validation.
26    #[error("invalid distribution at observation {index}: {reason}")]
27    InvalidDistribution {
28        /// Row index of the offending observation.
29        index: usize,
30        /// Why the distribution is invalid.
31        reason: String,
32    },
33
34    /// A label index was out of range for its distribution.
35    #[error("label {label} out of range for distribution of width {width} at observation {index}")]
36    InvalidLabel {
37        /// Row index of the offending observation.
38        index: usize,
39        /// The offending label index.
40        label: usize,
41        /// Distribution width (number of classes/levels).
42        width: usize,
43    },
44
45    /// A bin count was zero or exceeded the observation count.
46    #[error("invalid bin count {bins}: need 1 <= bins <= n ({n})")]
47    InvalidBinCount {
48        /// Requested number of bins.
49        bins: usize,
50        /// Number of observations.
51        n: usize,
52    },
53
54    /// A miscoverage / confidence level outside (0, 1).
55    #[error("invalid level {value}: must lie strictly inside (0, 1)")]
56    InvalidLevel {
57        /// The offending level.
58        value: f64,
59    },
60
61    /// A shift split was constructed with overlapping fit and evaluation families.
62    #[error(
63        "shift split violation: families {families:?} appear on both the fit and evaluation side"
64    )]
65    ShiftSplitOverlap {
66        /// The overlapping family identifiers.
67        families: Vec<String>,
68    },
69}