# shrinkage::Scaled

Shrinkage for Rust · 0.3.0

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

```rust
pub struct Scaled<P>
```

A complete penalty multiplied by a finite, nonnegative scalar. 

`Scaled::new(scale, penalty)` evaluates `scale * penalty.value(coefficients)`. Parameters are checked during evaluation and fitting. For a positive scale, the exact proximal map delegates to the inner map with `step * scale`. Zero scaling returns zero value and the identity proximal map, while still checking the wrapped penalty through [`Penalty::validate_input`](<a4f4243001e8d9121fca7a92bcb924b17aa5375aba23987fae95b2a05faf5245#method-validate_input>). The wrapper adds no allocations or coefficient storage. 

```rust
use shrinkage::{ElasticNet, Penalty, ProximalPenalty, Scaled};

let penalty = Scaled::new(0.5, ElasticNet::new(2.0, 4.0));
assert_eq!(penalty.value(&[-2.0])?, 6.0);
let mut output = [0.0];
penalty.prox(&[-4.0], 0.5, &mut output)?;
assert_eq!(output, [-1.75]);
```

Scaling a value-only term does not supply a complete proximal map: 

```rust
use shrinkage::{FitError, Penalty, ProximalPenalty, Scaled};
struct ValueOnly;
impl Penalty for ValueOnly {
    type Error = FitError;
    fn value(&self, _: &[f64]) -> Result<f64, FitError> { Ok(1.0) }
}
let penalty = Scaled::new(0.5, ValueOnly);
penalty.prox(&[1.0], 1.0, &mut [0.0]);
```

<a id="impl-1075f7e81e93737f8ef2a6f83455186a365b199e0a67273e86478577c63d4bee"></a>

## Inherent implementation

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

```rust
impl<P> Scaled<P>
```

<a id="method-new-1075f7e81e93737f8ef2a6f83455186a365b199e0a67273e86478577c63d4bee"></a>

### `new`

```rust
pub fn new(scale: f64, penalty: P) -> Self
```

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

Set the scalar and complete inner penalty, checked when used. 

<a id="method-penalty-1075f7e81e93737f8ef2a6f83455186a365b199e0a67273e86478577c63d4bee"></a>

### `penalty`

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

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

Borrow the complete inner penalty, including its own strengths. 

<a id="method-scale-1075f7e81e93737f8ef2a6f83455186a365b199e0a67273e86478577c63d4bee"></a>

### `scale`

```rust
pub fn scale(&self) -> f64
```

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

Configured multiplier of the complete penalty. 

<a id="impl-75957003359d5b8caa1337c63adbe5874ff8231b98254a0ce889078e6a05e3de"></a>

## Implementation of Clone

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

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

<a id="method-clone-75957003359d5b8caa1337c63adbe5874ff8231b98254a0ce889078e6a05e3de"></a>

### `clone`

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

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

<a id="impl-44f90578ac9bd7a53c0b89f4aed0774455f02dd4f2e186af8120993907165825"></a>

## Implementation of Copy

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

```rust
impl<P: core::marker::Copy> Copy for Scaled<P>
```

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

## Implementation of Debug

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

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

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

### `fmt`

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

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

<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="associated-type-Error-ce9cd3f44b09ec0a62d31806403a63883d3d11eda067896fa0651e1877991e69"></a>

### `Error`

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

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

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

### `validate_input`

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

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

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

### `value`

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

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

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

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

<a id="method-prox_restricted-9605f1a203df063232aec565bf5d552eb12b05986b23184a84f4256717e6d909"></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/scaled.rs>)

<a id="method-validate_restricted_input-9605f1a203df063232aec565bf5d552eb12b05986b23184a84f4256717e6d909"></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/scaled.rs>)

<a id="method-value_restricted-9605f1a203df063232aec565bf5d552eb12b05986b23184a84f4256717e6d909"></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/scaled.rs>)

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

## Implementation of Freeze

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

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

## Implementation of RefUnwindSafe

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

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

## Implementation of Send

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

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

## Implementation of Sync

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

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

## Implementation of Unpin

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

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

## Implementation of UnsafeUnpin

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

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

## Implementation of UnwindSafe

```rust
impl<P> UnwindSafe for Scaled<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>
```
