Beispiel #1
0
    def _get_weibull_dist(self, qty, mean=None, std=None, scale=1.0, shape=5.0):

        x_line = np.arange(mean - std * 4.0, mean + std * 5.0, 1 * std)

        if self.weibull_dist_method == 'double':
            _data = dweibull(shape, loc=mean, scale=std)
            y_line = _data.pdf(x_line) * qty

        if self.weibull_dist_method == 'inverted':
            _data = invweibull(shape, loc=mean, scale=std)
            y_line = _data.pdf(x_line) * qty

        if self.weibull_dist_method == 'exponential':
            _data = exponweib(scale, shape, loc=mean, scale=std)
            y_line = _data.pdf(x_line) * qty

        if self.weibull_dist_method == 'min':
            _data = weibull_min(shape, loc=mean, scale=std)
            y_line = _data.pdf(x_line) * qty

        if self.weibull_dist_method == 'max':
            _data = weibull_max(shape, loc=mean, scale=std)
            y_line = _data.pdf(x_line) * qty

        line = Line(width=1280, height=600)
        line.add(u'{0}'.format(self.spc_target), x_line, y_line, xaxis_name=u'{0}'.format(self.spc_target),
                 yaxis_name=u'数量(Quantity)',
                 line_color='rgba(0 ,255 ,127,0.5)', legend_pos='center',
                 is_smooth=True, line_width=2,
                 tooltip_tragger='axis', is_fill=True, area_color='#20B2AA', area_opacity=0.4)
        pyecharts.configure(force_js_embed=True)
        return line.render_embed()
Beispiel #2
0
 def weibullRelease(self, period):
     """
     Returns the rate from a user-shaped weibull distribution function 
     at a specific period.  
     """
     par = self.parameters
     if len(par) == 2:   # scale = 1
         c = par[0]
         loc = par[1]
         frozenWeib = st.dweibull(c, loc)
         rate = frozenWeib.pdf(period)
         return rate
     elif len(self.parameters) == 3: # scale defined by user
         c = par[0]
         loc = par[1]
         scale = par[2]
         frozenWeib = st.dweibull(c, loc, scale)
         rate = frozenWeib.pdf(period)
         return rate
     else:
         print('ERROR:')
         print('Too few or too many arguments for weibull release function.')
         print('Enter two or three arguments for weibull release function.')
ax1 = fig.add_subplot(1, 2, 1)
sm.qqplot(logeados,
          stats.dgamma(parametros_dgamma[0],
                       loc=parametros_dgamma[1],
                       scale=parametros_dgamma[2]),
          line="45",
          ax=ax1)
ax1.set_title('dgamma', size=11.0)
ax1.set_xlabel("")
ax1.set_ylabel("")

ax2 = fig.add_subplot(1, 2, 2)
sm.qqplot(logeados,
          stats.dweibull(parametros_dweibull[0],
                         loc=parametros_dweibull[1],
                         scale=parametros_dweibull[2]),
          line="45",
          ax=ax2)
ax2.set_title('dweibull', size=11.0)
ax2.set_xlabel("")
ax2.set_ylabel("")

fig.tight_layout(pad=0.7)

