File tree Expand file tree Collapse file tree 1 file changed +0
-30
lines changed
Expand file tree Collapse file tree 1 file changed +0
-30
lines changed Original file line number Diff line number Diff line change 66import 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-
399def oas (n_samples :int , pcov = None , scov = None , ** ignore ):
4010 """ Compute shrunk covariance matrix from empirical
4111 :param pcov: Covariance matrix
You can’t perform that action at this time.
0 commit comments