Skip to main content

LedoitWolf

#include <Skigen/Covariance>

template <typename Scalar = double>
class Skigen::LedoitWolf(assume_centered=false)

Ledoit-Wolf shrinkage covariance estimator.

Estimates the covariance matrix using the Ledoit-Wolf shrinkage method, which analytically computes the optimal shrinkage coefficient that minimizes the Frobenius norm of the estimation error.

The estimator computes:

Σ^=(1α)S+αμI\hat{\Sigma} = (1 - \alpha)\,S + \alpha\,\mu\,I

where SS is the sample covariance (normalized by nn), μ=tr(S)/p\mu = \mathrm{tr}(S)/p is the mean eigenvalue, and α[0,1]\alpha \in [0,1] is the optimal shrinkage coefficient.

Reference: Ledoit & Wolf (2004), "A well-conditioned estimator for large-dimensional covariance matrices", Journal of Multivariate Analysis, 88(2), 365-411.

Mirrors sklearn.covariance.LedoitWolf.


Parameters:

  • assume_centered : bool, default=false If true, data is assumed to be centered and mean is not subtracted (bool, default false).

Attributes:

  • covariance : MatrixType Estimated covariance matrix (p × p).

  • shrinkage : Scalar Optimal shrinkage coefficient α ∈ [0, 1].

  • location : RowVectorType Estimated location (mean) of the data (1 × p).


Methods

fit(X)

Fit the Ledoit-Wolf covariance model.

Parameters:

  • X : MatrixType Data matrix of shape (n_samples, n_features).

Returns:

  • result : LedoitWolf Reference to the fitted estimator (*this).

score(X)

Return the Gaussian log-likelihood of X under the fitted model.

Parameters:

  • X : MatrixType Data matrix of shape (n_samples, n_features).

Returns:

  • result : Scalar Average log-likelihood per sample.

Example

Skigen::LedoitWolf<double> lw;
lw.fit(X);

std::cout << "=== LedoitWolf ===\n"
<< "Shrinkage coefficient: " << lw.shrinkage() << "\n"
<< "Covariance (4x4):\n" << lw.covariance() << "\n\n";