|
6 | 6 |
|
7 | 7 | import pytensor
|
8 | 8 | from pytensor.tensor.basic import arange, as_tensor_variable
|
| 9 | +from pytensor.tensor.math import sqrt |
9 | 10 | from pytensor.tensor.random.op import RandomVariable
|
10 | 11 | from pytensor.tensor.random.type import RandomGeneratorType, RandomStateType
|
11 | 12 | from pytensor.tensor.random.utils import (
|
@@ -526,6 +527,43 @@ def chisquare(df, size=None, **kwargs):
|
526 | 527 | return gamma(shape=df / 2.0, scale=2.0, size=size, **kwargs)
|
527 | 528 |
|
528 | 529 |
|
| 530 | +def rayleigh(scale=1.0, *, size=None, **kwargs): |
| 531 | + r"""Draw samples from a Rayleigh distribution. |
| 532 | +
|
| 533 | + The probability density function for `rayleigh` with parameter `scale` is given by: |
| 534 | +
|
| 535 | + .. math:: |
| 536 | + f(x; s) = \frac{x}{s^2} e^{-x^2/(2 s^2)} |
| 537 | +
|
| 538 | + where :math:`s` is the scale parameter. |
| 539 | +
|
| 540 | + This variable is obtained by taking the square root of the sum of the squares of |
| 541 | + two independent, standard normally distributed random variables. |
| 542 | +
|
| 543 | + Signature |
| 544 | + --------- |
| 545 | + `() -> ()` |
| 546 | +
|
| 547 | + Parameters |
| 548 | + ---------- |
| 549 | + scale : float or array_like of floats, optional |
| 550 | + Scale parameter of the distribution (positive). Default is 1.0. |
| 551 | + size : int or tuple of ints, optional |
| 552 | + Output shape. If the given shape is, e.g., `(m, n, k)`, then `m * n * k` samples |
| 553 | + are drawn. Default is None, in which case the output shape is determined by the |
| 554 | + shape of `scale`. |
| 555 | +
|
| 556 | + Notes |
| 557 | + ----- |
| 558 | + `Rayleigh` is a special case of `chisquare` with ``df=2``. |
| 559 | + """ |
| 560 | + |
| 561 | + scale = as_tensor_variable(scale) |
| 562 | + if size is None: |
| 563 | + size = scale.shape |
| 564 | + return sqrt(chisquare(df=2, size=size, **kwargs)) * scale |
| 565 | + |
| 566 | + |
529 | 567 | class ParetoRV(ScipyRandomVariable):
|
530 | 568 | r"""A pareto continuous random variable.
|
531 | 569 |
|
|
0 commit comments