# shrinkage::ProximalPenalty

Shrinkage for Rust · 0.3.0

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

```rust
pub trait ProximalPenalty: Penalty<Error = shrinkage::FitError>
```

A convex penalty with an exact proximal map for the complete term. 

Implementations minimize `||z - input||² / (2 * step) + self.value(z)`. This contract applies to the entire penalty, including its strengths. A sum of penalties does not acquire this capability from its summands. A value-only penalty cannot be fitted by proximal gradient: 

```rust
use shrinkage::{FitError, Gaussian, Penalty, Problem, ProximalGradient};
use shrinkage::lazymatrix::{ColumnStats, MatVecInto, MatTransposeVecInto, RawColumns};
fn fit<M, P>(problem: &Problem<&M, Gaussian<'_>, P>)
where
    M: RawColumns<f64> + ColumnStats<f64>
        + MatVecInto<Vec<f64>> + MatTransposeVecInto<Vec<f64>>,
    P: Penalty<Error = FitError>,
{
    let _ = problem.fit_with(&ProximalGradient::<Vec<f64>>::new());
}
```

<a id="methods"></a>

## Methods

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

### `gap_safe`

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

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

Optional dual feasibility, safe zero screening, and exact zero restriction. 

Implementations without this capability retain ordinary proximal fitting. 

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

Write the proximal minimizer into reusable output storage. 

<a id="method-prox-documentation-errors"></a>

#### Errors

Reject invalid parameters, nonpositive or nonfinite steps, mismatched lengths, nonfinite input, or nonfinite arithmetic. Output is unspecified after an error. 

<a id="impl-45cdfd2a1bad32f0464e23503eca0925292c491b0dd809c9255cefd7056bc08a"></a>

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

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

```rust
impl ProximalPenalty for ElasticNet
```

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

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

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

```rust
impl ProximalPenalty for L1
```

<a id="impl-67a6bb4e3fe83764bc356b6ba58d6a9471a8be54f912a12dcc08b729228a5f33"></a>

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

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

```rust
impl ProximalPenalty for Ridge
```

<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="impl-06c6c8aae556dba70d68f950f48296a204524a358eee83b590023da00d3673bb"></a>

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

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

```rust
impl ProximalPenalty for ClusteredLasso
```

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

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

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

```rust
impl ProximalPenalty for GroupLasso
```

<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="impl-8229edc5d6baea4d2c5d03c6231654dd3f77fc0abd6ac5c0876d76ba4e976aec"></a>

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

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

```rust
impl<P: ProximalPenalty> ProximalPenalty for ErasedPathPenalty<P>
```

<a id="impl-636eea55951d2673f1c578d31593cfb7a1a173bc742bab83a6fad7fd348827c3"></a>

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

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

```rust
impl<P: ProximalPenalty> ProximalPenalty for AxisPenalty<P>
```

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

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

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

```rust
impl<P: ProximalPenalty> ProximalPenalty for Scaled<P>
```

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

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

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

```rust
impl<P: RestrictedProximalPenalty> ProximalPenalty for Masked<P>
```
