# shrinkage::AxisPenalty

Shrinkage for Rust · 0.3.0

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

```rust
pub struct AxisPenalty<P>
```

A complete vector penalty applied along an explicit coefficient axis. 

`Features` separates responses; `Responses` can couple their coefficients at each feature. `All` can couple the full matrix. Each group uses the supplied strength without dividing by the group or response count. The prox is exact because the groups are disjoint. Intercepts are never included. Strided response groups use owned reusable CPU scratch buffers. 

Compose [`crate::Scaled`](<002e330ba78b1cd4f3d636338d545dc3876d2d58d4a1fda37a736ec8d9bb63e9>) and [`crate::Masked`](<2dec36b360b55f50673aea5f43199a63294c9255ade7907fb4ade3d975bb106c>) inside the axis penalty. With `Responses`, each feature row receives the same vector penalty and a mask has one entry per response. With `Features`, a mask has one entry per feature and excludes those feature rows across all responses. Masks require an inner [`crate::RestrictedProximalPenalty`](<6e81c84ae32917d40a6711abfffe4b252008f5265d347b3a8b6129238b41dffe>). 

```rust
use shrinkage::{
    AxisPenalty, CoefficientLayout, Masked, Penalty, PenaltyAxis,
    ProximalPenalty, Ridge, Scaled,
};

let layout = CoefficientLayout::new(3, 2)?;
let penalty = AxisPenalty::new(
    layout,
    PenaltyAxis::Responses,
    Scaled::new(0.5, Masked::new(vec![true, false], Ridge::new(2.0))),
);
// Each response's feature vector is contiguous, so the rows are [1, 4],
// [2, 5], and [3, 6]. Only the second response is penalized in each row.
let input = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];
assert!((penalty.value(&input)? - 38.5).abs() < 1e-12);
let mut output = [0.0; 6];
penalty.prox(&input, 1.0, &mut output)?;
assert_eq!(output, [1.0, 2.0, 3.0, 2.0, 2.5, 3.0]);
```

<a id="impl-039b9e6b247d5ae92063472e24fc890773f2fae3bb6f6527e101179171253d2a"></a>

## Inherent implementation

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

```rust
impl<P> AxisPenalty<P>
```

<a id="method-axis-039b9e6b247d5ae92063472e24fc890773f2fae3bb6f6527e101179171253d2a"></a>

### `axis`

```rust
pub fn axis(&self) -> PenaltyAxis
```

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

Axis along which the complete vector penalty applies. 

<a id="method-layout-039b9e6b247d5ae92063472e24fc890773f2fae3bb6f6527e101179171253d2a"></a>

### `layout`

```rust
pub fn layout(&self) -> CoefficientLayout
```

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

Feature and response dimensions on which this penalty is defined. 

<a id="method-new-039b9e6b247d5ae92063472e24fc890773f2fae3bb6f6527e101179171253d2a"></a>

### `new`

```rust
pub fn new(layout: CoefficientLayout, axis: PenaltyAxis, penalty: P) -> Self
```

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

Apply a vector penalty to the selected axis of the given layout. 

<a id="method-penalty-039b9e6b247d5ae92063472e24fc890773f2fae3bb6f6527e101179171253d2a"></a>

### `penalty`

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

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

Borrow the complete vector penalty applied to each group. 

<a id="impl-1a98c18c4fbc1f031079821e01d04992589310e64ab8a77d824059ad98bf2293"></a>

## Implementation of Clone

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

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

<a id="method-clone-1a98c18c4fbc1f031079821e01d04992589310e64ab8a77d824059ad98bf2293"></a>

### `clone`

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

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

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

## Implementation of Debug

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

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

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

### `fmt`

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

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

<a id="impl-3ef4a7414d2252c1b07ad74f609f4dcb38549ef7e60ac4297290435412ec6c12"></a>

## [Implementation of PathPenalty](<5696a47a26612eb54b73987df7c9af737a60d396dd77d3c0b67969a3a5f37105>)

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

```rust
impl<P: PathPenalty> PathPenalty for shrinkage::AxisPenalty<P>
```

<a id="associated-type-AtStrength-3ef4a7414d2252c1b07ad74f609f4dcb38549ef7e60ac4297290435412ec6c12"></a>

### `AtStrength`

```rust
type AtStrength = AxisPenalty<<P as PathPenalty>::AtStrength>;
```

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

<a id="method-at_strength-3ef4a7414d2252c1b07ad74f609f4dcb38549ef7e60ac4297290435412ec6c12"></a>

### `at_strength`

```rust
fn at_strength(
    &self,
    lambda: f64
) -> Result<<Self as PathPenalty>::AtStrength, FitError>
```

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

