megengine.random.beta#
- beta(alpha, beta, size=None)#
Random variable with Beta distribution \(\operatorname{Beta}(\alpha, \beta)\).
The corresponding probability density function is
\[p(x)=\frac{1}{\mathrm{~B}(\alpha, \beta)} x^{\alpha-1}(1-x)^{\beta-1} \quad \text { for } \alpha, \beta>0,\]where \(\mathrm{~B}(\alpha, \beta)\) is the beta function,
\[\mathrm{~B}(\alpha, \beta)=\int_{0}^{1} t^{\alpha-1}(1-t)^{\beta-1} d t.\]- Parameters:
alpha (
Union
[Tensor
,float
]) – the alpha parameter of the distribution. Must be non-negative.beta (
Union
[Tensor
,float
]) – the beta parameter of the distribution. Must be non-negative.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.
- Returns:
the output tensor.
Examples
>>> 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)