Beispiel #1
0
import numpy as np
from scipy.stats import laplace
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)

mean, var, skew, kurt = laplace.stats(moments='mvsk')

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



rv = laplace()
ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')
vals = laplace.ppf([0.001, 0.5, 0.999])
np.allclose([0.001, 0.5, 0.999], laplace.cdf(vals))

r = laplace.rvs(size=1000)
#ax.hist(r, normed=True, histtype='stepfilled', alpha=0.2)
#ax.legend(loc='best', frameon=False)

plt.show()
def laplace_central_moment(loc, scale, moment):
    if moment < 1 or moment > 4:
        print 'Unable to compute moment of laplace distribution ):'
        assert(False)
    moments_arr = laplace.stats(loc=loc, scale=scale, moments='mvsk')
    return moments_arr[moment - 1]