Skip to content

Commit

Permalink
Dynamically generate RVTransform list in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rlouf committed Jan 25, 2023
1 parent b39b744 commit 1e5e1c2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
27 changes: 2 additions & 25 deletions docs/source/api/transforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,37 +56,14 @@ associated variables and their values:

.. autoclass:: aeppl.transforms.TransformValuesRewrite


---------------------
Invertible transforms
---------------------

AePPL currently supports transforms using the following (invertible) Aesara operators. This means that AePPL can compute the log-probability of a random variable that is the result of one of the following transformations applied to another random variable:

- `aesara.tensor.add`
- `aesara.tensor.sub`
- `aesara.tensor.mul`
- `aesara.tensor.true_div`
- `aesara.tensor.exponential`
- `aesara.tensor.exp`
- `aesara.tensor.log`

One can also apply the following transforms directly:

.. autoclass:: aeppl.transforms.LocTransform
.. autoclass:: aeppl.transforms.ScaleTransform
.. autoclass:: aeppl.transforms.LogTransform
.. autoclass:: aeppl.transforms.ExpTransform
.. autoclass:: aeppl.transforms.ReciprocalTransform
.. autoclass:: aeppl.transforms.IntervalTransform
.. autoclass:: aeppl.transforms.LogOddsTransform
.. autoclass:: aeppl.transforms.SimplexTransform
.. autoclass:: aeppl.transforms.CircularTransform

These transformations can be chained using:


.. autoclass:: aeppl.transforms.ChainedTransform

.. print-invertible-transforms::

---------
Censoring
Expand Down
37 changes: 37 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,42 @@ def run(self):
return [res]


class InvertibleTransformationsDirective(SphinxDirective):
def run(self):
import inspect
import sys

import aeppl.transforms as transforms

invertible_transforms = (
mname
for mname, mtype in inspect.getmembers(sys.modules["aeppl.transforms"])
if inspect.isclass(mtype)
and issubclass(mtype, transforms.RVTransform)
and not mtype == transforms.RVTransform
)

res = nodes.bullet_list()
for transform_name in invertible_transforms:
attributes = {}
reftarget = f"aeppl.transforms.{transform_name}"
attributes["reftarget"] = reftarget
attributes["reftype"] = "class"
attributes["refdomain"] = "py"

ref = nodes.paragraph()

rawsource = rf":py:class:`{reftarget}`"
xref = sphinx.addnodes.pending_xref(rawsource, **attributes)
xref += nodes.literal(reftarget, reftarget, classes=["xref"])

ref += xref
item = nodes.list_item("", ref)
res += item

return [res]


def setup(app):
app.add_directive("print-supported-dists", SupportedDistributionsDirective)
app.add_directive("print-invertible-transforms", InvertibleTransformationsDirective)

0 comments on commit 1e5e1c2

Please sign in to comment.