megengine.random.beta

beta(alpha, beta, size=None)

服从贝塔分布 Beta(α,β) 的随机变量。

对应的概率密度函数为

p(x)=1 B(α,β)xα1(1x)β1 for α,β>0,

其中  B(α,β) 是 Beta 函数,

 B(α,β)=01tα1(1t)β1dt.
参数
  • alpha (Union[Tensor, float]) – the alpha parameter of the distribution. Must be positive.

  • beta (Union[Tensor, float]) – the beta parameter of the distribution. Must be positive.

  • size (Optional[Iterable[int]]) – the size of output tensor. If alpha and beta are scalars and given size is, e.g., (m, n), then the output shape is (m, n). If alpha or beta is a Tensor and given size is, e.g., (m, n), then the output shape is (m, n) + broadcast(alpha, beta).shape. Default: None.

返回

tensor. The random variable with Beta distribution.

返回类型

Return type

实际案例

>>> import megengine.random as rand
>>> x = rand.beta(alpha=2, beta=1, size=(2, 2))
>>> x.numpy()   
array([[0.6172312 , 0.9789006 ],
       [0.50004643, 0.9775796 ]], dtype=float32)
>>> alpha = mge.Tensor([[0.5],
...                     [  3]], dtype="float32")
>>> beta = mge.Tensor([0.5,5], dtype="float32")
>>> x = rand.beta(alpha=alpha, beta=beta)
>>> x.numpy()   
array([[0.0075407 , 0.1275094 ],
       [0.96331763, 0.22299217]], dtype=float32)
>>> x = rand.beta(alpha=alpha, beta=beta, size=2)
>>> x.numpy()   
array([[[0.46863747, 0.13819647],
        [0.8646759 , 0.16014215]],
[[0.0682759 , 0.04448463],

[0.97733796, 0.19206746]]], dtype=float32)