Skip to content

Commit cd3a0cb

Browse files
yah
1 parent c99b997 commit cd3a0cb

File tree

1 file changed

+0
-30
lines changed

1 file changed

+0
-30
lines changed

precise/covariance/statefunctions.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,6 @@
66
import numpy as np
77

88

9-
def ledoit_wolf()
10-
11-
12-
def naive_ledoit_wolf_shrinkage(n_samples, pcov, p2cov):
13-
"""
14-
:param n_samples:
15-
:param pcov: Covariance of X
16-
:param p2cov: Covariance of
17-
:return:
18-
"""
19-
# From https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/covariance/tests/test_covariance.py
20-
# A simple implementation of the formulas from Ledoit & Wolf
21-
# The computation below achieves the following computations of the
22-
# "O. Ledoit and M. Wolf, A Well-Conditioned Estimator for
23-
# Large-Dimensional Covariance Matrices"
24-
# beta and delta are given in the beginning of section 3.2
25-
n_features = np.shape(pcov)[0]
26-
mu = np.trace(pcov) / n_features
27-
delta_ = pcov.copy()
28-
delta_.flat[:: n_features + 1] -= mu
29-
delta = (delta_ ** 2).sum() / n_features
30-
beta_ = 1.0 / (n_features * n_samples) * np.sum(p2cov - pcov ** 2)
31-
32-
beta = min(beta_, delta)
33-
shrinkage = beta / delta
34-
return shrinkage
35-
36-
37-
38-
399
def oas(n_samples:int, pcov=None, scov=None, **ignore):
4010
""" Compute shrunk covariance matrix from empirical
4111
:param pcov: Covariance matrix

0 commit comments

Comments
 (0)