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:
where is the sample covariance (normalized by ), is the mean eigenvalue, and 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, defaultfalse).
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";