I have some code in matlab, that I would like to rewrite into python. It's simple program, that computes some distribution and plot it in double-log scale.
The problem I occured is with computing cdf. Here is matlab code:
for D = 1:10
delta = D / 10;
for k = 1:n
N_delta = poissrnd(delta^-alpha,1);
Y_k_delta = ( (1 - randn(N_delta)) / (delta.^alpha) ).^(-1/alpha);
Y_k_delta = Y_k_delta(Y_k_delta > delta);
X(k) = sum(Y_k_delta);
%disp(X(k))
end
[f,x] = ecdf(X);
plot(log(x), log(1-f))
hold on
end
In matlab one I can simply use:
[f,x] = ecdf(X);
to get cdf (f) at points x. Here is documentation for it.
In python it is more complicated:
import numpy as np
from scipy.stats import norm
import matplotlib.pyplot as plt
from statsmodels.distributions.empirical_distribution import ECDF
alpha = 1.5
n = 1000
X = []
for delta in range(1,5):
delta = delta/10.0
for k in range(1,n + 1):
N_delta = np.random.poisson(delta**(-alpha), 1)
Y_k_delta = ( (1 - np.random.random(N_delta)) / (delta**alpha) )**(-1/alpha)
Y_k_delta = [i for i in Y_k_delta if i > delta]
X.append(np.sum(Y_k_delta))
ecdf = ECDF(X)
x = np.linspace(min(X), max(X))
f = ecdf(x)
plt.plot(np.log(f), np.log(1-f))
plt.show()
It makes my plot look very strange, definetly not smooth as matlab's one.
I think the problem is that I do not understand ECDF
function or it works differently than in matlab.
I implemented this solution (the most points one) for my python code, but it looks like it doesn't work correctly.