Created
March 9, 2021 07:58
-
-
Save thesfinox/5d39b0c2f931b5b7571e297baeb9e88e to your computer and use it in GitHub Desktop.
Marchenko-Pastur Distribution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Marchenko-Pastur distribution | |
# see https://en.wikipedia.org/wiki/Marchenko%E2%80%93Pastur_distribution | |
def marchenko_pastur(x, c, var=1.0): | |
''' | |
Marchenko-Pastur PDF. | |
Arguments: | |
x: independent variable, | |
c: phase transition parameter, | |
var: variance of the data matrix. | |
''' | |
N = 2.0 * np.pi * c * x * var # denominator | |
a = var * np.square(1 - np.sqrt(c)) # inf of the support | |
b = var * np.square(1 + np.sqrt(c)) # sup of the support | |
# piecewise definition | |
if a <= x <= b: | |
return np.sqrt((b - x) * (x - a)) / N | |
else: | |
return 0.0 | |
# convenience redefinition to use array-like objects as independent variable | |
# see https://numpy.org/doc/stable/reference/generated/numpy.vectorize.html | |
marchenko_pastur = np.vectorize(marchenko_pastur) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment