Révision 13c68160
b/papers/2014/reservation/experiments/src/python/lib/kadeploy.py | ||
---|---|---|
7 | 7 |
import numpy as np |
8 | 8 |
from matplotlib import rc |
9 | 9 |
from pylab import * |
10 |
from scipy.stats import gaussian_kde, lognorm, rayleigh, norm |
|
10 |
from scipy.stats import gaussian_kde, lognorm, rayleigh, norm, kstest, ks_2samp
|
|
11 | 11 |
import scipy.stats as stats |
12 | 12 |
rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']}) |
13 | 13 |
rc('text', usetex=True) |
14 | 14 |
plt.rcParams.update({'font.size': 14}) |
15 | 15 |
from datetime import datetime |
16 |
from statsmodels.stats.gof import powerdiscrepancy |
|
16 | 17 |
|
17 | 18 |
TZINFO = pytz.timezone("Europe/Paris") |
18 | 19 |
|
... | ... | |
157 | 158 |
ar1 = np.array(values) |
158 | 159 |
fig, ax = plt.subplots() |
159 | 160 |
|
160 |
num_bins = 50
|
|
161 |
num_bins = 60
|
|
161 | 162 |
n, bins, patches = plt.hist(ar1, bins=num_bins, histtype='bar', |
162 | 163 |
normed=True, facecolor='#708090', alpha=0.5, rwidth=0.8) |
163 | 164 |
plt.subplots_adjust(left=0.15) |
164 | 165 |
|
165 | 166 |
max = round(bins[len(bins) - 1]) |
166 |
density = gaussian_kde(ar1) |
|
167 |
xs = np.linspace(0, max, 300) |
|
168 |
density.covariance_factor = lambda : .25 |
|
169 |
density._compute_covariance() |
|
167 |
# xs = np.linspace(0, max, len(values)) |
|
168 |
xs = np.linspace(0, max, len(values)) |
|
169 |
|
|
170 |
# density = gaussian_kde(ar1) |
|
171 |
# density.covariance_factor = lambda : .25 |
|
172 |
# density._compute_covariance() |
|
170 | 173 |
# plt.plot(xs, density(xs), 'r--') |
171 | 174 |
|
172 | 175 |
ax.set_xlabel(x_label) |
... | ... | |
190 | 193 |
|
191 | 194 |
# dist_names = ['lognorm', 'beta', 'betaprime', 'gamma', 'rayleigh'] |
192 | 195 |
dist_names = ['lognorm', 'beta', 'betaprime', 'gamma', 'rayleigh'] |
196 |
#dist_names = ['lognorm', 'beta', 'betaprime', 'gamma'] |
|
197 |
# dist_names = ['beta', 'betaprime', 'gamma'] |
|
198 |
ks_tests = {} |
|
193 | 199 |
|
194 | 200 |
for dist_name in dist_names: |
195 | 201 |
dist = getattr(stats, dist_name) |
196 | 202 |
param = dist.fit(ar1) |
197 | 203 |
pdf_fitted = dist.pdf(xs, *param[:-2], loc=param[-2], scale=param[-1]) |
204 |
|
|
205 |
kst = kstest(ar1, dist_name, param) |
|
206 |
ks_tests[dist_name] = kst |
|
207 |
|
|
198 | 208 |
plt.plot(xs, pdf_fitted, label=dist_name) |
199 | 209 |
plt.xlim(0, max) |
200 |
plt.legend(loc='upper right') |
|
201 | 210 |
|
202 |
# param = lognorm.fit(ar1) |
|
203 |
# pdf_fitted = lognorm.pdf(xs, param[0], loc=param[1], scale=param[2]) |
|
204 |
# plt.plot(xs, pdf_fitted, 'b') |
|
205 |
|
|
206 |
# param = norm.fit(ar1) |
|
207 |
# pdf_fitted = norm.pdf(xs, loc=param[0], scale=param[1]) |
|
208 |
# plt.plot(xs, pdf_fitted, 'b') |
|
211 |
plt.legend(loc='upper right') |
|
209 | 212 |
|
210 | 213 |
#print param |
214 |
for key, value in ks_tests.iteritems(): |
|
215 |
print key, value |
|
211 | 216 |
|
212 |
# plt.show()
|
|
213 |
plt.savefig(out_file) |
|
217 |
plt.show() |
|
218 |
# plt.savefig(out_file)
|
|
214 | 219 |
|
215 | 220 |
|
216 | 221 |
def plot_graphs(): |
Formats disponibles : Unified diff