# shrinkage::Slope

Shrinkage for Rust · 0.3.0

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

```rust
pub struct Slope
```

SLOPE penalty `sum_j weights[j] * |beta|_(j)` on optimization coefficients. 

`|beta|_(j)` denotes the jth largest coefficient magnitude. Supply one finite, nonnegative, nonincreasing weight per coefficient, including the penalty strength. Equal weights give L1; all zero weights give no penalty. An empty weight vector defines the penalty on an empty coefficient vector. Intercepts are excluded by the fitting APIs. 

The exact proximal map sorts magnitudes, projects the thresholded values onto nonincreasing, nonnegative sequences by pooling adjacent violations, and restores the original signs and order. Sorting costs `O(p log p)` and pooling costs `O(p)`. Owned CPU scratch storage is reused across calls. Typed Gaussian problems also support [`crate::HybridCoordinateDescent`](<6e142c2de8c70807e35ff7553fffda094241be993dc7a332ee193688dc1f04bf>), combining full PG transitions with exact signed magnitude-cluster sweeps. 

```rust
use shrinkage::{Penalty, ProximalPenalty, Slope};

let penalty = Slope::new(vec![3.0, 1.0]);
assert_eq!(penalty.value(&[-3.0, 3.0])?, 12.0);
let mut output = [0.0; 2];
penalty.prox(&[-3.0, 3.0], 1.0, &mut output)?;
assert_eq!(output, [-1.0, 1.0]);
```

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

## Inherent implementation

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

```rust
impl Slope
```

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

### `new`

```rust
pub fn new(weights: Vec<f64>) -> Self
```

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

Set complete rank weights, checked during evaluation and fitting. 

<a id="method-weights-bab7ff90425261df8e717e8f00445783926bb7f93c25350581ac1d82b491ec15"></a>

### `weights`

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

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

Configured rank weights, including the penalty strength. 

<a id="impl-3a4a0e3115fd534b809f4a958fc8326f59cb3e8768bf0b0397598c51c2a0f672"></a>

## Implementation of Clone

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

```rust
impl Clone for Slope
```

<a id="method-clone-3a4a0e3115fd534b809f4a958fc8326f59cb3e8768bf0b0397598c51c2a0f672"></a>

### `clone`

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

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

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

## Implementation of Debug

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

```rust
impl Debug for Slope
```

<a id="method-fmt-7eb565e9ccf8d4cdf7c0bfef42f4a86ffec10356fbfe8a17fddf14a12c161c3f"></a>

### `fmt`

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

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

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

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

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

```rust
impl GapSafePenalty for shrinkage::Slope
```

<a id="method-dual_feasible-c0e9e90d7de5c93536e790e4dee5a0ed4e7121cc5b1fe066dc139a4c91f3b9c6"></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-dual_scaling-c0e9e90d7de5c93536e790e4dee5a0ed4e7121cc5b1fe066dc139a4c91f3b9c6"></a>

### `dual_scaling`

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

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

<a id="method-has_sparsity-c0e9e90d7de5c93536e790e4dee5a0ed4e7121cc5b1fe066dc139a4c91f3b9c6"></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-c0e9e90d7de5c93536e790e4dee5a0ed4e7121cc5b1fe066dc139a4c91f3b9c6"></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-c0e9e90d7de5c93536e790e4dee5a0ed4e7121cc5b1fe066dc139a4c91f3b9c6"></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-7a5e2350d9b954b49afbd190a8aef8cf94e525b0169776efacfff032bd482314"></a>

## Implementation of Partition

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

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

<a id="method-labels-7a5e2350d9b954b49afbd190a8aef8cf94e525b0169776efacfff032bd482314"></a>

### `labels`

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

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

<a id="method-new-7a5e2350d9b954b49afbd190a8aef8cf94e525b0169776efacfff032bd482314"></a>

### `new`

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

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

<a id="method-rebuild-7a5e2350d9b954b49afbd190a8aef8cf94e525b0169776efacfff032bd482314"></a>

