# shrinkage::ChainFusedLasso

Shrinkage for Rust · 0.3.0

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

```rust
pub struct ChainFusedLasso
```

Complete penalty `l1 * sum_j |beta[j]| + fusion * sum_j w[j] * |beta[j+1]-beta[j]|`. 

Edges follow feature order and contribute once. Both strengths and every weight must be finite and nonnegative, checked on use. Unit weights are implicit unless [`Self::with_weights`](<b88554a6c3f1121915d157c3e7684558bb6e9e9f59dbacd8115eb616c3631ce1#method-with_weights-0900757c49e6461916a04fda6567b51646862e9290d792dd9aa34fa600758009>) supplies exactly one weight per edge. Zero weights cut the chain. Empty and single-feature chains have no edges. Intercepts are excluded, and coefficients refer to the optimization scale. 

The exact complete prox uses weighted taut strings followed by uniform L1 soft-thresholding. Value and prox take `O(p)` time; the prox reuses `O(p)` CPU storage. [`crate::ProximalGradient`](<dbf207e0ed64fdc5c0f5cc6c364e567527bca92737c69f45f608ed62e8d669d5>) supports typed and runtime problems, and [`crate::HybridCoordinateDescent`](<6e142c2de8c70807e35ff7553fffda094241be993dc7a332ee193688dc1f04bf>) adds exact Gaussian segment-coordinate sweeps. 

```rust
use shrinkage::{ChainFusedLasso, Penalty, ProximalPenalty};
let penalty = ChainFusedLasso::new(0.1, 0.2).with_weights(vec![2.0, 0.0]);
assert!((penalty.value(&[-2.0, 2.0, 1.0])? - 2.1).abs() < 1e-14);
let mut output = [0.0; 3];
penalty.prox(&[-2.0, 2.0, 1.0], 1.0, &mut output)?;
assert_eq!(output, [-1.5, 1.5, 0.9]);
```

<a id="impl-0900757c49e6461916a04fda6567b51646862e9290d792dd9aa34fa600758009"></a>

## Inherent implementation

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

```rust
impl ChainFusedLasso
```

<a id="method-fusion-0900757c49e6461916a04fda6567b51646862e9290d792dd9aa34fa600758009"></a>

### `fusion`

```rust
pub fn fusion(&self) -> f64
```

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

Configured multiplier of the edge weights. 

<a id="method-l1-0900757c49e6461916a04fda6567b51646862e9290d792dd9aa34fa600758009"></a>

### `l1`

```rust
pub fn l1(&self) -> f64
```

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

Configured L1 strength. 

<a id="method-new-0900757c49e6461916a04fda6567b51646862e9290d792dd9aa34fa600758009"></a>

### `new`

```rust
pub fn new(l1: f64, fusion: f64) -> Self
```

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

Set independent L1 and fusion strengths, with implicit unit weights. 

<a id="method-weights-0900757c49e6461916a04fda6567b51646862e9290d792dd9aa34fa600758009"></a>

### `weights`

```rust
pub fn weights(&self) -> Option<&[f64]>
```

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

Explicit edge weights, or `None` for implicit unit weights. 

<a id="method-with_weights-0900757c49e6461916a04fda6567b51646862e9290d792dd9aa34fa600758009"></a>

### `with_weights`

```rust
pub fn with_weights(self, weights: Vec<f64>) -> Self
```

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

Supply one finite, nonnegative weight per adjacent edge, checked on use. 

<a id="impl-138bfbdd3f2665ccd1531bbc8a6789cab65e1e04fe86caad9679218632f6b6ad"></a>

## Implementation of Clone

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

```rust
impl Clone for ChainFusedLasso
```

<a id="method-clone-138bfbdd3f2665ccd1531bbc8a6789cab65e1e04fe86caad9679218632f6b6ad"></a>

### `clone`

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

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

<a id="impl-79d470aa10733040193141e66eb55097a93afddf4be81aacfa3b05d1fa50bffd"></a>

## Implementation of Debug

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

```rust
impl Debug for ChainFusedLasso
```

<a id="method-fmt-79d470aa10733040193141e66eb55097a93afddf4be81aacfa3b05d1fa50bffd"></a>

### `fmt`

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

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

<a id="impl-4aba12756cba46501c1f131992292ac408f15b936047206d8f4fb8ef96d27ee6"></a>

## [Implementation of GapSafePenalty](<70ffed513f4897153138a3d474faab53b31c338c10fd2b0945fd39cc01a58a42>)

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

```rust
impl GapSafePenalty for shrinkage::ChainFusedLasso
```

<a id="method-dual_feasible-4aba12756cba46501c1f131992292ac408f15b936047206d8f4fb8ef96d27ee6"></a>

### `dual_feasible`

```rust
fn dual_feasible(
    &self,
    correlations: &[f64],
    errors: &[f64]
) -> Result<bool, FitError>
```

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

<a id="method-has_sparsity-4aba12756cba46501c1f131992292ac408f15b936047206d8f4fb8ef96d27ee6"></a>

### `has_sparsity`

```rust
fn has_sparsity(&self) -> bool
```

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

<a id="method-prox_zeroed-4aba12756cba46501c1f131992292ac408f15b936047206d8f4fb8ef96d27ee6"></a>

### `prox_zeroed`

```rust
fn prox_zeroed(
    &self,
    input: &[f64],
    zeroed: &[bool],
    step: f64,
    output: &mut [f64]
) -> Result<(), FitError>
```

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

<a id="method-screen_zeros-4aba12756cba46501c1f131992292ac408f15b936047206d8f4fb8ef96d27ee6"></a>

### `screen_zeros`

```rust
fn screen_zeros(
    &self,
    correlations: &[f64],
    errors: &[f64],
    zeroed: &mut [bool]
) -> Result<(), FitError>
```

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

<a id="impl-9a860e85845eb83f89802089346e1d83433da3039baf2a2b06f16dd2ed9ecbf6"></a>

## Implementation of Partition

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

```rust
impl Partition<ChainFusedLasso> for State
```

<a id="method-labels-9a860e85845eb83f89802089346e1d83433da3039baf2a2b06f16dd2ed9ecbf6"></a>

### `labels`

```rust
fn labels(&self) -> &[usize]
```

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

<a id="method-new-9a860e85845eb83f89802089346e1d83433da3039baf2a2b06f16dd2ed9ecbf6"></a>

### `new`

```rust
fn new(n: usize, p: usize) -> Self
```

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

<a id="method-rebuild-9a860e85845eb83f89802089346e1d83433da3039baf2a2b06f16dd2ed9ecbf6"></a>

### `rebuild`

```rust
fn rebuild<M: RawColumns<f64> + lazymatrix::MatrixErrorType>(
    &mut self,
    matrix: &LazyMatrix<M>,
    coefficients: &[f64],
    residual: &[f64],
    penalty: &ChainFusedLasso,
    iteration: usize
) -> Result<(), FitError<<M as >::Error>>
```

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

<a id="method-set_screened-9a860e85845eb83f89802089346e1d83433da3039baf2a2b06f16dd2ed9ecbf6"></a>

### `set_screened`

```rust
fn set_screened(&mut self, zeroed: &[bool])
```

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

<a id="method-set_weights-9a860e85845eb83f89802089346e1d83433da3039baf2a2b06f16dd2ed9ecbf6"></a>

### `set_weights`

```rust
fn set_weights(&mut self, weights: &[f64])
```

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

<a id="method-sweep_observed-9a860e85845eb83f89802089346e1d83433da3039baf2a2b06f16dd2ed9ecbf6"></a>

### `sweep_observed`

```rust
fn sweep_observed<E, T: SolverObserver + ?Sized>(
    &mut self,
    coefficients: &mut [f64],
    intercept: &mut f64,
    fit_intercept: bool,
    penalty: &ChainFusedLasso,
    iteration: usize,
    observer: &mut T
) -> Result<(), FitError<E>>
```

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

<a id="method-sweep_visits-9a860e85845eb83f89802089346e1d83433da3039baf2a2b06f16dd2ed9ecbf6"></a>

### `sweep_visits`

```rust
fn sweep_visits(&self) -> (usize, usize)
```

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

<a id="method-values-9a860e85845eb83f89802089346e1d83433da3039baf2a2b06f16dd2ed9ecbf6"></a>

### `values`

```rust
fn values(&self) -> Vec<f64>
```

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

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

## [Implementation of PathPenalty](<5696a47a26612eb54b73987df7c9af737a60d396dd77d3c0b67969a3a5f37105>)

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

```rust
impl PathPenalty for shrinkage::ChainFusedLasso
```

<a id="associated-type-AtStrength-d44440774b57b2a12464ccb4162a7de6c6d84b6b35e0d4e4142c28d31d0398e5"></a>

### `AtStrength`

```rust
type AtStrength = ChainFusedLasso;
```

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

<a id="method-at_strength-d44440774b57b2a12464ccb4162a7de6c6d84b6b35e0d4e4142c28d31d0398e5"></a>

### `at_strength`

```rust
fn at_strength(&self, lambda: f64) -> Result<Self, FitError>
```

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

<a id="method-maximum_penalty-d44440774b57b2a12464ccb4162a7de6c6d84b6b35e0d4e4142c28d31d0398e5"></a>

### `maximum_penalty`

```rust
fn maximum_penalty(&self, gradient: &[f64]) -> Result<PenaltyMaximum, FitError>
```

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

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

## [Implementation of Penalty](<a4f4243001e8d9121fca7a92bcb924b17aa5375aba23987fae95b2a05faf5245>)

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

```rust
impl Penalty for ChainFusedLasso
```

<a id="associated-type-Error-f45a898208ae833db5baebc93caa3ff714a20b29072749fb8cef9ec0bd871940"></a>

### `Error`

```rust
type Error = FitError;
```

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

<a id="method-validate_input-f45a898208ae833db5baebc93caa3ff714a20b29072749fb8cef9ec0bd871940"></a>

### `validate_input`

```rust
fn validate_input(&self, coefficients: &[f64]) -> Result<(), FitError>
```

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

<a id="method-value-f45a898208ae833db5baebc93caa3ff714a20b29072749fb8cef9ec0bd871940"></a>

### `value`

```rust
fn value(&self, coefficients: &[f64]) -> Result<f64, FitError>
```

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

<a id="impl-5302a3477a753c5e36cf00d57b3d8c74ee2071d9d15c9aad50f342068c65ce01"></a>

## [Implementation of ProximalPenalty](<45434a0394c5d718086e7e777f7db8271e2fb2b568e2519720168e5ea2877ed0>)

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

```rust
impl ProximalPenalty for ChainFusedLasso
```

<a id="method-gap_safe-5302a3477a753c5e36cf00d57b3d8c74ee2071d9d15c9aad50f342068c65ce01"></a>

### `gap_safe`

```rust
fn gap_safe(&self) -> Option<&dyn shrinkage::GapSafePenalty>
```

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

<a id="method-prox-5302a3477a753c5e36cf00d57b3d8c74ee2071d9d15c9aad50f342068c65ce01"></a>

### `prox`

```rust
fn prox(
    &self,
    input: &[f64],
    step: f64,
    output: &mut [f64]
) -> Result<(), FitError>
```

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

<a id="impl-537d9f5af31b81862e1892cd748a12f5fc854480aba544268007a75571d41962"></a>

## Implementation of ReducedCoordinatePenalty

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

```rust
impl ReducedCoordinatePenalty for shrinkage::ChainFusedLasso
```

<a id="associated-type-State-537d9f5af31b81862e1892cd748a12f5fc854480aba544268007a75571d41962"></a>

### `State`

```rust
type State = State;
```

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

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

## Implementation of Freeze

```rust
impl !Freeze for ChainFusedLasso
```

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

## Implementation of RefUnwindSafe

```rust
impl !RefUnwindSafe for ChainFusedLasso
```

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

## Implementation of Send

```rust
impl Send for ChainFusedLasso
```

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

## Implementation of Sync

```rust
impl !Sync for ChainFusedLasso
```

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

## Implementation of Unpin

```rust
impl Unpin for ChainFusedLasso
```

<a id="impl-024be0a6bdd386a9f56fc54b8e5b25a508082e8f627dc703eef7c07953af45c7"></a>

## Implementation of UnsafeUnpin

```rust
impl UnsafeUnpin for ChainFusedLasso
```

<a id="impl-542c3b88ddda940e4c24291eeb763488721ba983f2f4bfd5d84f14e1983291cd"></a>

## Implementation of UnwindSafe

```rust
impl UnwindSafe for ChainFusedLasso
```

<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>
```