fig.text(0.5, 0, 'Cuantiles teóricos', ha='center', va='center')
fig.text(0.,
         0.5,
         'Cuantiles observados',
         ha='center',
         va='center',
import numpy as np
from scipy.stats import dweibull
from matplotlib import pyplot as plt

#------------------------------------------------------------
# Define the distribution parameters to be plotted
k_values = [0.5, 1, 2, 2]
lam_values = [1, 1, 1, 2]
linestyles = ['-', '--', ':', '-.', '--']
mu = 0
x = np.linspace(-10, 10, 1000)

#------------------------------------------------------------
# plot the distributions
for (k, lam, ls) in zip(k_values, lam_values, linestyles):
    dist = dweibull(k, mu, lam)
    plt.plot(x,
             dist.pdf(x),
             ls=ls,
             c='black',
             label=r'$k=%.1f,\ \lambda=%i$' % (k, lam))

plt.xlim(0, 5)
plt.ylim(0, 1.0)

plt.xlabel('$x$', fontsize=14)
plt.ylabel(r'$P(x|k,\lambda)$', fontsize=14)
plt.title('Weibull Distribution')

plt.legend()
plt.show()
#   "Statistics, Data Mining, and Machine Learning in Astronomy" (2013)
#   For more information, see http://astroML.github.com
import numpy as np
from scipy.stats import dweibull
from matplotlib import pyplot as plt

#------------------------------------------------------------
# Define the distribution parameters to be plotted
k_values = [0.5, 1, 2, 2]
lam_values = [1, 1, 1, 2]
linestyles = ['-', '--', ':', '-.', '--']
mu = 0
x = np.linspace(-10, 10, 1000)

#------------------------------------------------------------
# plot the distributions
for (k, lam, ls) in zip(k_values, lam_values, linestyles):
    dist = dweibull(k, mu, lam)
    plt.plot(x, dist.pdf(x), ls=ls, c='black',
             label=r'$k=%.1f,\ \lambda=%i$' % (k, lam))

plt.xlim(0, 5)
plt.ylim(0, 1.0)

plt.xlabel('$x$', fontsize=14)
plt.ylabel(r'$p(x|k,\lambda)$', fontsize=14)
plt.title('Weibull Distribution')

plt.legend()
plt.show()
def dweibull(n = 100, c = 2.07, loc = 0, scale = 1):
    '''
    double weibull distribution

    n - розмір вибірки
    loc - середина
    scale - відхилення
    c - параметр c

    Повертає список вигляду [згенерована вибірка, список x, список y, середнє, мода, медіана,
    розмах, девіація, варіанса, стандарт, варіація, асиметрія, ексцес]
    '''
    distribution = st.dweibull(loc=loc, c=c, scale=scale)
    sample = list(distribution.rvs(size = n))

    for i in range(len(sample)):
        sample[i] = round(sample[i], 2)
     
    var = list(sample)
    var.sort()
    x = list(set(sample))
    y = list()
    x.sort()

    freq_table = dict()

    for num in x:
        freq_table[num] = sample.count(num)

    int_len = ((max(sample) - min(sample)) / r(sample))
    int_bounds = list()
    next = min(sample)

    for i in range(r(sample)):
        int_bounds.append(round(next, 2))
        next += int_len

    int_bounds.append(max(sample))

    freq_table = dict()
    int_list = list()

    for i in range(len(int_bounds)-1):
        int_list.append([int_bounds[i], int_bounds[i+1]])

    for i in range(len(int_list)):
        if i != len(int_list)-1:
            freq_table["[" + str(int_list[i][0]) + "; " + str(int_list[i][1]) + ")"] = 0
        else:
            freq_table["[" + str(int_list[i][0]) + "; " + str(int_list[i][1]) + "]"] = 0

    for i in range(len(sample)):
        for j in range(len(int_list)):
            if sample[i] >= int_list[j][0] and sample[i] < int_list[j][1] and j != len(int_list)-1:
                freq_table["[" + str(int_list[j][0]) + "; " + str(int_list[j][1]) + ")"] += 1

            elif sample[i] >= int_list[j][0] and sample[i] <= int_list[j][1] and j == len(int_list)-1:
                    freq_table["[" + str(int_list[j][0]) + "; " + str(int_list[j][1]) + "]"] += 1
        
    int_list_values = list()
    for key in freq_table:
        int_list_values.append(int(freq_table[key]))

    intr = list(freq_table.keys())

    centered_int = list()
    for intr in int_list:
        centered_int.append(round(((intr[0] + intr[1])/2), 3))

    freq_table_disc = dict()
    x = list(set(sample))
    for num in x:
        freq_table_disc[num] = sample.count(num)

    result = list()
    result.append(sample)

    start = distribution.ppf(0.01)
    end = distribution.ppf(0.99)
    x = list(np.linspace(start, end, n))
    y = list(distribution.pdf(x))
    result.append(x)
    result.append(y)

    mean = np.mean(sample)
    result.append(mean)

    moda = list(mode(freq_table_disc).keys())
    result.append(moda)

    med = statistics.median(sample)
    result.append(med)

    ro = max(sample) - min(sample)
    result.append(ro)
    
    deviation = dev(freq_table_disc)
    result.append(deviation)

    variansa = dev(freq_table_disc) / (len(sample)-1)
    result.append(variansa)

    standart = math.sqrt(variansa)
    result.append(standart)

    variation = standart / np.mean(sample)

    asym = st.skew(sample)
    result.append(asym)

    ex = st.kurtosis(sample)
    result.append(ex)

    return result
Beispiel #7
0
c = 2.07
mean, var, skew, kurt = dweibull.stats(c, moments='mvsk')

# Display the probability density function (``pdf``):

x = np.linspace(dweibull.ppf(0.01, c), dweibull.ppf(0.99, c), 100)
ax.plot(x, dweibull.pdf(x, c), 'r-', lw=5, alpha=0.6, label='dweibull pdf')

# Alternatively, the distribution object can be called (as a function)
# to fix the shape, location and scale parameters. This returns a "frozen"
# RV object holding the given parameters fixed.

# Freeze the distribution and display the frozen ``pdf``:

rv = dweibull(c)
ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')

# Check accuracy of ``cdf`` and ``ppf``:

vals = dweibull.ppf([0.001, 0.5, 0.999], c)
np.allclose([0.001, 0.5, 0.999], dweibull.cdf(vals, c))
# True

# Generate random numbers:

r = dweibull.rvs(c, size=1000)

# And compare the histogram:

ax.hist(r, normed=True, histtype='stepfilled', alpha=0.2)
Beispiel #8
0
import numpy as np
from scipy.stats import dweibull
from matplotlib import pyplot as plt
plt.ion()

Weibull = dweibull(2, 0, 6)  #k=2, lamda=6
x_axis = np.asarray([i + 0.5 for i in range(20)])
y_axis = np.asarray([
    2.75, 7.80, 11.64, 13.79, 14.20, 13.15, 11.14, 8.72, 6.34, 4.30, 2.73,
    1.62, 0.91, 0.48, 0.24, 0.11, 0.05, 0.02, 0.01, 0.00
]) * 100

y, c = [], 0
for i in range(len(y_axis)):
    y = np.concatenate((y, np.linspace(c, c + 1, y_axis[i])), axis=0)
    c += 1
plt.hist(y, bins=30, normed=True, label=' Data Histogram')

x = np.linspace(0, 20, 10e3)
plt.plot(x, Weibull.pdf(x) * 2, '-k', label='Weibull k=2,$ \lambda=6$')
plt.xlabel('x')
plt.ylabel('p(x|k,$\lambda)$')
plt.title('Weibull Distribution')
plt.legend()
plt.show()
Beispiel #9
0
def all_dists():
    # dists param were taken from scipy.stats official
    # documentaion examples
    # Total - 89
    return {
        "alpha":
        stats.alpha(a=3.57, loc=0.0, scale=1.0),
        "anglit":
        stats.anglit(loc=0.0, scale=1.0),
        "arcsine":
        stats.arcsine(loc=0.0, scale=1.0),
        "beta":
        stats.beta(a=2.31, b=0.627, loc=0.0, scale=1.0),
        "betaprime":
        stats.betaprime(a=5, b=6, loc=0.0, scale=1.0),
        "bradford":
        stats.bradford(c=0.299, loc=0.0, scale=1.0),
        "burr":
        stats.burr(c=10.5, d=4.3, loc=0.0, scale=1.0),
        "cauchy":
        stats.cauchy(loc=0.0, scale=1.0),
        "chi":
        stats.chi(df=78, loc=0.0, scale=1.0),
        "chi2":
        stats.chi2(df=55, loc=0.0, scale=1.0),
        "cosine":
        stats.cosine(loc=0.0, scale=1.0),
        "dgamma":
        stats.dgamma(a=1.1, loc=0.0, scale=1.0),
        "dweibull":
        stats.dweibull(c=2.07, loc=0.0, scale=1.0),
        "erlang":
        stats.erlang(a=2, loc=0.0, scale=1.0),
        "expon":
        stats.expon(loc=0.0, scale=1.0),
        "exponnorm":
        stats.exponnorm(K=1.5, loc=0.0, scale=1.0),
        "exponweib":
        stats.exponweib(a=2.89, c=1.95, loc=0.0, scale=1.0),
        "exponpow":
        stats.exponpow(b=2.7, loc=0.0, scale=1.0),
        "f":
        stats.f(dfn=29, dfd=18, loc=0.0, scale=1.0),
        "fatiguelife":
        stats.fatiguelife(c=29, loc=0.0, scale=1.0),
        "fisk":
        stats.fisk(c=3.09, loc=0.0, scale=1.0),
        "foldcauchy":
        stats.foldcauchy(c=4.72, loc=0.0, scale=1.0),
        "foldnorm":
        stats.foldnorm(c=1.95, loc=0.0, scale=1.0),
        # "frechet_r": stats.frechet_r(c=1.89, loc=0.0, scale=1.0),
        # "frechet_l": stats.frechet_l(c=3.63, loc=0.0, scale=1.0),
        "genlogistic":
        stats.genlogistic(c=0.412, loc=0.0, scale=1.0),
        "genpareto":
        stats.genpareto(c=0.1, loc=0.0, scale=1.0),
        "gennorm":
        stats.gennorm(beta=1.3, loc=0.0, scale=1.0),
        "genexpon":
        stats.genexpon(a=9.13, b=16.2, c=3.28, loc=0.0, scale=1.0),
        "genextreme":
        stats.genextreme(c=-0.1, loc=0.0, scale=1.0),
        "gausshyper":
        stats.gausshyper(a=13.8, b=3.12, c=2.51, z=5.18, loc=0.0, scale=1.0),
        "gamma":
        stats.gamma(a=1.99, loc=0.0, scale=1.0),
        "gengamma":
        stats.gengamma(a=4.42, c=-3.12, loc=0.0, scale=1.0),
        "genhalflogistic":
        stats.genhalflogistic(c=0.773, loc=0.0, scale=1.0),
        "gilbrat":
        stats.gilbrat(loc=0.0, scale=1.0),
        "gompertz":
        stats.gompertz(c=0.947, loc=0.0, scale=1.0),
        "gumbel_r":
        stats.gumbel_r(loc=0.0, scale=1.0),
        "gumbel_l":
        stats.gumbel_l(loc=0.0, scale=1.0),
        "halfcauchy":
        stats.halfcauchy(loc=0.0, scale=1.0),
        "halflogistic":
        stats.halflogistic(loc=0.0, scale=1.0),
        "halfnorm":
        stats.halfnorm(loc=0.0, scale=1.0),
        "halfgennorm":
        stats.halfgennorm(beta=0.675, loc=0.0, scale=1.0),
        "hypsecant":
        stats.hypsecant(loc=0.0, scale=1.0),
        "invgamma":
        stats.invgamma(a=4.07, loc=0.0, scale=1.0),
        "invgauss":
        stats.invgauss(mu=0.145, loc=0.0, scale=1.0),
        "invweibull":
        stats.invweibull(c=10.6, loc=0.0, scale=1.0),
        "johnsonsb":
        stats.johnsonsb(a=4.32, b=3.18, loc=0.0, scale=1.0),
        "johnsonsu":
        stats.johnsonsu(a=2.55, b=2.25, loc=0.0, scale=1.0),
        "ksone":
        stats.ksone(n=1e03, loc=0.0, scale=1.0),
        "kstwobign":
        stats.kstwobign(loc=0.0, scale=1.0),
        "laplace":
        stats.laplace(loc=0.0, scale=1.0),
        "levy":
        stats.levy(loc=0.0, scale=1.0),
        "levy_l":
        stats.levy_l(loc=0.0, scale=1.0),
        "levy_stable":
        stats.levy_stable(alpha=0.357, beta=-0.675, loc=0.0, scale=1.0),
        "logistic":
        stats.logistic(loc=0.0, scale=1.0),
        "loggamma":
        stats.loggamma(c=0.414, loc=0.0, scale=1.0),
        "loglaplace":
        stats.loglaplace(c=3.25, loc=0.0, scale=1.0),
        "lognorm":
        stats.lognorm(s=0.954, loc=0.0, scale=1.0),
        "lomax":
        stats.lomax(c=1.88, loc=0.0, scale=1.0),
        "maxwell":
        stats.maxwell(loc=0.0, scale=1.0),
        "mielke":
        stats.mielke(k=10.4, s=3.6, loc=0.0, scale=1.0),
        "nakagami":
        stats.nakagami(nu=4.97, loc=0.0, scale=1.0),
        "ncx2":
        stats.ncx2(df=21, nc=1.06, loc=0.0, scale=1.0),
        "ncf":
        stats.ncf(dfn=27, dfd=27, nc=0.416, loc=0.0, scale=1.0),
        "nct":
        stats.nct(df=14, nc=0.24, loc=0.0, scale=1.0),
        "norm":
        stats.norm(loc=0.0, scale=1.0),
        "pareto":
        stats.pareto(b=2.62, loc=0.0, scale=1.0),
        "pearson3":
        stats.pearson3(skew=0.1, loc=0.0, scale=1.0),
        "powerlaw":
        stats.powerlaw(a=1.66, loc=0.0, scale=1.0),
        "powerlognorm":
        stats.powerlognorm(c=2.14, s=0.446, loc=0.0, scale=1.0),
        "powernorm":
        stats.powernorm(c=4.45, loc=0.0, scale=1.0),
        "rdist":
        stats.rdist(c=0.9, loc=0.0, scale=1.0),
        "reciprocal":
        stats.reciprocal(a=0.00623, b=1.01, loc=0.0, scale=1.0),
        "rayleigh":
        stats.rayleigh(loc=0.0, scale=1.0),
        "rice":
        stats.rice(b=0.775, loc=0.0, scale=1.0),
        "recipinvgauss":
        stats.recipinvgauss(mu=0.63, loc=0.0, scale=1.0),
        "semicircular":
        stats.semicircular(loc=0.0, scale=1.0),
        "t":
        stats.t(df=2.74, loc=0.0, scale=1.0),
        "triang":
        stats.triang(c=0.158, loc=0.0, scale=1.0),
        "truncexpon":
        stats.truncexpon(b=4.69, loc=0.0, scale=1.0),
        "truncnorm":
        stats.truncnorm(a=0.1, b=2, loc=0.0, scale=1.0),
        "tukeylambda":
        stats.tukeylambda(lam=3.13, loc=0.0, scale=1.0),
        "uniform":
        stats.uniform(loc=0.0, scale=1.0),
        "vonmises":
        stats.vonmises(kappa=3.99, loc=0.0, scale=1.0),
        "vonmises_line":
        stats.vonmises_line(kappa=3.99, loc=0.0, scale=1.0),
        "wald":
        stats.wald(loc=0.0, scale=1.0),
        "weibull_min":
        stats.weibull_min(c=1.79, loc=0.0, scale=1.0),
        "weibull_max":
        stats.weibull_max(c=2.87, loc=0.0, scale=1.0),
        "wrapcauchy":
        stats.wrapcauchy(c=0.0311, loc=0.0, scale=1.0),
    }
pp_plot(logeados, stats.gennorm(beta = parametros_normal[0], 
                                loc = parametros_normal[1],
                                scale=parametros_normal[2]), 
        line = True, ax=ax1)

ax1.set_title('Normal generalizada', fontsize=11)


pp_plot(logeados, stats.genpareto(c = parametros_pareto[0], 
                                loc = parametros_pareto[1],
                                scale=parametros_pareto[2]), 
        line = True,ax=ax2)
ax2.set_title('Pareto generalizada', fontsize=11)

pp_plot(logeados, stats.dweibull(c = parametros_weibull[0], 
                                loc = parametros_weibull[1],
                                scale=parametros_weibull[2]), 
        line = True,ax=ax3)
ax3.set_title('Weibull doble', fontsize=11)

pp_plot(logeados, stats.gamma(a = parametros_gamma[0], 
                                loc = parametros_gamma[1],
                                scale=parametros_gamma[2]), 
        line = True,ax=ax4)
ax4.set_title('Gamma', fontsize=11)

fig.tight_layout(pad=0.7)

fig.text(0.5, 0, 'Probabilidades teóricas', ha='center', va='center')
fig.text(0., 0.5, 'Probabilidades observadas', ha='center', va='center', rotation='vertical')