### `rebuild`

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

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

<a id="method-set_screened-7a5e2350d9b954b49afbd190a8aef8cf94e525b0169776efacfff032bd482314"></a>

### `set_screened`

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

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

<a id="method-set_weights-7a5e2350d9b954b49afbd190a8aef8cf94e525b0169776efacfff032bd482314"></a>

### `set_weights`

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

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

<a id="method-sweep_observed-7a5e2350d9b954b49afbd190a8aef8cf94e525b0169776efacfff032bd482314"></a>

### `sweep_observed`

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

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

<a id="method-sweep_visits-7a5e2350d9b954b49afbd190a8aef8cf94e525b0169776efacfff032bd482314"></a>

### `sweep_visits`

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

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

<a id="method-values-7a5e2350d9b954b49afbd190a8aef8cf94e525b0169776efacfff032bd482314"></a>

### `values`

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

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

<a id="impl-6645ed1e1cc35ef166af1fddabfc4cd0125c4f23462354f7ac69246ad02ca890"></a>

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

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

```rust
impl PathPenalty for shrinkage::Slope
```

<a id="associated-type-AtStrength-6645ed1e1cc35ef166af1fddabfc4cd0125c4f23462354f7ac69246ad02ca890"></a>

### `AtStrength`

```rust
type AtStrength = Slope;
```

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

<a id="method-at_strength-6645ed1e1cc35ef166af1fddabfc4cd0125c4f23462354f7ac69246ad02ca890"></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-6645ed1e1cc35ef166af1fddabfc4cd0125c4f23462354f7ac69246ad02ca890"></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-82c704c5bf3bf1e6aae6953cb6a9010913fecca51afb08cdc537e13efaf8eef9"></a>

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

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

```rust
impl Penalty for Slope
```

<a id="associated-type-Error-82c704c5bf3bf1e6aae6953cb6a9010913fecca51afb08cdc537e13efaf8eef9"></a>

### `Error`

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

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

<a id="method-validate_input-82c704c5bf3bf1e6aae6953cb6a9010913fecca51afb08cdc537e13efaf8eef9"></a>

### `validate_input`

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

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

<a id="method-value-82c704c5bf3bf1e6aae6953cb6a9010913fecca51afb08cdc537e13efaf8eef9"></a>

### `value`

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

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

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

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

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

```rust
impl ProximalPenalty for Slope
```

<a id="method-gap_safe-c6535032741a7b08ed477034a116082cd85712d15ed8c4f23b25c35e09c3d6b4"></a>

### `gap_safe`

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

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

<a id="method-prox-c6535032741a7b08ed477034a116082cd85712d15ed8c4f23b25c35e09c3d6b4"></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/slope.rs>)

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

## Implementation of ReducedCoordinatePenalty

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

```rust
impl ReducedCoordinatePenalty for shrinkage::Slope
```

<a id="associated-type-State-b463d14dd30296dbef37ef639bd3ef69ff44a76da4d5e672280922bc24e2c282"></a>

### `State`

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

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

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

## Implementation of Freeze

```rust
impl !Freeze for Slope
```

<a id="impl-3fb8564ee3e4be9c4923549e3ce60b5edaba0fdc0b8d1e5def648211813e5908"></a>

## Implementation of RefUnwindSafe

```rust
impl !RefUnwindSafe for Slope
```

<a id="impl-74075d7be349d06b4297968d5f25c7d5aaed1b15a0d32e4319f5f4bcb36d123b"></a>

## Implementation of Send

```rust
impl Send for Slope
```

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

## Implementation of Sync

```rust
impl !Sync for Slope
```

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

## Implementation of Unpin

```rust
impl Unpin for Slope
```

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

## Implementation of UnsafeUnpin

```rust
impl UnsafeUnpin for Slope
```

<a id="impl-54216285430103529c465e2f5fc551e572ef6d59f9e2506395f3fa3ba57f30aa"></a>

## Implementation of UnwindSafe

```rust
impl UnwindSafe for Slope
```

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