Skip to content

Commit a9f05bf

Browse files
committed
Cleanup random API docs
1 parent 1c2bc8f commit a9f05bf

File tree

4 files changed

+86
-235
lines changed

4 files changed

+86
-235
lines changed

doc/library/tensor/random/basic.rst

Lines changed: 0 additions & 161 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. _libdoc_tensor_random_distributions:
2+
3+
Distributions
4+
=============
5+
6+
.. automodule:: pytensor.tensor.random.basic
7+
:members:
8+
:special-members: __call__

doc/library/tensor/random/index.rst

Lines changed: 78 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,89 @@
1-
.. _libdoc_tensor_random:
1+
2+
.. _libdoc_tensor_random_basic:
23

34
=============================================
4-
:mod:`random` -- Low-level random numbers
5+
:mod:`random` -- Random number functionality
56
=============================================
67

7-
Low-level random numbers
8-
------------------------
8+
.. module:: pytensor.tensor.random
9+
:synopsis: symbolic random variables
10+
911

1012
The :mod:`pytensor.tensor.random` module provides random-number drawing functionality
1113
that closely resembles the :mod:`numpy.random` module.
1214

13-
.. toctree::
14-
:maxdepth: 2
1515

16-
basic
17-
utils
16+
High-level API
17+
==============
18+
19+
PyTensor assigns NumPy RNG states (i.e. `Generator` objects) to
20+
each `RandomVariable`. The combination of an RNG state, a specific
21+
`RandomVariable` type (e.g. `NormalRV`), and a set of distribution parameters
22+
uniquely defines the `RandomVariable` instances in a graph.
23+
24+
This means that a "stream" of distinct RNG states is required in order to
25+
produce distinct random variables of the same kind. `RandomStream` provides a
26+
means of generating distinct random variables in a fully reproducible way.
27+
28+
`RandomStream` is also designed to produce simpler graphs and work with more
29+
sophisticated `Op`\s like `Scan`, which makes it a user-friendly random variable
30+
interface in PyTensor.
31+
32+
For an example of how to use random numbers, see :ref:`Using Random Numbers <using_random_numbers>`.
33+
34+
35+
.. class:: RandomStream()
36+
37+
This is a symbolic stand-in for `numpy.random.Generator`.
38+
39+
.. method:: updates()
40+
41+
:returns: a list of all the (state, new_state) update pairs for the
42+
random variables created by this object
43+
44+
This can be a convenient shortcut to enumerating all the random
45+
variables in a large graph in the ``update`` argument to
46+
`pytensor.function`.
47+
48+
.. method:: seed(meta_seed)
49+
50+
`meta_seed` will be used to seed a temporary random number generator,
51+
that will in turn generate seeds for all random variables
52+
created by this object (via `gen`).
53+
54+
:returns: None
55+
56+
.. method:: gen(op, *args, **kwargs)
57+
58+
Return the random variable from ``op(*args, **kwargs)``.
59+
60+
This function also adds the returned variable to an internal list so
61+
that it can be seeded later by a call to `seed`.
62+
63+
.. method:: uniform, normal, binomial, multinomial, random_integers, ...
64+
65+
See :ref: Available distributions `<_libdoc_tensor_random_distributions>`.
66+
67+
68+
.. testcode:: constructors
69+
70+
from pytensor.tensor.random.utils import RandomStream
71+
72+
rng = RandomStream()
73+
sample = rng.normal(0, 1, size=(2, 2))
74+
75+
fn = pytensor.function([], sample)
76+
print(fn(), fn()) # different numbers due to default updates
77+
78+
79+
Low-level objects
80+
=================
81+
82+
.. automodule:: pytensor.tensor.random.op
83+
:members: RandomVariable, default_rng
1884

85+
..automodule:: pytensor.tensor.random.type
86+
:members: RandomType, RandomGeneratorType, random_generator_type
1987

20-
.. automodule:: pytensor.tensor.random.basic
21-
:members:
88+
.. automodule:: pytensor.tensor.random.var
89+
:members: RandomGeneratorSharedVariable

doc/library/tensor/random/utils.rst

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)