maxframe.tensor.random.noncentral_chisquare#
- maxframe.tensor.random.noncentral_chisquare(df, nonc, size=None, chunk_size=None, gpu=None, dtype=None)[源代码]#
从非中心卡方分布中抽取样本。
非中心 \(\chi^2\) 分布是 \(\chi^2\) 分布的推广。
- 参数:
df (float or array_like of floats) -- 自由度,应大于 0。
nonc (float or array_like of floats) -- 非中心性,应为非负数。
size (int or tuple of ints, optional) -- 输出形状。如果给定形状,例如
(m, n, k),则抽取m * n * k个样本。如果 size 为None``(默认),且 ``df和nonc均为标量,则返回单个值。否则,抽取mt.broadcast(df, nonc).size个样本。chunk_size (int or tuple of int or tuple of ints, optional) -- 每个维度上期望的块大小
gpu (bool, optional) -- 如果为 True,则将张量分配到 GPU 上,默认为 False
dtype (data-type, optional) -- 返回张量的数据类型。
- 返回:
out -- 从参数化的非中心卡方分布中抽取的样本。
- 返回类型:
Tensor or scalar
备注
非中心卡方分布的概率密度函数为
\[P(x;df,nonc) = \sum^{\infty}_{i=0} \frac{e^{-nonc/2}(nonc/2)^{i}}{i!} \P_{Y_{df+2i}}(x),\]其中 \(Y_{q}\) 是具有 q 个自由度的卡方分布。
Delhi (2007) 指出,非中心卡方分布在轰炸和覆盖问题中非常有用,点目标被摧毁的概率由非中心卡方分布给出。
引用
示例
从分布中抽取值并绘制直方图
>>> import matplotlib.pyplot as plt >>> import maxframe.tensor as mt >>> values = plt.hist(mt.random.noncentral_chisquare(3, 20, 100000).execute(), ... bins=200, normed=True) >>> plt.show()
从非中心性非常小的非中心卡方分布中抽取值,并与卡方分布进行比较。
>>> plt.figure() >>> values = plt.hist(mt.random.noncentral_chisquare(3, .0000001, 100000).execute(), ... bins=mt.arange(0., 25, .1).execute(), normed=True) >>> values2 = plt.hist(mt.random.chisquare(3, 100000).execute(), ... bins=mt.arange(0., 25, .1).execute(), normed=True) >>> plt.plot(values[1][0:-1], values[0]-values2[0], 'ob') >>> plt.show()
演示较大的非中心性如何导致分布更加对称。
>>> plt.figure() >>> values = plt.hist(mt.random.noncentral_chisquare(3, 20, 100000).execute(), ... bins=200, normed=True) >>> plt.show()