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 Feb 22, 2023
1 parent b39b744 commit 7c49e9d
Show file tree
Hide file tree
Showing 2 changed files with 41 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
39 changes: 39 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import sphinx.addnodes
import sphinx.directives
from docutils import nodes
from docutils.frontend import OptionParser
from docutils.utils import new_document
from sphinx.parsers import RSTParser
from sphinx.util.docutils import SphinxDirective

import aeppl
Expand Down Expand Up @@ -110,5 +113,41 @@ 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
)

rst = ".. autosummary::\n"
rst += " :toctree: _generated\n\n"
for transform_name in invertible_transforms:
rst += f" aeppl.transforms.{transform_name}\n"

return self.parse_rst(rst)

def parse_rst(self, text: str):
parser = RSTParser()
parser.set_application(self.env.app)

settings = OptionParser(
defaults=self.env.settings,
components=(RSTParser,),
read_config_files=True,
).get_default_values()
document = new_document("<rst-doc>", settings=settings)
parser.parse(text, document)
return document.children

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

0 comments on commit 7c49e9d

Please sign in to comment.