Shrinkage

Multivariate Gaussian

MultivariateGaussian fits qq real-valued responses with shared observations:

F(Y,H)=∥Y−H∥F22n=12n∑r=1q∑i=1n(Yir−Hir)2. F(Y,H) = \frac{\|Y - H\|_F^2}{2n} = \frac1{2n}\sum_{r=1}^q\sum_{i=1}^n(Y_{ir} - H_{ir})^2.

The loss sums over responses and averages over observations. It never divides by qq. Independent response fits therefore use the same penalty strengths as the corresponding single-response Gaussian problems.

Evaluate the loss

Store response columns contiguously. Entry (i,r)(i,r) has index r * nobs + i. The supplied dimensions must be positive and match the response length.

use shrinkage::MultivariateGaussian;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let y = [1.0, 3.0, 2.0, 4.0];
    let datafit = MultivariateGaussian::new(&y, 2, 2);
    let mut gradient = [0.0; 4];
    datafit.gradient(&[0.0; 4], &mut gradient)?;
    assert_eq!(gradient, [-0.5, -1.5, -1.0, -2.0]);
    Ok(())
}

Every response has a free, unpenalized intercept by default. .fit_intercept(false) disables all free intercepts. Predictors and predictions use the same response-major layout as the observations.

Fitting uses proximal gradient and an AxisPenalty with an explicit feature-by-response CoefficientLayout. See multivariate regression for a complete example and feature selection across responses.

API: shrinkage::MultivariateGaussian.