def main(data_name, r=1): with open(data_name + '.pkl', 'rb') as f: data = pickle.load(f) insts = data.keys() seeds = list(filter(lambda x: '#' not in x, insts)) for i in seeds: inst = TSP(data[i]) dists = np.array(inst.dist_mat).flatten() # normalise to r == 1 dists = dists / dists.max() * 2.0 * r _, shp, _, scl = exponweib.fit(dists, f0=1) print(i, np.abs(-0.509 * shp + 0.707)) # plt.clf() # plt.title(i) # _ = plt.hist(dists, density=True) # x = np.linspace(dists.min(), dists.max(), 1000) # plt.plot(x, weibull(x, shp, scl)) # plt.show() for i in range(5): inst = TSP(int(data_name.split('_')[-1])) dists = np.array(inst.dist_mat).flatten() dists = dists / dists.max() * 2.0 * r _, shp, _, scl = exponweib.fit(dists, f0=1) print('rand' + str(i), np.abs(-0.509 * shp + 0.707))
def calculate_parameters(start, end, step, e): steps = int( np.floor(((end - start).days * 24 * 60 * 60 + (end - start).seconds) / (step * 60 * 60))) print((end - start).days) parameters = [] for i in range(steps): it = e.get_orders( 'BTCUSDT', start.timestamp() * 1000 + i * step * 1000 * 60 * 60, start.timestamp() * 1000 + (i + 1) * step * 1000 * 60 * 60) times = [] for order in it: times.append(order.time) sample = np.diff(times) print(i) #parameters.append([1 / m, np.exp(-c - m)]) a, c, loc, scale = exponweib.fit(sample, loc=0, scale=1) parameters.append([a, c]) return parameters
def fit_tests(features, ind=True, q=0.90, verbose=False): """ Input: features: a dictionary like with the numerical results from the QC tests. For example, the gradient test values, not the flags, but the floats itself, like {'gradient': ma.array([.23, .12, .08]), 'spike': ...} ind: The features values positions to be considered in the fit. It's usefull to eliminate out of range data, or to restrict to a subset of the data, like in the calibration procedure. q: The lowest percentile to be considered. For example, .90 means that only the top 10% data (i.e. percentiles higher than .90) are considered in the fitting. """ output = {} for test in features: samp = features[test][ind & np.isfinite(features[test])] ind_top = samp > samp.quantile(q) if ind_top.any(): param = exponweib.fit(samp[ind_top]) output[test] = {'param': param, 'qlimit': samp.quantile(q)} if verbose is True: import pylab x = np.linspace(samp[ind_top].min(), samp[ind_top].max(), 100) pdf_fitted = exponweib.pdf(x, *param[:-2], loc=param[-2], scale=param[-1]) pylab.plot(x, pdf_fitted, 'b-') pylab.hist(ma.array(samp[ind_top]), 100, normed=1, alpha=.3) pylab.title(test) pylab.show() return output
def returnDistData(cls, self): gammaParam = gamma.fit(10**(self.data / 10)) gammaDist = gamma.pdf(self.data, *gammaParam) rayleighParam = rayleigh.fit(self.data) rayleighDist = rayleigh.pdf(self.data, *rayleighParam) normParam = norm.fit(self.data) normDist = norm.pdf(self.data, *normParam) logNormParam = lognorm.fit(self.data) lognormDist = lognorm.pdf(self.data, *logNormParam) nakagamiParam = nakagami.fit(self.data) nakagamiDist = nakagami.pdf(self.data, *nakagamiParam) exponParam = expon.fit(self.data) exponDist = expon.pdf(self.data, *exponParam) exponweibParam = exponweib.fit(self.data) weibDist = exponweib.pdf(self.data, *exponweibParam) distDF = pd.DataFrame(np.column_stack([ gammaDist, rayleighDist, normDist, lognormDist, nakagamiDist, exponDist, weibDist ]), columns=[ 'gammaDist', 'rayleighDist', 'normDist', 'lognormDist', 'nakagamiDist', 'exponDist', 'weibDist' ]) self.distDF = distDF
def weibull_scale(data): """ Compute the weibull scalen parameter for a set of ratios. """ ldata = data[data > .5] # only look at right-hand side of distribution if len(ldata) > 0: # exponweib.fit returns a, c, loc, scale return exponweib.fit(ldata, floc=0)[3] else: return 0
def fit(self, data): """ data is an np array :param data: :return: """ data = np.array(data) nPoints = len(data) avg = np.mean(data) std = np.std(data) spikes = data > ([avg + self.spike_std_factor * std] * nPoints) self.last = data[-1] self.params = None if any(spikes): self.spike_max = max(data[spikes]) self.spike_avg = np.mean(data[spikes]) last_nonzero_idx = np.max(np.nonzero(data)) self.time_since_last_spike = len(data) - 1 - np.max( np.nonzero(spikes)) interarrivaltime = 0 spikewidth = 0 inter_arrival_times = [] in_spike = False has_spiked = False spikewidths = [] for isspike in spikes: if not isspike: if in_spike: # was in spike, now not spike spikewidths.append(spikewidth) spikewidth = 0 interarrivaltime = interarrivaltime + 1 in_spike = False else: if not in_spike and has_spiked: inter_arrival_times.append(interarrivaltime) interarrivaltime = 0 spikewidth = spikewidth + 1 in_spike = True has_spiked = True if len(inter_arrival_times) > 0: if self.fit_model == "Weibull": self.params = exponweib.fit(inter_arrival_times, floc=0, f0=1) # a, c, loc, scale elif self.fit_model == "Expon": self.params = expon.fit(inter_arrival_times, floc=0) # returns loc, scale else: # self.fit_model == "Sampling": self.params = inter_arrival_times self.spike_width_avg = int( np.mean(spikewidths)) if len(spikewidths) > 0 else 1 return self
def test_fit_weibull(y): """The PDF really doesn't look like the data. Might the parameters be wrong? """ a, b, loc, scale = exponweib.fit(y) x = linspace(0, y.max()) pdf_fitted = exponweib.pdf(x, a, b, loc, scale) title("Weibull distribution: (a=%.2f,b=%.2f) loc = %.2f, scale = %.2f" % (a, b, loc, scale)) plot(x, pdf_fitted, 'r-') hist(y, normed=1, alpha=.3, bins=int(y.max())) show() return a, b, loc, scale
def fit_weib2(): # 生成韦伯分布数据 sample = exponweib.rvs(a=10, c=1, scale=3, loc=0, size=1000) x = np.linspace(0, np.max(sample), 100) #拟合 a, c, loc, scale = exponweib.fit(sample, floc=0, fa=1) print(a, c, loc, scale) y = exponweib.pdf(x, a, c, loc, scale) for x1, y1 in zip(x, y): print(x1, y1) plt.plot(x, y) plt.show()
def fit_distribution(data, fit_type, x_min, x_max, n_points=1000): # Initialization of the variables param, x, cdf, pdf = [-1, -1, -1, -1] if fit_type == 'exponweib': x = np.linspace(x_min, x_max, n_points) # Fit data to the theoretical distribution param = exponweib.fit(data, 1, 1, scale=02, loc=0) # param = exponweib.fit(data, fa=1, floc=0) # param = exponweib.fit(data) cdf = exponweib.cdf(x, param[0], param[1], param[2], param[3]) pdf = exponweib.pdf(x, param[0], param[1], param[2], param[3]) elif fit_type == 'lognorm': x = np.linspace(x_min, x_max, n_points) # Fit data to the theoretical distribution param = lognorm.fit(data, loc=0) cdf = lognorm.cdf(x, param[0], param[1], param[2]) pdf = lognorm.pdf(x, param[0], param[1], param[2]) elif fit_type == 'norm': x = np.linspace(x_min, x_max, n_points) # Fit data to the theoretical distribution param = norm.fit(data, loc=0) cdf = norm.cdf(x, param[0], param[1]) pdf = norm.pdf(x, param[0], param[1]) elif fit_type == 'weibull_min': x = np.linspace(x_min, x_max, n_points) # Fit data to the theoretical distribution param = weibull_min.fit(data, floc=0) cdf = weibull_min.cdf(x, param[0], param[1], param[2]) pdf = weibull_min.pdf(x, param[0], param[1], param[2]) return param, x, cdf, pdf
def fit_tests(features, q=0.90, verbose=False): """ Input: features: a dictionary like with the numerical results from the QC tests. For example, the gradient test values, not the flags, but the floats itself, like {'gradient': ma.array([.23, .12, .08]), 'spike': ...} It also works with a pandas.DataFrame() q: The lowest percentile to be considered. For example, .90 means that only the top 10% data (i.e. percentiles higher than .90) are considered in the fitting. """ assert (q >= 0) & (q < 1), "q must be in [0, 1)" output = {} for f in features: # Sample only valid values samp = ma.compressed(features[f][np.isfinite(features[f])]) # Identify the percentile q qlimit = np.percentile(samp, 1e2 * q) # Restricts to the top q values samp = samp[samp > qlimit] if samp.any(): param = exponweib.fit(samp) output[f] = {'param': param, 'qlimit': qlimit} if verbose is True: import pylab x = np.linspace(samp.min(), samp.max(), 100) pdf_fitted = exponweib.pdf(x, *param[:-2], loc=param[-2], scale=param[-1]) pylab.plot(x, pdf_fitted, 'b-') pylab.hist(ma.array(samp), 100, normed=1, alpha=.3) pylab.title(f) pylab.show() return output
#history_data = [10,30,150,90,120,320,40,410,170,170,60,60,150,90,150,330,100,60,70,60,100,90,210,130,140,40,40,110,60,40,20,20] #history_data = [i for i in history_data if i >=300] history_data = history_data[history_data > 100] #history_data = history_data[history_data>200] params = gamma.fit(history_data) params = rv_continuous(gamma, history_data) statistic, pvalue = kstest(history_data, gamma.cdf, params) print('gamma: %f %f' % (statistic, pvalue)) print(params) params = norm.fit(history_data) statistic, pvalue = kstest(history_data, "norm", params) print('norm: %f %f' % (statistic, pvalue)) params = exponweib.fit(history_data) statistic, pvalue = kstest(history_data, "exponweib", params) print('weibull: %f %f' % (statistic, pvalue)) params = expon.fit(history_data) statistic, pvalue = kstest(history_data, "expon", params) print('expon: %f %f' % (statistic, pvalue)) params = lognorm.fit(history_data) statistic, pvalue = kstest(history_data, "lognorm", params) print('lognormal: %f %f' % (statistic, pvalue)) print(params) f = Fitter(history_data, distributions=['gamma', 'norm', 'exponweib', 'expon', 'lognorm']) f.fit()
# plt.matshow(lower); # plt.colorbar(); # plt.show(); # plt.matshow(median); # plt.colorbar(); # plt.show(); exit(); r = exponweib.rvs(1.0,2.0,loc=0.0,scale=1.0,size=10); interv = exponweib.interval(0.99,1.0,2.0,loc=0.0,scale=1.0) print(interv); binned,edges = np.histogram(r,bins, normed=True); fit = exponweib.fit(r); DF = bins - len(fit); print(DF) x = np.linspace(np.min(r),np.max(r),bins); y = exponweib.pdf(x,*fit); kern = scipy.stats.gaussian_kde(r) res = binned - y; s_err = np.sum(res**2)/DF #err = exponweib.std(*fit); #print(scipy.stats.pearsonr(binned,y), scipy.stats.spearmanr(binned,y)); ykern = kern(x)
def fit_weibull_distribution_sp(data, init_a=1, init_c=1, scale=1, loc=0): vals = exponweib.fit(data, init_a, init_c, scale=scale, loc=loc) return vals, data, exponweib.pdf(data, *vals)
def plot_fall_distributions(fallScores): plt.rcParams.update({'font.size': 26}) plt.rcParams['text.usetex'] = True plt.rcParams['text.latex.preamble'] = [r'\usepackage{amsmath}'] fig, axs = plt.subplots(5, 1) fig.set_size_inches(10, 20) lines = [] bins = [[], [], [], [], []] y = [[], [], [], [], []] y2 = [[], [], [], [], []] fallScores[4] = [fallScores[4][i] / 0.8 for i in range(len(fallScores[4]))] labels = [ r'$\mathrm{Deterministic}$', r'$\mathrm{Probabilistic-CVaR~Cost}$', r'$\mathrm{Probabilistic-Expected+CVaR~Cost}$', r'$\mathrm{Probabilistic-Expected~Cost}$', r'$\mathrm{No~Intervention}$' ] for i in range(5): # (mu, sigma) = rayleigh.fit(fallScores[i]) prameters = exponweib.fit(fallScores[i], floc=0) # print(mu,sigma) n, bins[i], patches = axs[i].hist(fallScores[i], density=True, stacked=True, color="royalblue", bins=40, alpha=1) # y[i] = rayleigh.pdf(bins[i], mu, sigma) y2[i] = exponweib.pdf(bins[i], *prameters) # axs[i].plot(bins[i], y[i], "red", linewidth=3) axs[i].plot(bins[i], y2[i], "black", linewidth=3) axs[i].grid(True) axs[i].set_xlim(0, 17) axs[i].set_ylim(0, 1) axs[i].set_xticklabels([]) axs[i].set_yticklabels( [r'$\mathrm{0.0}$', r'$\mathrm{0.5}$', r'$\mathrm{1.0}$'], fontsize=20) props = dict(boxstyle='round', facecolor='white', alpha=1) axs[i].text(0.7, 0.9, labels[i], transform=axs[i].transAxes, fontsize=14, verticalalignment='top', bbox=props, ha='center') axs[4].set_xticklabels([ r'$\mathrm{0}$', r'$\mathrm{2.5}$', r'$\mathrm{5.0}$', r'$\mathrm{7.5}$', r'$\mathrm{10.0}$', r'$\mathrm{12.5}$', r'$\mathrm{15}$' ], fontsize=20) axs[4].set_xlabel(r'$\mathrm{Fall~Score}$', fontsize=20) axs[2].set_ylabel(r'$\mathrm{Density}$', fontsize=20) plt.show() fig5, ax6 = plt.subplots() fig5.set_size_inches(15, 10) labels = [ r'$\mathrm{Deterministic}$', r'$\mathrm{Probabilistic-CVaR~Cost}$', r'$\mathrm{Probabilistic-Expected+CVaR~Cost}$', r'$\mathrm{Probabilistic-Expected~Cost}$', r'$\mathrm{No~Intervention}$' ] colors = ['k-.', 'b--', 'r', 'b:', "k"] for i in range(5): lines.append( ax6.plot(bins[i], y2[i], colors[i], linewidth=3, label=labels[i])) # Add labels ax6.set_xticklabels([ r'$\mathrm{}$', r'$\mathrm{2}$', r'$\mathrm{4}$', r'$\mathrm{6}$', r'$\mathrm{8}$', r'$\mathrm{10}$', r'$\mathrm{12}$', r'$\mathrm{14}$', r'$\mathrm{16}$' ], fontsize=20) ax6.set_yticklabels([ r'$\mathrm{0.00}$', r'$\mathrm{0.05}$', r'$\mathrm{0.10}$', r'$\mathrm{0.15}$', r'$\mathrm{0.20}$', r'$\mathrm{0.25}$', r'$\mathrm{0.30}$' ], fontsize=20) ax6.set_xlabel(r'$\mathrm{Fall~Score}$', fontsize=20) ax6.set_ylabel(r'$\mathrm{Density}$', fontsize=20) ax6.legend(fontsize=20) ax6.grid(True) plt.show()
plt.plot(x, rv_exponential.pdf(np.array(x)), label='exponencial') plt.plot(x, rv_uniforme.pdf(np.array(x)), label='uniforme') plt.legend(loc='upper right') plt.title("ATERRIZAJES") # DESEMBARQUES #Cargamos las muestras de tiempo de los desembarques text_file = open("E4.desembarques.txt") datos = np.array(text_file.read().split('\n')) datos = datos[:-1].astype(float) #Ajustamos las muestras de tiempo a las diferentes distribuciones que queremos contrastar parametros_exponencial = expon.fit(datos) parametros_weibull = exponweib.fit( datos, floc=0, fa=1 ) #Establecemos el parámetro a de la distribución Weibull exponencial para obtener #la Weibull, además de establecer la media a 0 (puesto que la Weibull tiene media 0) parametros_normal = norm.fit(datos) print("=============DESEMBARQUES=============") print("Ajuste de parámetros de una distribución exponencial: ", parametros_exponencial) print("Ajuste de parámetros de una distribución weibull: ", parametros_weibull) print("Ajuste de parámetros de una distribución normal: ", parametros_normal) #Realizamos el contraste de las distribuciones que hemos obtenido del ajuste anterior con las muestras de tiempo print( "KS Test Exponencial: ", stats.kstest(datos, cdf='expon',
def hardness_est(self): dists = np.array(self.dist_mat).flatten() # normalise to r == 1 dists = dists / dists.max() * 2.0 _, shp, _, _ = exponweib.fit(dists, f0=1) return np.abs(-0.509 * shp + 0.707)
def weibull_params(self): if self._weibull_params is None: from scipy.stats import exponweib self._weibull_params = exponweib.fit(self.speed, floc=0) return self._weibull_params
def downtime_accepted_models(D=list(), alpha=.05): params = list() params.append(uniform.fit(D)) params.append(expon.fit(D)) params.append(rayleigh.fit(D)) params.append(weibull_min.fit(D)) params.append(gamma.fit(D)) params.append(gengamma.fit(D)) params.append(invgamma.fit(D)) params.append(gompertz.fit(D)) params.append(lognorm.fit(D)) params.append(exponweib.fit(D)) llf_value = list() llf_value.append(log(product(uniform.pdf(D, *params[0])))) llf_value.append(log(product(expon.pdf(D, *params[1])))) llf_value.append(log(product(rayleigh.pdf(D, *params[2])))) llf_value.append(log(product(weibull_min.pdf(D, *params[3])))) llf_value.append(log(product(gamma.pdf(D, *params[4])))) llf_value.append(log(product(gengamma.pdf(D, *params[5])))) llf_value.append(log(product(invgamma.pdf(D, *params[6])))) llf_value.append(log(product(gompertz.pdf(D, *params[7])))) llf_value.append(log(product(lognorm.pdf(D, *params[8])))) llf_value.append(log(product(exponweib.pdf(D, *params[9])))) AIC = list() AIC.append(2 * len(params[0]) - 2 * llf_value[0]) AIC.append(2 * len(params[1]) - 2 * llf_value[1]) AIC.append(2 * len(params[2]) - 2 * llf_value[2]) AIC.append(2 * len(params[3]) - 2 * llf_value[3]) AIC.append(2 * len(params[4]) - 2 * llf_value[4]) AIC.append(2 * len(params[5]) - 2 * llf_value[5]) AIC.append(2 * len(params[6]) - 2 * llf_value[6]) AIC.append(2 * len(params[7]) - 2 * llf_value[7]) AIC.append(2 * len(params[8]) - 2 * llf_value[8]) AIC.append(2 * len(params[9]) - 2 * llf_value[9]) model = list() model.append( ["uniform", params[0], kstest(D, "uniform", params[0])[1], AIC[0]]) model.append( ["expon", params[1], kstest(D, "expon", params[1])[1], AIC[1]]) model.append( ["rayleigh", params[2], kstest(D, "rayleigh", params[2])[1], AIC[2]]) model.append([ "weibull_min", params[3], kstest(D, "weibull_min", params[3])[1], AIC[3] ]) model.append( ["gamma", params[4], kstest(D, "gamma", params[4])[1], AIC[4]]) model.append( ["gengamma", params[5], kstest(D, "gengamma", params[5])[1], AIC[5]]) model.append( ["invgamma", params[6], kstest(D, "invgamma", params[6])[1], AIC[6]]) model.append( ["gompertz", params[7], kstest(D, "gompertz", params[7])[1], AIC[7]]) model.append( ["lognorm", params[8], kstest(D, "lognorm", params[8])[1], AIC[8]]) model.append( ["exponweib", params[9], kstest(D, "exponweib", params[9])[1], AIC[9]]) accepted_models = [i for i in model if i[2] > alpha] if accepted_models: aic_values = [i[3] for i in accepted_models] final_model = min(range(len(aic_values)), key=aic_values.__getitem__) return accepted_models, accepted_models[final_model] elif not accepted_models: aic_values = [i[3] for i in model] final_model = min(range(len(aic_values)), key=aic_values.__getitem__) return model, model[final_model]
def __init__(self,input_filename=None): self.streamdata = [] with open(input_filename, 'rb') as csvfile: inputdata = csv.reader(csvfile) for row in inputdata: self.streamdata.append(str(row[0])) # MTTR Calculation failcount = 0 failcount_list = [] streamdata = self.streamdata for i in xrange(len(streamdata)): if streamdata[i] == 'OK': continue if streamdata[i] == 'Fail' and streamdata[i+1] != 'OK': failcount = failcount + 1 if streamdata[i] == 'Fail' and streamdata[i+1] == 'OK': failcount = failcount + 1 # taking count = 15 as a starting point of being permanent failure if failcount > 15: failcount = 0 continue else: failcount_list.append(failcount) failcount = 0 MTTR = np.mean(failcount_list) # weibull distribution fit dd = exponweib.fit(failcount_list, floc=0,fa=1) dummy = list(set(list(failcount_list))) seaborn.set_style("darkgrid") values,bins,hist = plt.hist(failcount_list,bins=len(dummy),range=(0,max(dummy)),normed=True,rwidth=.5) plt.plot(bins,weibull(bins,dd[1],dd[3]),label='Fitted Weibull Distribution') plt.xlabel('Recovery Time') plt.ylabel('Probability') plt.title('Historical Recovery Time Distribution') plt.legend() plt.show() # MTTF Calculation OKcount = 0 OKcount_list = [] for i in xrange(len(streamdata)): if streamdata[i] == 'Fail': continue if i != (len(streamdata)-1) and streamdata[i] == 'OK' and streamdata[i+1] != 'Fail': OKcount = OKcount + 1 if i == (len(streamdata)-1) and streamdata[i] == 'OK': OKcount = OKcount + 1 if i != (len(streamdata)-1) and streamdata[i] == 'OK' and streamdata[i+1] == 'Fail': OKcount = OKcount + 1 OKcount_list.append(OKcount) OKcount = 0 MTTF = np.mean(OKcount_list) # MLT Calculation check_faillist = ['Fail' for i in xrange(15)] lifecount = 0 lifecount_list = [] for i in xrange(len(streamdata)): if streamdata[i] == 'OK': lifecount = lifecount + 1 if streamdata[i+1:i+16] == check_faillist: lifecount_list.append(lifecount) lifecount = 0 MLT = np.mean(lifecount_list) self.lamda = 1/MTTF self.mu = 1/MTTR self.delta = 1/MLT self.shape = dd[1] self.scale = dd[3]
def fitDist(self): n = len(self.data) # gamma distribution gammaParam = gamma.fit(self.data) gammaNumPar = len(gammaParam) gammaSum = -1 * np.sum(np.log(gamma.pdf(self.data, *gammaParam))) aicGamma = 2 * gammaNumPar + 2 * gammaSum + (2 * gammaNumPar * (gammaNumPar + 1) / (n - gammaNumPar - 1)) # rayleigh distribution rayleighParam = rayleigh.fit(self.data) rayleighNumPar = len(rayleighParam) rayleighSum = -1 * np.sum( np.log(rayleigh.pdf(self.data, *rayleighParam))) aicRayleigh = 2 * rayleighNumPar + 2 * rayleighSum + ( 2 * rayleighNumPar * (rayleighNumPar + 1) / (n - rayleighNumPar - 1)) # normal distribution normParam = norm.fit(self.data) normNumPar = len(normParam) normSum = -1 * np.sum(np.log(norm.pdf(self.data, *normParam))) aicNorm = 2 * normNumPar + 2 * normSum + (2 * normNumPar * (normNumPar + 1) / (n - normNumPar - 1)) # LogNormal distribution logNormParam = lognorm.fit(self.data) logNormNumPar = len(logNormParam) logNormSum = -1 * np.sum(np.log(lognorm.pdf(self.data, *logNormParam))) aicLogNorm = 2 * logNormNumPar + 2 * logNormSum + ( 2 * logNormNumPar * (logNormNumPar + 1) / (n - logNormNumPar - 1)) # Nakagami distribution nakagamiParam = nakagami.fit(self.data) nakagamiNumPar = len(nakagamiParam) nakagamiSum = -1 * np.sum( np.log(nakagami.pdf(self.data, *nakagamiParam))) aicNakagami = 2 * nakagamiNumPar + 2 * nakagamiSum + ( 2 * nakagamiNumPar * (nakagamiNumPar + 1) / (n - nakagamiNumPar - 1)) # exponential distribution exponParam = expon.fit(self.data) exponNumPar = len(exponParam) exponSum = -1 * np.sum(np.log(expon.pdf(self.data, *exponParam))) aicExpon = 2 * exponNumPar + 2 * exponSum + (2 * exponNumPar * (exponNumPar + 1) / (n - exponNumPar - 1)) # weibul distribution exponweibParam = exponweib.fit(self.data) exponweibNumPar = len(exponweibParam) exponweibSum = -1 * np.sum( np.log(exponweib.pdf(self.data, *exponweibParam))) aicExpWeib = 2 * exponweibNumPar + 2 * exponweibSum + ( 2 * exponweibNumPar * (exponweibNumPar + 1) / (n - exponweibNumPar - 1)) return (aicGamma, aicRayleigh, aicNorm, aicLogNorm, aicNakagami, aicExpon, aicExpWeib)
def distribution(data, column, norm=True, plotWeibull=False, upperLimit=1.0, title=''): x = np.linspace(data[column].min(), data[column].max(), 1000) if plotWeibull: plt.plot(x, exponweib.pdf(x, *exponweib.fit(data[column], 1, 1))) plt.title(title) return plt.hist(data[column], bins=np.linspace(0, upperLimit), normed=norm, alpha=0.5);