def uniform_distribution(*args):
     try:
         a, b = float(args[0]), float(args[1])
     except (ValueError, TypeError):
         return {'is_valid': False}
     if b < a:
         a, b = b, a
     elif b == a:
         return {'is_valid': False}
     t = Symbol('t')
     mean, var = uniform.stats(loc=a, scale=b - a, moments='mv')
     cf = (exp(I * t * b) - exp(I * t * a)) / (I * t * (b - a))
     d_cf = diff(cf, t)
     dd_cf = diff(d_cf, t)
     mean2 = uniform.moment(2, loc=a, scale=b - a)
     return {
         'a': a,
         'b': b,
         'mean': round(float(mean), 2),
         'mean2': round(mean2, 2),
         'b_minus_a': b - a,
         'var': round(float(var), 2),
         'g': latex(nsimplify(cf, tolerance=0.1)),
         'g1': latex(nsimplify(d_cf, tolerance=0.1)),
         'g2': latex(nsimplify(dd_cf, tolerance=0.1)),
         'type': type,
         'is_valid': True,
     }
Exemple #2
0
### .plot() : Permet de tracer un graphe (x,y) suivant des options determinees
# 'r' est la couleur rouge du tracer
# 'k' est la couleur noire du tracer
# 'lw' = 'linewidth'


# ============================================= #
# ============= UNIFORME CONTINUE ============= #
# ============================================= #

fig, ax = plt.subplots(1, 1)

#### Calcul de différentes valeurs statistiques
# mean, variance, skew & kurtosis
# = moyenne, variance, coef d'asymétrie, coef d'aplatissement
mean, var, skew, kurt = uniform.stats(moments='mvsk')

# Création d'un ensemble de valeurs équitablement espacées
x = np.linspace(uniform.ppf(0.01), uniform.ppf(0.99), 100)

ax.plot(x, uniform.pdf(x),'r-', lw=5, alpha=0.6, label='uniform pdf')


# L'appel de la fonction permet de recevoir une version 'frozen' de la PDF
rv = uniform()
ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')

vals = uniform.ppf([0.001, 0.5, 0.999])

# Return True ou False si les elements sont d'un vecteur sont egaux (a tolerance pres)
np.allclose([0.001, 0.5, 0.999], uniform.cdf(vals))
Exemple #3
0
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import uniform

print uniform.rvs(loc=0, scale=1, size=10)
print uniform.stats(moments='mvsk')

print uniform.rvs(size=1000)
Exemple #4
0
import matplotlib

matplotlib.use('Agg')

import scipy.stats
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from scipy.stats import uniform, pareto, norm

#mean, var, skew, kurt =
b = 1.0
dists = []
dists += [[("pareto"), pareto.stats(2, moments='mvsk'), pareto]]
dists += [[("uniform"), uniform.stats(moments='mvsk'), uniform]]
dists += [[("normal"), norm.stats(moments='mvsk'), norm]]
dists += [[("normal_sc"), norm.stats(moments='mvsk'), norm]]

print(dists)

size = 20000

for dist in dists:

    print dist[0]
    if (dist[0] == "pareto"):
        sample = dist[2].rvs(b, size=size)
        sample = sample[(sample < 8)]
    if (dist[0] == "normal"):
        sample = dist[2].rvs(size=size)
    if (dist[0] == "uniform"):
Exemple #5
0
plt.legend(loc='upper left', shadow=True)

plt.show()

# ### Uniform (Continuous) Distribution

# In[8]:

#Uniform (Continuous) Distribution
from scipy.stats import uniform

loc, scale = 1, 10
x = np.linspace(uniform.ppf(0.01, loc, scale), uniform.ppf(0.99, loc, scale),
                100)  #Percent Point Function (inverse of cdf — percentiles)

print("Mean              : ", uniform.stats(loc, scale, moments='m'))
print("Variance          : ", uniform.stats(loc, scale, moments='v'))
print("Prob. Dens. Func. : ", uniform.pdf(x, loc, scale))
print("Cum. Density Func.: ", uniform.cdf(x, loc, scale))

CDF = randint.cdf(x, loc, scale)

fig = plt.figure(figsize=(20, 10))
plt.subplot(221)
plt.plot(x, uniform.pdf(x, loc, scale), 'g', ms=8, label='PDF')
plt.vlines(loc, 0, 0.1, colors='g', lw=5, alpha=0.5, linestyle='dashed')
plt.vlines(scale + 1, 0, 0.1, colors='g', lw=5, alpha=0.5, linestyle='dashed')
plt.xlabel("Sample Space of Continuous Uniform Distribution", fontsize=14)
plt.ylabel("PDF", fontsize=14)
plt.title(
    "Probability Distribution of Continuous Uniform(a=1,b=10) Distribution",
Exemple #6
0
def testUniform(a, b, size):
    values = [lhw.rnuni(a, b) for i in range(size)]
    mean, var = uniform.stats(a, b - 1, moments='mv')
    startWork(values, mean, var, "uniform")
    pass
def uniform_central_moment(loc, scale, moment):
    if moment < 1 or moment > 4:
        print 'Unable to compute moment of uniform distribution ):'
        assert(False)
    moments_arr = uniform.stats(loc=loc, scale=scale, moments='mvsk')
    return moments_arr[moment - 1]
Exemple #8
0
# plt.title(u'泊松分布与二项分布对比')
# plt.show()

# 几何分布
# fig,ax = plt.subplots(1,1)
# p = 0.5
# #平均值, 方差, 偏度, 峰度
# mean,var,skew,kurt = geom.stats(p,moments='mvsk')
# print(mean,var,skew,kurt)
# #ppf:累积分布函数的反函数。q=0.01时,ppf就是p(X<x)=0.01时的x值。
# x = np.arange(geom.ppf(0.01, p),geom.ppf(0.99, p))
# ax.plot(x, geom.pmf(x, p),'o')
# plt.title(u'几何分布概率质量函数')
# plt.show()

# 均匀分布
fig, ax = plt.subplots(1, 1)

loc = 1
scale = 1

# 平均值, 方差, 偏度, 峰度
mean, var, skew, kurt = uniform.stats(loc, scale, moments='mvsk')
print(mean, var, skew, kurt)
# ppf:累积分布函数的反函数。q=0.01时,ppf就是p(X<x)=0.01时的x值。
x = np.linspace(uniform.ppf(0.01, loc, scale), uniform.ppf(0.99, loc, scale),
                100)
ax.plot(x, uniform.pdf(x, loc, scale), 'b-', label='uniform')

plt.title(u'均匀分布概率密度函数')
plt.show()