예제 #1
0
  def testExponentiallyModifiedGaussianLogPDF(self):
    batch_size = 6
    mu = tf.constant([3.0] * batch_size, dtype=self.dtype)
    sigma = tf.constant([math.sqrt(10.0)] * batch_size, dtype=self.dtype)
    rate = tf.constant([2.] * batch_size, dtype=self.dtype)
    x = np.array([-2.5, 2.5, 4.0, 0.0, -1.0, 2.0], dtype=self.dtype)
    exgaussian = tfd.ExponentiallyModifiedGaussian(
        loc=mu, scale=sigma, rate=rate, validate_args=True)

    log_pdf = exgaussian.log_prob(x)
    self.assertAllEqual(
        self.evaluate(exgaussian.batch_shape_tensor()), log_pdf.shape)
    self.assertAllEqual(
        self.evaluate(exgaussian.batch_shape_tensor()),
        self.evaluate(log_pdf).shape)
    self.assertAllEqual(exgaussian.batch_shape, log_pdf.shape)
    self.assertAllEqual(exgaussian.batch_shape, self.evaluate(log_pdf).shape)

    pdf = exgaussian.prob(x)
    self.assertAllEqual(
        self.evaluate(exgaussian.batch_shape_tensor()), pdf.shape)
    self.assertAllEqual(
        self.evaluate(exgaussian.batch_shape_tensor()),
        self.evaluate(pdf).shape)
    self.assertAllEqual(exgaussian.batch_shape, pdf.shape)
    self.assertAllEqual(exgaussian.batch_shape, self.evaluate(pdf).shape)

    expected_log_pdf = sp_stats.exponnorm(
        1. / (self.evaluate(rate) * self.evaluate(sigma)),
        loc=self.evaluate(mu),
        scale=self.evaluate(sigma)).logpdf(x)
    self.assertAllClose(
        expected_log_pdf, self.evaluate(log_pdf), atol=1e-5, rtol=1e-5)
    self.assertAllClose(
        np.exp(expected_log_pdf), self.evaluate(pdf), atol=1e-5, rtol=1e-5)
예제 #2
0
    def __init__(self,
                 nbElevator,
                 typeAlgo,
                 lamb=0.5,
                 expo=60,
                 typeIdle="noMoveIdle"):
        self.elevators = []
        self.users = {
            '1': [],
            '2': [],
            '3': [],
            '4': [],
            '5': [],
            '6': [],
            '7': []
        }
        self.totalUsers = 0
        self.totalTravels = 0
        self.totalWaitingTime = 0
        self.meanWaitingTime = 0
        self.calls = []
        self.expo = expo
        self.exp = exponnorm(expo)
        self.lamb = lamb
        self.typeIdle = typeIdle
        self.tpsAttendu = []

        for i in range(nbElevator):
            newElevator = Elevator(False, False, [], 1, typeAlgo,
                                   self.typeIdle)
            self.elevators.append(newElevator)

        userT = userThread(self)
        userT.start()
예제 #3
0
  def testExponentiallyModifiedGaussianLogCDF(self):
    batch_size = 50
    mu = self._rng.randn(batch_size)
    sigma = self._rng.rand(batch_size) + 1.0
    rate = self._rng.rand(batch_size) + 1.0
    x = np.linspace(-8.0, 8.0, batch_size).astype(self.dtype)

    exgaussian = tfd.ExponentiallyModifiedGaussian(
        loc=mu, scale=sigma, rate=rate, validate_args=True)
    cdf = exgaussian.log_cdf(x)
    self.assertAllEqual(
        self.evaluate(exgaussian.batch_shape_tensor()), cdf.shape)
    self.assertAllEqual(
        self.evaluate(exgaussian.batch_shape_tensor()),
        self.evaluate(cdf).shape)
    self.assertAllEqual(exgaussian.batch_shape, cdf.shape)
    self.assertAllEqual(exgaussian.batch_shape, self.evaluate(cdf).shape)
    expected_cdf = sp_stats.exponnorm(
        1. / (rate * sigma), loc=mu, scale=sigma).logcdf(x)
    self.assertAllClose(expected_cdf, self.evaluate(cdf), atol=0)
예제 #4
0
def Fit_background_distribution(image, mask_deep):
    # Check background, fit with gaussian and exp-gaussian distribution
    from scipy import stats

    plt.figure(figsize=(6, 4))
    z_sky = image[~mask_deep]
    if seaborn_plot:
        sns.distplot(z_sky, label='Data', hist_kws={'alpha': 0.3})
    else:
        plt.hist(z_sky, label='Data', alpha=0.3)

    mu_fit, std_fit = stats.norm.fit(z_sky)
    print(mu_fit, std_fit)
    d_mod = stats.norm(loc=mu_fit, scale=std_fit)
    x = np.linspace(d_mod.ppf(0.001), d_mod.ppf(0.999), 100)
    plt.plot(x, d_mod.pdf(x), 'g-', lw=2, alpha=0.6, label='Norm Fit')

    K_fit, mu_fit, std_fit = stats.exponnorm.fit(z_sky)
    print(K_fit, mu_fit, std_fit)
    d_mod2 = stats.exponnorm(loc=mu_fit, scale=std_fit, K=K_fit)
    x = np.linspace(d_mod2.ppf(0.001), d_mod2.ppf(0.9999), 100)
    plt.plot(x, d_mod2.pdf(x), 'r-', lw=2, alpha=0.6, label='Exp-Norm Fit')

    plt.legend(fontsize=12)
