def gamma(self,samples):
"""
Sampling from a Gamma distribution with mean 1
The parameterization with alpha and beta is more common in Bayesian statistics,
where the gamma distribution is used as a conjugate prior distribution
for various types of inverse scale (aka rate) parameters, such as the
lambda of an exponential distribution or a Poisson distribution[4] or for
t hat matter, the beta of the gamma distribution itself.
(The closely related inverse gamma distribution is used as a conjugate
prior for scale parameters, such as the variance of a normal distribution.)
shape, scale = 2., 2. # mean=4, std=2*sqrt(2)
(Wikipedia: https://en.wikipedia.org/wiki/Gamma_distribution)
s = np.random.gamma(shape, scale, 1000)
E|x| = k.theta (alpha*theta)
If i want a specific mean, theta=E|x|/alpha
------------------------------------------------------------------------
- samples: number of values that will be returned.
"""
shape=float(self.__params[0]*1.0)
theta=float(self.__params[1]*1.0)
distro=gamma(a=shape,scale=theta)
f=distro.rvs(size=samples)
return f
评论列表
文章目录