maxframe.tensor.random.rayleigh#

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

从瑞利分布中抽取样本。

\(\chi\) 和韦布尔分布是瑞利分布的推广。

参数:
  • scale (float or array_like of floats, optional) -- 尺度参数,也等于众数。应大于等于 0。默认为 1。

  • size (int or tuple of ints, optional) -- 输出形状。如果给定形状例如 (m, n, k),则抽取 m * n * k 个样本。如果 size 是 None``(默认),当 ``scale 是标量时返回单个值。否则抽取 mt.array(scale).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;scale) = \frac{x}{scale^2}e^{\frac{-x^2}{2 \cdotp scale^2}}\]

例如,如果风速的东向和北向分量具有相同的零均值高斯分布,则风速将服从瑞利分布。

引用

示例

从分布中抽取值并绘制直方图

>>> import matplotlib.pyplot as plt
>>> import maxframe.tensor as mt
>>> values = plt.hist(mt.random.rayleigh(3, 100000).execute(), bins=200, normed=True)

波高通常服从瑞利分布。如果平均波高为 1 米,那么有多少比例的波高可能超过 3 米?

>>> meanvalue = 1
>>> modevalue = mt.sqrt(2 / mt.pi) * meanvalue
>>> s = mt.random.rayleigh(modevalue, 1000000)

波高超过 3 米的比例为:

>>> (100.*mt.sum(s>3)/1000000.).execute()
0.087300000000000003