qualia_core_db/solvers/learning/mod.rs
1//! Statistical learning (ISL) — predictive estimators built **on** the engine's
2//! existing foundation, never duplicating it (see `stats_plan.md`).
3//!
4//! Reuses: `solvers::linear_algebra` (gemm/qr/cholesky/eigen/svd) for the linear
5//! algebra, `solvers::statistics` (descriptive/distributions/correlation) for moments
6//! and p-values, and `platform::compute_bridge` for per-kernel-class dispatch.
7//!
8//! Categories (one method-family per sub-library, PROJECT RULE §13):
9//! [`metrics`], [`preprocessing`], [`regression`], [`glm`], [`classification`],
10//! [`resampling`], [`dimensionality`], [`clustering`], [`trees`], [`splines`],
11//! [`survival`], [`multiple_testing`].
12
13// Declared as each method-family lands (build order in `stats_plan.md`).
14pub mod active;
15pub mod classification;
16pub mod clustering;
17pub mod dimensionality;
18pub mod experiment;
19pub mod gaussian_process;
20pub mod glm;
21pub mod graphical_models;
22pub mod kg_embedding;
23pub mod metrics;
24pub mod multiple_testing;
25pub mod preprocessing;
26pub mod regression;
27pub mod resampling;
28pub mod sampling;
29pub mod sequential;
30pub mod splines;
31pub mod survival;
32pub mod trees;
33pub mod variational;
34
35/// Errors common to the learning estimators. Estimators **fail closed** (return an
36/// error) rather than emit a fabricated fit — consistent with the engine-wide
37/// honesty rule.
38#[derive(Debug, Clone, PartialEq, Eq)]
39pub enum LearningError {
40 /// Input shapes are inconsistent (lengths / row×col mismatch).
41 InvalidDimension,
42 /// Not enough data for the requested fit (e.g. fewer samples than parameters).
43 InsufficientData,
44 /// The system is singular / rank-deficient (e.g. collinear predictors) — fail
45 /// closed instead of returning a meaningless solution.
46 Singular,
47 /// An iterative fit did not converge within its iteration budget.
48 NotConverged,
49}
50
51impl core::fmt::Display for LearningError {
52 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
53 match self {
54 LearningError::InvalidDimension => write!(f, "inconsistent input dimensions"),
55 LearningError::InsufficientData => write!(f, "insufficient data for the requested fit"),
56 LearningError::Singular => write!(
57 f,
58 "singular / rank-deficient system (e.g. collinear predictors)"
59 ),
60 LearningError::NotConverged => write!(f, "iterative fit did not converge"),
61 }
62 }
63}
64impl std::error::Error for LearningError {}
65
66impl From<crate::solvers::SolversError> for LearningError {
67 fn from(e: crate::solvers::SolversError) -> Self {
68 use crate::solvers::SolversError as E;
69 match e {
70 E::InvalidDimension => LearningError::InvalidDimension,
71 E::SingularMatrix => LearningError::Singular,
72 _ => LearningError::InvalidDimension,
73 }
74 }
75}