maxframe.tensor.random.chisquare#

maxframe.tensor.random.chisquare(df, size=None, chunk_size=None, gpu=None, dtype=None)[源代码]#

从卡方分布中抽取样本。

df 个独立的随机变量,每个都服从标准正态分布(均值为 0,方差为 1),平方并求和后,所得的分布即为卡方分布(参见注释)。此分布常用于假设检验。

参数:
  • df (float or array_like of floats) -- 自由度数,应大于 0。

  • size (int or tuple of ints, optional) -- 输出形状。如果给定的形状为,例如 (m, n, k),则抽取 m * n * k 个样本。如果 size 为 None``(默认),且 ``df 是标量,则返回单个值。否则,抽取 mt.array(df).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

抛出:

ValueError -- 当 df <= 0 或者给定不合适的 size`(例如 ``size=-1`)时。

备注

通过对 df 个独立且服从标准正态分布的随机变量进行平方并求和得到的变量:

\[Q = \sum_{i=0}^{\mathtt{df}} X^2_i\]

服从卡方分布,记作

\[Q \sim \chi^2_k.\]

卡方分布的概率密度函数为

\[p(x) = \frac{(1/2)^{k/2}}{\Gamma(k/2)} x^{k/2 - 1} e^{-x/2},\]

其中 \(\Gamma\) 是伽马函数,

\[\Gamma(x) = \int_0^{-\infty} t^{x - 1} e^{-t} dt.\]

引用

示例

>>> import maxframe.tensor as mt
>>> mt.random.chisquare(2,4).execute()
array([ 1.89920014,  9.00867716,  3.13710533,  5.62318272])