# shrinkage::GroupLasso

Shrinkage for Rust · 0.3.0

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

```rust
pub struct GroupLasso
```

Group LASSO `lambda * sum_g weights[g] * ||beta[g]||₂`. 

Groups address optimization-scale coefficients and exclude intercepts. The supplied [`DisjointGroups`](<66837f98e8b085ca419007cb1086d289a594d7573fda3cdd4d56b38563de68bc>) fixes the coefficient count, explicit weights, and coverage policy. There is no implicit group-size scaling. Zero-weight groups and uncovered coefficients are unpenalized. Singleton groups give weighted L1, and zero lambda gives the zero penalty. 

The exact proximal map shrinks each block by `max(1 - step * lambda * weight / ||input[g]||₂, 0)` and copies free coordinates. Value evaluation and the prox take linear time and allocate no scratch storage. Gaussian fits use [`crate::ProximalGradient`](<dbf207e0ed64fdc5c0f5cc6c364e567527bca92737c69f45f608ed62e8d669d5>)'s reusable product and iteration workspaces through both typed and runtime problems. 

```rust
use shrinkage::{DisjointGroups, GroupLasso, Penalty, ProximalPenalty, UncoveredPolicy};

let groups = DisjointGroups::new(
    3, vec![vec![0, 2]], vec![2.0], UncoveredPolicy::Unpenalized,
)?;
let penalty = GroupLasso::new(0.5, groups);
assert_eq!(penalty.value(&[3.0, 9.0, 4.0])?, 5.0);
let mut output = [0.0; 3];
penalty.prox(&[3.0, 9.0, 4.0], 2.0, &mut output)?;
assert!((output[0] - 1.8).abs() < 1e-14);
assert_eq!(output[1], 9.0);
```

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

## Inherent implementation

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

```rust
impl GroupLasso
```

<a id="method-groups-4c38887de44ed02d22db44e969fc64da7eadc46e387a2250a6fb7c5d235929cb"></a>

### `groups`

```rust
pub fn groups(&self) -> &DisjointGroups
```

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

Immutable group definitions, weights, and coverage policy. 

<a id="method-lambda-4c38887de44ed02d22db44e969fc64da7eadc46e387a2250a6fb7c5d235929cb"></a>

### `lambda`

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

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

Configured multiplier of all explicit group weights. 

<a id="method-new-4c38887de44ed02d22db44e969fc64da7eadc46e387a2250a6fb7c5d235929cb"></a>

### `new`

```rust
pub fn new(lambda: f64, groups: DisjointGroups) -> Self
```

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

Set the overall strength and validated groups. Strength is checked on use. 

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

## Implementation of Clone

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

```rust
impl Clone for GroupLasso
```

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

### `clone`

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

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

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

## Implementation of Debug

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

```rust
impl Debug for GroupLasso
```

<a id="method-fmt-9e4fe2bd36454625760d46e6afb471735fbdbc14c8bbbfd53a3b179d5e2e13b6"></a>

### `fmt`

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

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

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

### `Error`

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

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

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

### `validate_input`

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

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

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

### `value`

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

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

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

## [Implementation of ProximalPenalty](<45434a0394c5d718086e7e777f7db8271e2fb2b568e2519720168e5ea2877ed0>)

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

```rust
impl ProximalPenalty for GroupLasso
```

<a id="method-prox-a858b06b14f13c579c47219c6e3ff28c3630377e06e82a7707f8ebf27f935103"></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/group_lasso.rs>)

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

## Implementation of Freeze

```rust
impl Freeze for GroupLasso
```

<a id="impl-069da0ff45cb5c8b07fb669b19bf19e652f8d7f896e2a4ac519cb258f997cbe6"></a>

## Implementation of RefUnwindSafe

```rust
impl RefUnwindSafe for GroupLasso
```

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

## Implementation of Send

```rust
impl Send for GroupLasso
```

<a id="impl-4901f909a5a5e1d6367da0f253b7596491be547ce8f86c9fed6f99619d865806"></a>

## Implementation of Sync

```rust
impl Sync for GroupLasso
```

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

## Implementation of Unpin

```rust
impl Unpin for GroupLasso
```

<a id="impl-7cc2a7310eca9b0d62095c687537dd773511c5d0697b03cdbfced194b13cb810"></a>

## Implementation of UnsafeUnpin

```rust
impl UnsafeUnpin for GroupLasso
```

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

## Implementation of UnwindSafe

```rust
impl UnwindSafe for GroupLasso
```

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