# shrinkage::Irls

Shrinkage for Rust · 0.3.0

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/solver/irls.rs>)

```rust
pub struct Irls
```

Iteratively reweighted least squares with coordinate-descent inner solves. 

Fits differentiable losses with nonnegative diagonal working curvature and separable convex penalties. For nonconvex losses, KKT checks certify stationarity rather than global optimality. Backtracking evaluates the original penalized objective. The quadratic model floors predictor curvature at `1e-12 / nobs`, leaving the original loss, gradient, and convergence check unchanged. Working sets use restricted checks between complete KKT checks. No safe screening or dual certificate is provided. 

Solver workspace is `O(nobs + nfeatures)`. Weighted column norms use LazyMatrix's `O(nobs + nnz)` operation once per column per outer iteration. Noncanonical sparse columns can require temporary `O(nobs)` scratch there. 

```rust
use faer::Mat;
use shrinkage::{Binomial, Irls, L1, Problem};
let x = Mat::from_fn(4, 1, |i, _| i as f64);
let y = [0.0, 0.0, 1.0, 1.0];
let fit = Problem::new(&x, Binomial::new(&y), L1::new(0.1))
    .fit_with(&Irls::new())?;
let logits = fit.predict(&x)?;
```

<a id="impl-d42788084a3c17dbcddc5c95a450b20fbb6721d3be7762845cd0d0b08358ce10"></a>

## Inherent implementation

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/solver/irls.rs>)

```rust
impl Irls
```

<a id="method-max_backtracks-d42788084a3c17dbcddc5c95a450b20fbb6721d3be7762845cd0d0b08358ce10"></a>

### `max_backtracks`

```rust
pub fn max_backtracks(self, count: usize) -> Self
```

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/solver/irls.rs>)

Set the maximum number of halvings after the initial full-step trial. 

<a id="method-max_inner_iterations-d42788084a3c17dbcddc5c95a450b20fbb6721d3be7762845cd0d0b08358ce10"></a>

### `max_inner_iterations`

```rust
pub fn max_inner_iterations(self, count: usize) -> Self
```

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/solver/irls.rs>)

Set the strictly positive sweep limit for each quadratic model. An inexact inner solve may still supply an accepted descent direction. 

<a id="method-max_iterations-d42788084a3c17dbcddc5c95a450b20fbb6721d3be7762845cd0d0b08358ce10"></a>

### `max_iterations`

```rust
pub fn max_iterations(self, count: usize) -> Self
```

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/solver/irls.rs>)

Set the strictly positive maximum number of accepted outer steps. 

<a id="method-new-d42788084a3c17dbcddc5c95a450b20fbb6721d3be7762845cd0d0b08358ce10"></a>

### `new`

```rust
pub fn new() -> Self
```

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/solver/irls.rs>)

Use KKT tolerance `1e-6`, 100 outer iterations, 1,000 inner sweeps per outer iteration, at most 100 step halvings, and working sets. 

<a id="method-terminate_on-d42788084a3c17dbcddc5c95a450b20fbb6721d3be7762845cd0d0b08358ce10"></a>

### `terminate_on`

```rust
pub fn terminate_on(self, criterion: StoppingCriterion) -> Self
```

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/solver/irls.rs>)

Select a stopping rule. Only absolute KKT violation is supported. 

<a id="method-tolerance-d42788084a3c17dbcddc5c95a450b20fbb6721d3be7762845cd0d0b08358ce10"></a>

### `tolerance`

```rust
pub fn tolerance(self, tolerance: f64) -> Self
```

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/solver/irls.rs>)

Set the finite, strictly positive absolute KKT tolerance. 

<a id="method-working_set_policy-d42788084a3c17dbcddc5c95a450b20fbb6721d3be7762845cd0d0b08358ce10"></a>

### `working_set_policy`

```rust
pub fn working_set_policy(self, policy: WorkingSetPolicy) -> Self
```

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/solver/irls.rs>)

Select the working-set policy. The last working-set setter wins. 

<a id="method-working_sets-d42788084a3c17dbcddc5c95a450b20fbb6721d3be7762845cd0d0b08358ce10"></a>

### `working_sets`

```rust
pub fn working_sets(self, enabled: bool) -> Self
```

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/solver/irls.rs>)

Enable automatic working sets, or disable heuristic restrictions. The last working-set setter wins. 

<a id="impl-e52c4f5d21bbb03d157db4d05a44d3cfdf1055cfef0831fe058f12f8a4efc17f"></a>

## Implementation of Clone

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/solver/irls.rs>)

```rust
impl Clone for Irls
```

<a id="method-clone-e52c4f5d21bbb03d157db4d05a44d3cfdf1055cfef0831fe058f12f8a4efc17f"></a>

