1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//! Regularized statistical models with lazy matrix normalization.
//!
//! [`Lasso`] fits Gaussian lasso models using dense or sparse CSC columns.
//! Fits return original-scale parameters, reusable training preprocessing,
//! and explicit convergence diagnostics. See [`Lasso::terminate_on`] for the
//! stopping criterion and [`LassoFit::termination`] before using a fit.
//!
//! The primal objective is `P(beta_0, beta) = F(beta_0, beta) + R(beta)`,
//! with datafit `F`, complete penalty `R`, coefficients `beta`, and intercept
//! `beta_0`. For a feasible dual variable `theta`, the dual objective is
//! `D(theta)` and the duality gap is
//! `G(beta_0, beta, theta) = P(beta_0, beta) - D(theta)`.
//!
//! No matrix backend is enabled by default. Versioned features select
//! LazyMatrix's integrations with faer 0.24 (`faer_v0_24`), nalgebra 0.34 and
//! nalgebra-sparse 0.11 (`nalgebra_v0_34`), ndarray 0.17 (`ndarray_v0_17`), or
//! sprs 0.11 (`sprs_v0_11`). The short names `faer`, `nalgebra`, `ndarray`, and
//! `sprs` are aliases for these features. Match your direct matrix dependency
//! to the selected release line.
//!
//! LazyMatrix implements each enabled backend release independently, so
//! feature unification retains support for the selected matrix types.
//! faer CSC inputs also accept borrowed `SparseColMatRef` views, including
//! cross-validation, without first cloning the source matrix.
//!
//! With `ndarray_v0_17` or its `ndarray` alias, fit directly against an array or
//! borrowed view:
//!
//! ```
//! # #[cfg(feature = "ndarray_v0_17")] {
//! use ndarray::array;
//! use shrinkage::Lasso;
//!
//! let x = array![[0.0], [1.0], [2.0]];
//! let fit = Lasso::new(0.1).fit(&x.view(), &[1.0, 3.0, 5.0])?;
//! let predictions = fit.predict(&x)?;
//! # }
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! With `sprs_v0_11` or its `sprs` alias, wrap CSC storage in
//! `lazymatrix::SprsCsc`. Borrowing a view checks its orientation without copying
//! its entries:
//!
//! ```
//! # #[cfg(feature = "sprs_v0_11")] {
//! use shrinkage::{Lasso, lazymatrix::SprsCsc};
//! use sprs::CsMat;
//!
//! let x = CsMat::new_csc((3, 1), vec![0, 2], vec![1, 2], vec![1.0, 2.0]);
//! let columns = SprsCsc::try_new(x.view()).unwrap();
//! let fit = Lasso::new(0.1).fit(&columns, &[1.0, 3.0, 5.0])?;
//! let predictions = fit.predict(&columns)?;
//! # }
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! For CSR input, explicitly convert with `to_csc()` before wrapping. ndarray
//! supports row-major, column-major, and strided arrays; column-major storage
//! keeps each column contiguous for coordinate descent.
//!
//! [`lazymatrix::IndexedRows`] borrows a raw row selection. Normalization uses
//! only those observations, and predictions retain the original feature scale:
//!
//! ```
//! # #[cfg(feature = "ndarray_v0_17")] {
//! use ndarray::array;
//! use shrinkage::{Lasso, lazymatrix::IndexedRows};
//!
//! let x = array![[0.0], [100.0], [2.0]];
//! let rows = [0, 2];
//! let training = IndexedRows::new(&x, &rows);
//! let fit = Lasso::new(0.1).fit(&training, &[1.0, 5.0])?;
//! assert_eq!(fit.preprocessing().centers(), Some([1.0].as_slice()));
//! let predictions = fit.predict(&x)?;
//! # }
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! Indexed columns filter the source on each traversal. Built-in
//! cross-validation instead copies selected entries into owned fold matrices
//! once, keeping repeated solver sweeps on that storage.
pub use ;
pub use ;
pub use FitError as LassoError;
pub use ;
pub use ;
pub use CoefficientLayout;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// Matrix capabilities, borrowed columns, and lazy normalization.
pub use lazymatrix;