r"""Random variable with Beta distribution :math:`\operatorname{Beta}(\alpha, \beta)`. The corresponding probability density function is .. math:: p(x)=\frac{1}{\mathrm{~B}(\alpha, \beta)} x^{\alpha-1}(1-x)^{\beta-1} \quad \text { for } \alpha, \beta>0,
(
self,
alpha: Union[Tensor, float],
beta: Union[Tensor, float],
size: Optional[Iterable[int]] = None,
)
| 433 | ) |
| 434 | |
| 435 | def beta( |
| 436 | self, |
| 437 | alpha: Union[Tensor, float], |
| 438 | beta: Union[Tensor, float], |
| 439 | size: Optional[Iterable[int]] = None, |
| 440 | ): |
| 441 | r"""Random variable with Beta distribution :math:`\operatorname{Beta}(\alpha, \beta)`. |
| 442 | |
| 443 | The corresponding probability density function is |
| 444 | |
| 445 | .. math:: |
| 446 | |
| 447 | p(x)=\frac{1}{\mathrm{~B}(\alpha, \beta)} x^{\alpha-1}(1-x)^{\beta-1} |
| 448 | \quad \text { for } \alpha, \beta>0, |
| 449 | |
| 450 | where :math:`\mathrm{~B}(\alpha, \beta)` is the beta function, |
| 451 | |
| 452 | .. math:: |
| 453 | |
| 454 | \mathrm{~B}(\alpha, \beta)=\int_{0}^{1} t^{\alpha-1}(1-t)^{\beta-1} d t. |
| 455 | |
| 456 | Args: |
| 457 | alpha(Union[Tensor, float]): the alpha parameter of the distribution. Must be positive. |
| 458 | beta(Union[Tensor, float]): the beta parameter of the distribution. Must be positive. |
| 459 | size(Optional[Iterable[int]]): the size of output tensor. If alpha and beta are scalars and given size is, e.g., |
| 460 | `(m, n)`, then the output shape is `(m, n)`. If alpha or beta is a Tensor and given size |
| 461 | is, e.g., `(m, n)`, then the output shape is `(m, n) + broadcast(alpha, beta).shape`. Default: None. |
| 462 | |
| 463 | Returns: |
| 464 | Return type: tensor. The random variable with Beta distribution. |
| 465 | |
| 466 | Examples: |
| 467 | >>> import megengine.random as rand |
| 468 | >>> x = rand.beta(alpha=2, beta=1, size=(2, 2)) |
| 469 | >>> x.numpy() # doctest: +SKIP |
| 470 | array([[0.6172312 , 0.9789006 ], |
| 471 | [0.50004643, 0.9775796 ]], dtype=float32) |
| 472 | >>> alpha = mge.Tensor([[0.5], |
| 473 | ... [ 3]], dtype="float32") |
| 474 | >>> beta = mge.Tensor([0.5,5], dtype="float32") |
| 475 | >>> x = rand.beta(alpha=alpha, beta=beta) |
| 476 | >>> x.numpy() # doctest: +SKIP |
| 477 | array([[0.0075407 , 0.1275094 ], |
| 478 | [0.96331763, 0.22299217]], dtype=float32) |
| 479 | >>> x = rand.beta(alpha=alpha, beta=beta, size=2) |
| 480 | >>> x.numpy() # doctest: +SKIP |
| 481 | array([[[0.46863747, 0.13819647], |
| 482 | [0.8646759 , 0.16014215]], |
| 483 | |
| 484 | [[0.0682759 , 0.04448463], |
| 485 | [0.97733796, 0.19206746]]], dtype=float32) |
| 486 | """ |
| 487 | _seed = self._seed() if callable(self._seed) else self._seed |
| 488 | return _beta(alpha=alpha, beta=beta, size=size, seed=_seed, handle=self._handle) |
| 489 | |
| 490 | def poisson(self, lam: Union[float, Tensor], size: Optional[Iterable[int]] = None): |
| 491 | r"""Random variable with poisson distribution :math:`\operatorname{Poisson}(\lambda)`. |