### `clone`

```rust
fn clone(&self) -> Self
```

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/solver/irls.rs>)

<a id="impl-f35ff1c16f6027de29dbcdd2daf149587d77b998968eb7a76102a38236f4e97e"></a>

## Implementation of Copy

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/solver/irls.rs>)

```rust
impl Copy for Irls
```

<a id="impl-b249ae0d62e6d59b2a771475a01e80aa8c07adcc28437d0b5ba5dad9d96be813"></a>

## Implementation of Debug

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/solver/irls.rs>)

```rust
impl Debug for Irls
```

<a id="method-fmt-b249ae0d62e6d59b2a771475a01e80aa8c07adcc28437d0b5ba5dad9d96be813"></a>

### `fmt`

```rust
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
```

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/solver/irls.rs>)

<a id="impl-69ba57bc8c99154d206480052d9401545141ad027019e76f177d6ab7d6a94112"></a>

## Implementation of Default

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/solver/irls.rs>)

```rust
impl Default for Irls
```

<a id="method-default-69ba57bc8c99154d206480052d9401545141ad027019e76f177d6ab7d6a94112"></a>

### `default`

```rust
fn default() -> Self
```

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/solver/irls.rs>)

<a id="impl-703293d97c638886cc526342da272fbe40fbd02656b404b9c3d7fdbab6dc069c"></a>

## [Implementation of ObservedSolver](<a6f9ede80f6a0ee77f85e776916acea8bcaa0a49156d6cf183b3c41ae61db21a>)

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/solver/irls.rs>)

```rust
impl<M, D, P> ObservedSolver<Problem<&M, D, P>> for Irls where M: RawColumns<f64> + ColumnStats<f64> + ?Sized, D: QuadraticModelDatafit, P: CoordinatePenalty
```

<a id="impl-0bac03ca5e5b8100fde3e49b05634cf4b4080dc3e43ff1739b16b78af26daf0e"></a>

## [Implementation of PathSolver](<f5c72d3e4429c416ab6028c635ab099e02363494611b3296ed38741c10c0f4cf>)

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/path/irls.rs>)

```rust
impl<M, D, P, Q> PathSolver<Problem<&M, D, P>, Q> for shrinkage::Irls where M: RawColumns<f64> + ColumnStats<f64> + ?Sized, D: QuadraticModelDatafit, Q: CoordinatePenalty
```

<a id="impl-bcf810d7496113ff8a81e6054808d3369b760e0587e1e0e47b5f76fd1c12b83e"></a>

## [Implementation of RegularizationPathSolver](<f0683a430ead6c2ec6bb1d72ad941d17f0612d3092504128df751d377350193c>)

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/path/irls.rs>)

```rust
impl<M, D, P> RegularizationPathSolver<Problem<&M, D, P>> for shrinkage::Irls where M: RawColumns<f64> + ColumnStats<f64> + ?Sized, D: QuadraticModelDatafit + NullModelDatafit, P: PathPenalty, <P as PathPenalty>::AtStrength: CoordinatePenalty
```

<a id="impl-33e9f3be78bec4e6b7e159d18c90887e51bcd45508a8f82a43fe1f3df7c37231"></a>

## [Implementation of Solver](<f80ebf14b213d3129f84bb1ccc4912d7d7123fed16e872d24da1a9f5ef741b0a>)

