提交 a9f05bf6 authored 作者: Ricardo Vieira's avatar Ricardo Vieira 提交者: Ricardo Vieira

Cleanup random API docs

上级 1c2bc8fe
.. _libdoc_tensor_random_basic:
=============================================
:mod:`basic` -- Low-level random numbers
=============================================
.. module:: pytensor.tensor.random
:synopsis: symbolic random variables
The :mod:`pytensor.tensor.random` module provides random-number drawing functionality
that closely resembles the :mod:`numpy.random` module.
Reference
=========
.. class:: RandomStream()
A helper class that tracks changes in a shared :class:`numpy.random.RandomState`
and behaves like :class:`numpy.random.RandomState` by managing access
to :class:`RandomVariable`\s. For example:
.. testcode:: constructors
from pytensor.tensor.random.utils import RandomStream
rng = RandomStream()
sample = rng.normal(0, 1, size=(2, 2))
.. class:: RandomStateType(Type)
A :class:`Type` for variables that will take :class:`numpy.random.RandomState`
values.
.. function:: random_state_type(name=None)
Return a new :class:`Variable` whose :attr:`Variable.type` is an instance of
:class:`RandomStateType`.
.. class:: RandomVariable(Op)
:class:`Op` that draws random numbers from a :class:`numpy.random.RandomState` object.
This :class:`Op` is parameterized to draw numbers from many possible
distributions.
Distributions
==============
PyTensor can produce :class:`RandomVariable`\s that draw samples from many different statistical distributions, using the following :class:`Op`\s. The :class:`RandomVariable`\s behave similarly to NumPy's *Generalized Universal Functions* (or `gunfunc`): it supports "core" random variable :class:`Op`\s that map distinctly shaped inputs to potentially non-scalar outputs. We document this behavior in the following with `gufunc`-like signatures.
.. autoclass:: pytensor.tensor.random.basic.UniformRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.RandIntRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.IntegersRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.ChoiceRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.PermutationRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.BernoulliRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.BetaRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.BetaBinomialRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.BinomialRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.CauchyRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.CategoricalRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.DirichletRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.ExponentialRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.GammaRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.GenGammaRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.GeometricRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.GumbelRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.HalfCauchyRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.HalfNormalRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.HyperGeometricRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.InvGammaRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.LaplaceRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.LogisticRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.LogNormalRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.MultinomialRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.MvNormalRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.NegBinomialRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.NormalRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.ParetoRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.PoissonRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.StandardNormalRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.StudentTRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.TriangularRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.TruncExponentialRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.VonMisesRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.WaldRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.WeibullRV
:members: __call__
.. _libdoc_tensor_random_distributions:
Distributions
=============
.. automodule:: pytensor.tensor.random.basic
:members:
:special-members: __call__
.. _libdoc_tensor_random:
.. _libdoc_tensor_random_basic:
=============================================
:mod:`random` -- Low-level random numbers
:mod:`random` -- Random number functionality
=============================================
Low-level random numbers
------------------------
.. module:: pytensor.tensor.random
:synopsis: symbolic random variables
The :mod:`pytensor.tensor.random` module provides random-number drawing functionality
that closely resembles the :mod:`numpy.random` module.
.. toctree::
:maxdepth: 2
basic
utils
High-level API
==============
PyTensor assigns NumPy RNG states (i.e. `Generator` objects) to
each `RandomVariable`. The combination of an RNG state, a specific
`RandomVariable` type (e.g. `NormalRV`), and a set of distribution parameters
uniquely defines the `RandomVariable` instances in a graph.
This means that a "stream" of distinct RNG states is required in order to
produce distinct random variables of the same kind. `RandomStream` provides a
means of generating distinct random variables in a fully reproducible way.
`RandomStream` is also designed to produce simpler graphs and work with more
sophisticated `Op`\s like `Scan`, which makes it a user-friendly random variable
interface in PyTensor.
For an example of how to use random numbers, see :ref:`Using Random Numbers <using_random_numbers>`.
.. class:: RandomStream()
This is a symbolic stand-in for `numpy.random.Generator`.
.. method:: updates()
:returns: a list of all the (state, new_state) update pairs for the
random variables created by this object
This can be a convenient shortcut to enumerating all the random
variables in a large graph in the ``update`` argument to
`pytensor.function`.
.. method:: seed(meta_seed)
`meta_seed` will be used to seed a temporary random number generator,
that will in turn generate seeds for all random variables
created by this object (via `gen`).
:returns: None
.. method:: gen(op, *args, **kwargs)
Return the random variable from ``op(*args, **kwargs)``.
This function also adds the returned variable to an internal list so
that it can be seeded later by a call to `seed`.
.. method:: uniform, normal, binomial, multinomial, random_integers, ...
See :ref: Available distributions `<_libdoc_tensor_random_distributions>`.
.. testcode:: constructors
from pytensor.tensor.random.utils import RandomStream
rng = RandomStream()
sample = rng.normal(0, 1, size=(2, 2))
fn = pytensor.function([], sample)
print(fn(), fn()) # different numbers due to default updates
Low-level objects
=================
.. automodule:: pytensor.tensor.random.op
:members: RandomVariable, default_rng
..automodule:: pytensor.tensor.random.type
:members: RandomType, RandomGeneratorType, random_generator_type
.. automodule:: pytensor.tensor.random.basic
:members:
.. automodule:: pytensor.tensor.random.var
:members: RandomGeneratorSharedVariable
.. _libdoc_tensor_random_utils:
======================================================
:mod:`utils` -- Friendly random numbers
======================================================
.. module:: pytensor.tensor.random.utils
:platform: Unix, Windows
:synopsis: symbolic random variables
.. moduleauthor:: LISA
Guide
=====
PyTensor assigns NumPy RNG states (e.g. `Generator` or `RandomState` objects) to
each `RandomVariable`. The combination of an RNG state, a specific
`RandomVariable` type (e.g. `NormalRV`), and a set of distribution parameters
uniquely defines the `RandomVariable` instances in a graph.
This means that a "stream" of distinct RNG states is required in order to
produce distinct random variables of the same kind. `RandomStream` provides a
means of generating distinct random variables in a fully reproducible way.
`RandomStream` is also designed to produce simpler graphs and work with more
sophisticated `Op`\s like `Scan`, which makes it the de facto random variable
interface in PyTensor.
For an example of how to use random numbers, see :ref:`Using Random Numbers <using_random_numbers>`.
Reference
=========
.. class:: RandomStream()
This is a symbolic stand-in for `numpy.random.Generator`.
.. method:: updates()
:returns: a list of all the (state, new_state) update pairs for the
random variables created by this object
This can be a convenient shortcut to enumerating all the random
variables in a large graph in the ``update`` argument to
`pytensor.function`.
.. method:: seed(meta_seed)
`meta_seed` will be used to seed a temporary random number generator,
that will in turn generate seeds for all random variables
created by this object (via `gen`).
:returns: None
.. method:: gen(op, *args, **kwargs)
Return the random variable from ``op(*args, **kwargs)``.
This function also adds the returned variable to an internal list so
that it can be seeded later by a call to `seed`.
.. method:: uniform, normal, binomial, multinomial, random_integers, ...
See :class:`basic.RandomVariable`.
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论