예제 #5
0
def generador_estadistica(base):
    from scipy.stats import expon, exponnorm, gamma, logistic, lognorm, norm, uniform, triang

    lista_distributions = []
    lista_parameters = []
    for z in range(0, len(base)):
        if base["Parameters"][z] == "Action can not be performed":
            lista_distributions.append("Action can not be performed")
            lista_parameters.append("Action can not be performed")
        else:
            distri_prueba = [*base["Parameters"][z]]
            lista_distributions.append(distri_prueba)
            lista_parameters.append(base["Parameters"][z].get(
                distri_prueba[0]))

    lista_mean = []
    lista_std = []
    for xx in range(0, len(base)):
        if lista_distributions[xx][0] == "expon":
            seleccion = expon(lista_parameters[xx][0], lista_parameters[xx][1])
            lista_mean.append(seleccion.mean())
            lista_std.append(seleccion.std())

        elif lista_distributions[xx][0] == "exponnorm":
            seleccion = exponnorm(lista_parameters[xx][0],
                                  lista_parameters[xx][1],
                                  lista_parameters[xx][2])
            lista_mean.append(seleccion.mean())
            lista_std.append(seleccion.std())

        elif lista_distributions[xx][0] == "gamma":
            seleccion = gamma(lista_parameters[xx][0], lista_parameters[xx][1],
                              lista_parameters[xx][2])
            lista_mean.append(seleccion.mean())
            lista_std.append(seleccion.std())

        elif lista_distributions[xx][0] == "logistic":
            seleccion = logistic(lista_parameters[xx][0],
                                 lista_parameters[xx][1])
            lista_mean.append(seleccion.mean())
            lista_std.append(seleccion.std())

        elif lista_distributions[xx][0] == "lognorm":
            seleccion = lognorm(lista_parameters[xx][0],
                                lista_parameters[xx][1],
                                lista_parameters[xx][2])
            lista_mean.append(seleccion.mean())
            lista_std.append(seleccion.std())

        elif lista_distributions[xx][0] == "norm":
            seleccion = norm(lista_parameters[xx][0], lista_parameters[xx][1])
            lista_mean.append(seleccion.mean())
            lista_std.append(seleccion.std())

        elif lista_distributions[xx][0] == "uniform":
            seleccion = uniform(lista_parameters[xx][0],
                                lista_parameters[xx][1])
            lista_mean.append(seleccion.mean())
            lista_std.append(seleccion.std())

        elif lista_distributions[xx][0] == "triang":
            seleccion = triang(lista_parameters[xx][0],
                               lista_parameters[xx][1],
                               lista_parameters[xx][2])
            lista_mean.append(seleccion.mean())
            lista_std.append(seleccion.std())

        elif lista_distributions[xx] == "Action can not be performed":
            lista_mean.append("No data for mean")
            lista_std.append("No data for std")

    base["mean"] = lista_mean
    base["std"] = lista_std
    return base
예제 #6
0
def generador_estadistica_2(base):
    dis = next(iter(base))
    lista_parameters = np.asarray(base[dis])

    if dis == "expon":
        seleccion = expon(lista_parameters[0], lista_parameters[1])
        lista_mean = seleccion.mean()
        lista_std = seleccion.std()
        lista_generador = seleccion.rvs(1000)

    elif dis == "exponnorm":
        seleccion = exponnorm(lista_parameters[0], lista_parameters[1],
                              lista_parameters[2])
        lista_mean = seleccion.mean()
        lista_std = seleccion.std()
        lista_generador = seleccion.rvs(1000)

    elif dis == "gamma":
        seleccion = gamma(lista_parameters[0], lista_parameters[1],
                          lista_parameters[2])
        lista_mean = seleccion.mean()
        lista_std = seleccion.std()
        lista_generador = seleccion.rvs(1000)

    elif dis == "logistic":
        seleccion = logistic(lista_parameters[0], lista_parameters[1])
        lista_mean = seleccion.mean()
        lista_std = seleccion.std()
        lista_generador = seleccion.rvs(1000)

    elif dis == "lognorm":
        seleccion = lognorm(lista_parameters[0], lista_parameters[1],
                            lista_parameters[2])
        lista_mean = seleccion.mean()
        lista_std = seleccion.std()
        lista_generador = seleccion.rvs(1000)

    elif dis == "norm":
        seleccion = norm(lista_parameters[0], lista_parameters[1])
        lista_mean = seleccion.mean()
        lista_std = seleccion.std()
        lista_generador = seleccion.rvs(1000)

    elif dis == "uniform":
        seleccion = uniform(lista_parameters[0], lista_parameters[1])
        lista_mean = seleccion.mean()
        lista_std = seleccion.std()
        lista_generador = seleccion.rvs(1000)

    elif dis == "triang":
        seleccion = triang(lista_parameters[0], lista_parameters[1],
                           lista_parameters[2])
        lista_mean = seleccion.mean()
        lista_std = seleccion.std()
        lista_generador = seleccion.rvs(1000)

    elif dis == "Action can not be performed":
        lista_mean = "No data for mean"
        lista_std = "No data for std"
        lista_generador = seleccion.rvs(1000)

    base["mean"] = lista_mean
    base["std"] = lista_std
    base["generador"] = lista_generador
    return base
예제 #7
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),
    }
예제 #8
0
mean, var, skew, kurt = exponnorm.stats(K, moments='mvsk')

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

x = np.linspace(exponnorm.ppf(0.01, K),
                exponnorm.ppf(0.99, K), 100)
ax.plot(x, exponnorm.pdf(x, K),
       'r-', lw=5, alpha=0.6, label='exponnorm 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 = exponnorm(K)
ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')

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

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

# Generate random numbers:

r = exponnorm.rvs(K, size=1000)

# And compare the histogram:

ax.hist(r, density=True, histtype='stepfilled', alpha=0.2)