# shrinkage::Penalty

Shrinkage for Rust · 0.3.0

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

```rust
pub trait Penalty
```

The complete penalty `R(beta)` on optimization-scale coefficients. 

A value alone does not imply a proximal map or a valid coordinate update. 

<a id="associated-types"></a>

## Associated types

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

### `Error`

```rust
type Error;
```

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

Failure returned by penalty evaluation. 

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

## Methods

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

### `validate_input`

```rust
fn validate_input(
    &self,
    coefficients: &[f64]
) -> Result<(), <Self as Penalty>::Error>
```

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

Check parameters and coefficient compatibility independently of scaling. 

The default evaluates the penalty and discards its value. Implementations can override this to validate without value arithmetic, allowing a zero [`Scaled`](<002e330ba78b1cd4f3d636338d545dc3876d2d58d4a1fda37a736ec8d9bb63e9>) penalty to avoid overflow in a value that is never used. 

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

#### Errors

Reject invalid coefficients or parameters. The default also propagates errors from value evaluation. 

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

### `value`

```rust
fn value(&self, coefficients: &[f64]) -> Result<f64, <Self as Penalty>::Error>
```

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

Evaluate the penalty, including its strength. 

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

#### Errors

Returns an error for invalid coefficients, parameters, or arithmetic. 

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

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

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

```rust
impl Penalty for ElasticNet
```

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

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

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

```rust
impl Penalty for L1
```

<a id="impl-166e1e62bfe337e0bee7f65167d54b1ad33d1b22e85b10a7d5f92584ca3c9dc8"></a>

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

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

```rust
impl Penalty for Ridge
```

<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="impl-25ae2a5bceaa1e82727e7dbee51f6a4fcd67dfe3e3c7facdbc6db8141b1db3c8"></a>

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

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

```rust
impl Penalty for ClusteredLasso
```

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

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

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

```rust
impl Penalty for GroupLasso
```

<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="impl-3c53319ace32cc23819fc394fc9abd1ad98b73dfde42b3f4650f3a5d92b92873"></a>

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

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

```rust
impl<P: Penalty<Error = shrinkage::FitError>> Penalty for AxisPenalty<P>
```

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

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

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

```rust
impl<P: Penalty<Error = shrinkage::FitError>> Penalty for Scaled<P>
```

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

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

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

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

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

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

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

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