<a id="method-maximum_penalty-3ef4a7414d2252c1b07ad74f609f4dcb38549ef7e60ac4297290435412ec6c12"></a>

### `maximum_penalty`

```rust
fn maximum_penalty(&self, gradient: &[f64]) -> Result<PenaltyMaximum, FitError>
```

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

<a id="method-path_anchor-3ef4a7414d2252c1b07ad74f609f4dcb38549ef7e60ac4297290435412ec6c12"></a>

### `path_anchor`

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

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

<a id="impl-2c922a1b51f8422cde6974ec1686ccc2a939cb9ba607b129f0f6e9b60eeff887"></a>

## [Implementation of PathSolver](<f5c72d3e4429c416ab6028c635ab099e02363494611b3296ed38741c10c0f4cf>)

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

```rust
impl<M, P, Q, V> PathSolver<Problem<&M, MultivariateGaussian<'_>, AxisPenalty<P>>, AxisPenalty<Q>> for shrinkage::ProximalGradient<V> where M: RawColumns<f64> + ColumnStats<f64> + MatVecInto<V> + MatTransposeVecInto<V> + ?Sized, Q: ProximalPenalty, V: ProximalVector
```

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

### `Error`

```rust
type Error = FitError<<M as MatrixErrorType>::Error>;
```

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

<a id="associated-type-Fit-2c922a1b51f8422cde6974ec1686ccc2a939cb9ba607b129f0f6e9b60eeff887"></a>

### `Fit`

```rust
type Fit = MultivariateFit;
```

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

<a id="method-solve_path-2c922a1b51f8422cde6974ec1686ccc2a939cb9ba607b129f0f6e9b60eeff887"></a>

### `solve_path`

```rust
fn solve_path(
    &self,
    problem: &Problem<&M, MultivariateGaussian<'_>, AxisPenalty<P>>,
    penalties: Vec<AxisPenalty<Q>>
) -> Result<PathFit<MultivariateFit, AxisPenalty<Q>>, <Self as PathSolver>::Error>
```

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

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

## [Implementation of PathSolver](<f5c72d3e4429c416ab6028c635ab099e02363494611b3296ed38741c10c0f4cf>)

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

```rust
impl<P, Q: ProximalPenalty> PathSolver<Problem<Box<dyn RuntimeDesign + '_>, MultivariateGaussian<'_>, AxisPenalty<P>>, AxisPenalty<Q>> for shrinkage::ProximalGradient<Vec<f64>>
```

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

### `Error`

```rust
type Error = FitError<BackendError>;
```

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

<a id="associated-type-Fit-a88a53fec270ad545d10fad8f9dbca4187b6983bb37f8941c2ccbea9f2fd1fc7"></a>

### `Fit`

```rust
type Fit = MultivariateFit;
```

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

<a id="method-solve_path-a88a53fec270ad545d10fad8f9dbca4187b6983bb37f8941c2ccbea9f2fd1fc7"></a>

### `solve_path`

```rust
fn solve_path(
    &self,
    problem: &Problem<Box<dyn RuntimeDesign + '_>, MultivariateGaussian<'_>, AxisPenalty<P>>,
    penalties: Vec<AxisPenalty<Q>>
) -> Result<PathFit<MultivariateFit, AxisPenalty<Q>>, <Self as PathSolver>::Error>
```

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

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

### `Error`

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

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

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

### `validate_input`

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

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

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

### `value`

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

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

<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="method-prox-636eea55951d2673f1c578d31593cfb7a1a173bc742bab83a6fad7fd348827c3"></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/axis.rs>)

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

## Implementation of Freeze

```rust
impl<P> !Freeze for AxisPenalty<P>
```

<a id="impl-2f4c8976890f99f944bf8fc3f243201d8293d5199cc204e602fa405513e4b344"></a>

## Implementation of RefUnwindSafe

```rust
impl<P> !RefUnwindSafe for AxisPenalty<P>
```

<a id="impl-787b256b585b45e886b39c4a2ed82e30a15a4f8f6a4c7dda98726d216ec622e1"></a>

## Implementation of Send

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

<a id="impl-82afcb11da0858daddcef6f366d903fbde7153286466f164fb20e96f6b644d5c"></a>

## Implementation of Sync

```rust
impl<P> !Sync for AxisPenalty<P>
```

<a id="impl-9f0871e4459e2307630dbbe3c6342c9a7a72fbdff30ba9b4aa6d859078800aec"></a>

## Implementation of Unpin

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

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

## Implementation of UnsafeUnpin

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

<a id="impl-89da2f46621a5cfd2f05cdb6943c18f81c00b4808b6b30f82c60b230ef070529"></a>

## Implementation of UnwindSafe

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