maxframe.tensor.random.standard_cauchy#

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

从模式为 0 的标准柯西分布中抽取样本。

也称为洛伦兹分布。

参数:
  • size (int or tuple of ints, optional) -- 输出形状。如果给定的形状是,例如 (m, n, k),则抽取 m * n * k 个样本。默认为 None,此时返回一个单一值。

  • chunk_size (int or tuple of int or tuple of ints, optional) -- 每个维度上期望的分块大小

  • gpu (bool, optional) -- 如果为 True,则在 GPU 上分配张量,默认为 False

  • dtype (data-type, optional) -- 返回张量的数据类型。

返回:

samples -- 抽取的样本。

返回类型:

Tensor or scalar

备注

完整柯西分布的概率密度函数为

\[P(x; x_0, \gamma) = \frac{1}{\pi \gamma \bigl[ 1+ (\frac{x-x_0}{\gamma})^2 \bigr] }\]

而标准柯西分布只是设定了 \(x_0=0\)\(\gamma=1\)

柯西分布在受驱谐振子问题的解中出现,并且也描述了谱线的展宽。它还描述了一条以随机角度倾斜的直线与 x 轴相交位置的分布。

在研究假设正态性的假设检验时,观察这些检验在来自柯西分布的数据上的表现,是衡量它们对重尾分布敏感性的一个良好指标,因为柯西分布看起来非常像高斯分布,但尾部更重。

引用

示例

抽取样本并绘制分布:

>>> import maxframe.tensor as mt
>>> import matplotlib.pyplot as plt
>>> s = mt.random.standard_cauchy(1000000)
>>> s = s[(s>-25) & (s<25)]  # truncate distribution so it plots well
>>> plt.hist(s.execute(), bins=100)
>>> plt.show()