Skip to content

Implement RayleighRV #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions pytensor/tensor/random/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,48 @@ def __call__(self, alpha, beta, size=None, **kwargs):
beta = BetaRV()


class RayleighRV(RandomVariable):
r"""A rayleigh continuous random variable.

The probability density function for `rayleigh` is:

.. math::

P(x;scale) = \\frac{x}{scale^2}e^{\\frac{-x^2}{2 \\cdotp scale^2}}


"""
name = "rayleigh"
ndim_supp = 0
ndims_params = [0]
dtype = "floatX"
_print_name = ("Rayleigh", "\\operatorname{Rayleigh}")

def __call__(self, scale=1.0, size=None, **kwargs):
r"""Draw samples from a rayleigh distribution.

Signature
---------

`() -> ()`

Parameters
----------
scale
Scale, also equals the mode. Must be non-negative. Default is 1
size
Sample shape. If the given size is, e.g. `(m, n, k)` then `m * n * k`
independent, identically distributed random variables are
returned. Default is `None` in which case a single random variable
is returned.

"""
return super().__call__(scale, size=size, **kwargs)


rayleigh = RayleighRV()


class NormalRV(RandomVariable):
r"""A normal continuous random variable.

Expand Down Expand Up @@ -2125,4 +2167,5 @@ def __call__(self, x, **kwargs):
"negative_binomial",
"gengamma",
"t",
"rayleigh",
]
5 changes: 5 additions & 0 deletions tests/tensor/random/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
permutation,
poisson,
randint,
rayleigh,
standard_normal,
t,
triangular,
Expand Down Expand Up @@ -413,6 +414,10 @@ def test_exponential_default_args():
compare_sample_values(exponential)


def test_rayleigh_default_args():
compare_sample_values(rayleigh)


@pytest.mark.parametrize(
"alpha, size",
[
Expand Down