scipy.stats.genextreme#
- scipy.stats.genextreme = <scipy.stats._continuous_distns.genextreme_gen object>[source]#
一个广义极值连续随机变量。
作为
rv_continuous类的一个实例,genextreme对象继承了该类的通用方法集(完整列表请参见下文),并针对此特定分布补充了详细信息。方法
rvs(c, loc=0, scale=1, size=1, random_state=None)
随机变量。
pdf(x, c, loc=0, scale=1)
概率密度函数。
logpdf(x, c, loc=0, scale=1)
概率密度函数的对数。
cdf(x, c, loc=0, scale=1)
累积分布函数。
logcdf(x, c, loc=0, scale=1)
累积分布函数的对数。
sf(x, c, loc=0, scale=1)
生存函数(也定义为
1 - cdf,但sf有时更准确)。logsf(x, c, loc=0, scale=1)
生存函数的对数。
ppf(q, c, loc=0, scale=1)
百分点函数(
cdf的逆函数——百分位数)。isf(q, c, loc=0, scale=1)
逆生存函数(
sf的逆函数)。moment(order, c, loc=0, scale=1)
指定阶数的非中心矩。
stats(c, loc=0, scale=1, moments=’mv’)
均值(‘m’)、方差(‘v’)、偏度(‘s)和/或峰度(‘k)。
entropy(c, loc=0, scale=1)
(微分)熵。
fit(data)
通用数据的参数估计。有关关键字参数的详细文档,请参阅scipy.stats.rv_continuous.fit。
expect(func, args=(c,), loc=0, scale=1, lb=None, ub=None, conditional=False, **kwds)
关于分布的函数(一个自变量)的期望值。
median(c, loc=0, scale=1)
分布的中位数。
mean(c, loc=0, scale=1)
分布的均值。
var(c, loc=0, scale=1)
分布的方差。
std(c, loc=0, scale=1)
分布的标准差。
interval(confidence, c, loc=0, scale=1)
中位数周围面积相等的置信区间。
另请参阅
附注
对于 \(c=0\),
genextreme等同于gumbel_r,其概率密度函数为\[f(x) = \exp(-\exp(-x)) \exp(-x),\]其中 \(-\infty < x < \infty\)。
对于 \(c \ne 0\),
genextreme的概率密度函数为\[f(x, c) = \exp(-(1-c x)^{1/c}) (1-c x)^{1/c-1},\]其中如果 \(c > 0\),则 \(-\infty < x \le 1/c\);如果 \(c < 0\),则 \(1/c \le x < \infty\)。
请注意,一些来源和软件包对形状参数 \(c\) 的符号使用了相反的约定。
genextreme将c作为 \(c\) 的形状参数。上述概率密度是以“标准化”形式定义的。要平移和/或缩放分布,请使用
loc和scale参数。具体而言,genextreme.pdf(x, c, loc, scale)与genextreme.pdf(y, c) / scale完全等同,其中y = (x - loc) / scale。请注意,平移分布的位置并不会使其成为“非中心”分布;某些分布的非中心推广可在单独的类中获得。示例
>>> import numpy as np >>> from scipy.stats import genextreme >>> import matplotlib.pyplot as plt >>> fig, ax = plt.subplots(1, 1)
获取支撑域
>>> c = -0.1 >>> lb, ub = genextreme.support(c)
计算前四个矩
>>> mean, var, skew, kurt = genextreme.stats(c, moments='mvsk')
显示概率密度函数(
pdf)>>> x = np.linspace(genextreme.ppf(0.01, c), ... genextreme.ppf(0.99, c), 100) >>> ax.plot(x, genextreme.pdf(x, c), ... 'r-', lw=5, alpha=0.6, label='genextreme pdf')
或者,可以通过调用分布对象(作为函数)来固定形状、位置和尺度参数。这将返回一个包含固定参数的“冻结”RV对象。
冻结分布并显示冻结的
pdf>>> rv = genextreme(c) >>> ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')
检查
cdf和ppf的准确性>>> vals = genextreme.ppf([0.001, 0.5, 0.999], c) >>> np.allclose([0.001, 0.5, 0.999], genextreme.cdf(vals, c)) True
生成随机数
>>> r = genextreme.rvs(c, size=1000)
并比较直方图
>>> ax.hist(r, density=True, bins='auto', histtype='stepfilled', alpha=0.2) >>> ax.set_xlim([x[0], x[-1]]) >>> ax.legend(loc='best', frameon=False) >>> plt.show()