# shrinkage::Masked

Shrinkage for Rust · 0.3.0

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

```rust
pub struct Masked<P>
```

A complete penalty with explicit unpenalized coordinates. 

`true` excludes a coordinate, and `false` retains its penalty. The mask must have one entry per optimization-scale coefficient, excluding any intercept. Parameters and mask length are checked during evaluation and fitting. Excluded coordinates contribute no penalty and are copied unchanged by the proximal map. The wrapper owns its mask and allocates no evaluation workspace. 

```rust
use shrinkage::{L1, Masked, Penalty, ProximalPenalty};

let penalty = Masked::new(vec![true, false], L1::new(2.0));
assert_eq!(penalty.value(&[10.0, -3.0])?, 6.0);
let mut output = [0.0; 2];
penalty.prox(&[10.0, -3.0], 0.5, &mut output)?;
assert_eq!(output, [10.0, -2.0]);
```

A coupled penalty without an implemented restriction cannot be masked, even if it supplies a complete proximal map: 

```rust
use shrinkage::{Masked, Slope};
let penalty = Masked::new(vec![true, false], Slope::new(vec![2.0, 1.0]));
```

Runtime selection must preserve the restricted capability before masking: 

```rust
use shrinkage::{L1, Masked, ProximalPenalty};
let penalty: Box<dyn ProximalPenalty> = Box::new(L1::new(1.0));
let masked = Masked::new(vec![true, false], penalty);
```

<a id="impl-77c259da3804c9572f67fe43233eb12d9e832b256787487f5df5fdcfc151e7c3"></a>

## Inherent implementation

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

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

<a id="method-new-77c259da3804c9572f67fe43233eb12d9e832b256787487f5df5fdcfc151e7c3"></a>

### `new`

```rust
pub fn new(unpenalized: Vec<bool>, penalty: P) -> Self
```

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

Set the unpenalized mask and inner penalty, checked when used. 

<a id="method-penalty-77c259da3804c9572f67fe43233eb12d9e832b256787487f5df5fdcfc151e7c3"></a>

### `penalty`

```rust
pub fn penalty(&self) -> &P
```

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

Borrow the complete inner penalty, including its strengths. 

<a id="method-unpenalized-77c259da3804c9572f67fe43233eb12d9e832b256787487f5df5fdcfc151e7c3"></a>

### `unpenalized`

```rust
pub fn unpenalized(&self) -> &[bool]
```

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

One flag per coefficient; `true` marks an unpenalized coordinate. 

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

## Implementation of Clone

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

```rust
impl<P: core::clone::Clone> Clone for Masked<P>
```

<a id="method-clone-d11bb78bbce671de9ac678239331d671456b15117670b0c17029024b9df953a0"></a>

### `clone`

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

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

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

## Implementation of Debug

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

```rust
impl<P: core::fmt::Debug> Debug for Masked<P>
```

<a id="method-fmt-b65cc445502f388b06d17c324b8b214ec75ed6540b39cb9cd5142692ccb0a60d"></a>

### `fmt`

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

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

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

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

### `Error`

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

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

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

### `validate_input`

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

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

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

### `value`

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

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

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

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

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

## Implementation of Freeze

```rust
impl<P> Freeze for Masked<P> where P: Freeze
```

<a id="impl-09a718fa1722670a27a1410c8ffa0428b7b8e76ca3962ecb7faef86244ecdebd"></a>

## Implementation of RefUnwindSafe

```rust
impl<P> RefUnwindSafe for Masked<P> where P: RefUnwindSafe
```

<a id="impl-8b400db83fcdeb74b207880371d2806b89315c607e93e67e5f30cd27209787b6"></a>

## Implementation of Send

```rust
impl<P> Send for Masked<P> where P: Send
```

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

## Implementation of Sync

```rust
impl<P> Sync for Masked<P> where P: Sync
```

<a id="impl-60bd1da95481e77ab221fadb4b64f22671535773e70e77f5f25fb30660d16ed6"></a>

## Implementation of Unpin

```rust
impl<P> Unpin for Masked<P> where P: Unpin
```

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

## Implementation of UnsafeUnpin

```rust
impl<P> UnsafeUnpin for Masked<P> where P: UnsafeUnpin
```

<a id="impl-56bc505b5ccb4f63aaa519989f1e4bff0fa3e4adddb9a6d56661d0300674cf95"></a>

## Implementation of UnwindSafe

```rust
impl<P> UnwindSafe for Masked<P> where P: UnwindSafe
```

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