[Source](<https://github.com/jolars/shrinkage/blob/eeafe449edce19d3c552a03060f681ae3891af74/src/solver/irls.rs>)

```rust
impl<M, D, P> Solver<Problem<&M, D, P>> for Irls where M: RawColumns<f64> + ColumnStats<f64> + ?Sized, D: QuadraticModelDatafit, P: CoordinatePenalty
```

<a id="impl-ef87f0130d11dc5d061c70c2413ef2620accd88c3d6677e907a55c9667c11a7d"></a>

## Implementation of Freeze

```rust
impl Freeze for Irls
```

<a id="impl-6fef15a0342577490f8796271b120b3350973c5df8034e10cf19ece1da0eea29"></a>

## Implementation of RefUnwindSafe

```rust
impl RefUnwindSafe for Irls
```

<a id="impl-fdd0aa99dd5397fa823480cc2ffd6a409d206eab1a2ff40d54e5d4f9a389df9f"></a>

## Implementation of Send

```rust
impl Send for Irls
```

<a id="impl-86547ef26fcd275ebf6cbd51bc69381a2a80ac66779e2c776cbe2a866d357c92"></a>

## Implementation of Sync

```rust
impl Sync for Irls
```

<a id="impl-899b5adb5876a0b4605103413221707460bf37f38b814c567de02329fef441eb"></a>

## Implementation of Unpin

```rust
impl Unpin for Irls
```

<a id="impl-a40aaeebdd3863af9498358c00ecdae1b140e88238564cd6dcf72859d48c20d0"></a>

## Implementation of UnsafeUnpin

```rust
impl UnsafeUnpin for Irls
```

<a id="impl-49ced30a1b6ac02b293a50f5803d711ebcecd2dc1b885ebe68dfacc6dab79f43"></a>

## Implementation of UnwindSafe

```rust
impl UnwindSafe for Irls
```

<a id="impl-1e5682dc18e03c648aa9b125290c107c1e8d96ce8a179a8532e4057da4daf0cd"></a>

## Implementation of Any

```rust
impl<T> Any for T where T: 'static + ?Sized
```

<a id="impl-6c0b25c2c92cdb117802d9c0a4c70afc9a8bfb0da875bc6e66191e2349fcdf3f"></a>

## Implementation of Borrow

```rust
impl<T> Borrow<T> for T where T: ?Sized
```

<a id="impl-796e80d926348273a22b04d8e84f510693b11c06ec57c3c3e2e8c1524094a85c"></a>

## Implementation of BorrowMut

```rust
impl<T> BorrowMut<T> for T where T: ?Sized
```

<a id="impl-8360e4092e7ec4a05a26dd304cd739398f0cacc50c8d08dd5be0223d1a08d02e"></a>

## Implementation of ByRef

```rust
impl<T> ByRef<T> for T
```

<a id="impl-dbb1293b7b5dd80c4d9a98cfdd6843dc7470224c0b1387731cd418da07046d7b"></a>

## Implementation of CastableFrom

```rust
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT where ST: ?Sized, DT: ?Sized
```

<a id="impl-97b65e7dfc44b5ecaa495a3a19fe737914a1e9f8532200cf8f46191314e7d777"></a>

## Implementation of CastableFrom

```rust
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT where ST: ?Sized, DT: ?Sized
```

<a id="impl-86d7da2bfd1140cc1675dfe6a975e6a2762338ab32731152da0723858ef3aa81"></a>

## Implementation of CloneToUninit

```rust
impl<T> CloneToUninit for T where T: Clone
```

<a id="impl-c22bdd3b1b677b66eb32d1c182cc1410c7f0c46491dd74e6a659647c238d19ec"></a>

## Implementation of From

```rust
impl<T> From<T> for T
```

<a id="impl-5adf6ca1830f30fbbac655ab8ff394d254954df7ededc7cc833c72fdc87d6f00"></a>

## Implementation of Imply

```rust
impl<T, U> Imply<T> for U where T: ?Sized, U: ?Sized
```

<a id="impl-85eec431edd188129f88290bbcb748e4d2fdc97f7efef3c162b8c252286ffec0"></a>

## Implementation of Into

```rust
impl<T, U> Into<U> for T where U: From<T>
```

<a id="impl-c40268dd59dd3329202d3c0544c62372e98ff3baa8ec442ec00752e024ec1d06"></a>

## Implementation of IntoEither

```rust
impl<T> IntoEither for T
```

<a id="impl-5655b1ef858b34a584cb80104f040c8a4063ced0d281311a0833ed12aefde86e"></a>

## Implementation of Pointable

```rust
impl<T> Pointable for T
```

<a id="impl-8cc2aa01198fc9fa44f08b889f62988d70d2a7f4f0f11f4666d4c08bdaddb22a"></a>

## Implementation of Read

```rust
impl<T> Read<Exclusive, BecauseExclusive> for T where T: ?Sized
```

<a id="impl-5ea09131039c62dd92b119d480a35c7e2b33d2b81dccf0b849f6b1f19f4bda24"></a>

## Implementation of Same

```rust
impl<T> Same for T
```

<a id="impl-7ee6ff38d6674f5edfe4734359062c2a67a572cff5899a89704764822b931c7f"></a>

## Implementation of SupersetOf

```rust
impl<SS, SP> SupersetOf<SS> for SP where SS: SubsetOf<SP>
```

<a id="impl-a8ef6e94191301c3685488478f4905086c47137bac2d606ea4d09631d5472b06"></a>

## Implementation of ToOwned

```rust
impl<T> ToOwned for T where T: Clone
```

<a id="impl-83960135d00d98080c95a08867729696e36811280c2dd9cf34c1b4fe21c81e18"></a>

## Implementation of TryFrom

```rust
impl<T, U> TryFrom<U> for T where U: Into<T>
```

<a id="impl-1cc495bcaa5112ffb304e7f0de674feca391fd97f47bec86033a9225b72ac05c"></a>

## Implementation of TryInto

```rust
impl<T, U> TryInto<U> for T where U: TryFrom<T>
```
