# Ridge

Ridge shrinks coefficients continuously and usually leaves them nonzero. Its constraint region is a disk. This is a squared L2 penalty, which differs from the unsquared norm used by Group LASSO. 

$$

  R(\beta) = \frac{\lambda}{2}\|\beta\|_2^2.

$$

<a id="constraint-region"></a>

## Constraint region

![Feasible region for ridge; the shaded set includes its boundary.](<../assets/403372f30a92ea956e74a1820b8acfb160ba2811e068e8c3152de2261dbd10b5.svg>) 

$\lambda = 2$: $\beta_1^2 + \beta_2^2 \leq 1$. See the [plot conventions](<./#read-the-constraint-plots>) for the fixed budget and coefficient scale. 

<a id="use-the-penalty"></a>

## Use the penalty

```rust
use shrinkage::{Penalty, ProximalPenalty, Ridge};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let penalty = Ridge::new(0.5);
    let coefficients = [2.0, -1.0];
    println!("Penalty: {}", penalty.value(&coefficients)?);
    let mut shrunk = [0.0; 2];
    penalty.prox(&coefficients, 1.0, &mut shrunk)?;
    println!("Proximal result: {shrunk:?}");
    Ok(())
}
```

Use [proximal gradient](<../reference/solvers/proximal-gradient>) or [IRLS](<../reference/solvers/irls>) with Gaussian or binomial datafits. Its proximal map divides each input by $1 + s\lambda$. With zero strength, it returns the input unchanged. 

API: [`shrinkage::Ridge`](<https://shrinkage.cc/packages/rust/reference/cbb3b47b3b63b801639d1697f8ab9090627986cae975bb7f06d11764acdeee8c>).
