# shrinkage::RestrictedProximalPenalty

Shrinkage for Rust · 0.3.0

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

```rust
pub trait RestrictedProximalPenalty: ProximalPenalty
```

A convex penalty with an exact proximal map after excluding coordinates. 

Each `true` entry in `unpenalized` excludes the corresponding coefficient. The restricted value equals the complete penalty evaluated with those coordinates set to zero. Its proximal map minimizes `||z - input||² / (2 * step) + self.value_restricted(z, unpenalized)` and copies excluded inputs unchanged. Masks have one entry per coefficient. 

A complete proximal map alone does not imply this capability. In particular, restoring excluded inputs after a coupled proximal map is generally wrong. External penalties must implement the restricted problem explicitly. 

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

## Methods

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

### `prox_restricted`

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

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

Write the exact restricted proximal minimizer into reusable storage. 

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

#### Errors

Reject invalid parameters, nonpositive or nonfinite steps, mismatched input, output, or mask lengths, nonfinite input (including excluded coordinates), or nonfinite arithmetic. Output is unspecified on error. 

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

### `validate_restricted_input`

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

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

Validate coefficients and a restriction without evaluating its value. 

The default checks mask length and calls [`Penalty::validate_input`](<a4f4243001e8d9121fca7a92bcb924b17aa5375aba23987fae95b2a05faf5245#method-validate_input>) on the complete coefficients. Override it if restriction changes input compatibility or if complete validation performs unused value arithmetic. This check must still reject invalid parameters and nonfinite excluded coefficients, including when an outer [`super::Scaled`](<002e330ba78b1cd4f3d636338d545dc3876d2d58d4a1fda37a736ec8d9bb63e9>) has zero scale. 

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

#### Errors

Reject invalid parameters, coefficients, or mask lengths. 

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

### `value_restricted`

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

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

Evaluate the penalty with excluded coordinates set to zero. 

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

#### Errors

Reject invalid parameters, mismatched mask lengths, nonfinite coefficients (including excluded ones), or nonfinite arithmetic. 

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

## [Implementation of RestrictedProximalPenalty](<6e81c84ae32917d40a6711abfffe4b252008f5265d347b3a8b6129238b41dffe>)

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

```rust
impl RestrictedProximalPenalty for shrinkage::ElasticNet
```

<a id="impl-71f4983d124be898f9ca86e0b5b6db36392a031b3e58bc7df9d4d692b09296dc"></a>

## [Implementation of RestrictedProximalPenalty](<6e81c84ae32917d40a6711abfffe4b252008f5265d347b3a8b6129238b41dffe>)

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

```rust
impl RestrictedProximalPenalty for shrinkage::L1
```

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

## [Implementation of RestrictedProximalPenalty](<6e81c84ae32917d40a6711abfffe4b252008f5265d347b3a8b6129238b41dffe>)

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

```rust
impl RestrictedProximalPenalty for shrinkage::Ridge
```

<a id="impl-9605f1a203df063232aec565bf5d552eb12b05986b23184a84f4256717e6d909"></a>

## [Implementation of RestrictedProximalPenalty](<6e81c84ae32917d40a6711abfffe4b252008f5265d347b3a8b6129238b41dffe>)

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

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