Skip to content
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

Clarify behaviour of the Transformed distribution in the docstring. #109

Merged
merged 1 commit into from
Feb 25, 2022
Merged
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
12 changes: 12 additions & 0 deletions distrax/_src/distributions/transformed.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ class Transformed(dist_base.Distribution):
where `p(x)` is the probability density of `X` (the "base density") and
`J(f)(x)` is the Jacobian matrix of `f`, both evaluated at `x = f^{-1}(y)`.

Sampling from a Transformed distribution involves two steps: sampling from the
base distribution `x ~ p(x)` and then evaluating `y = f(x)`. The first step
is agnostic to the possible batch dimensions of the bijector `f(x)`. For
example:
```
dist = distrax.Normal(loc=0., scale=1.)
bij = distrax.ScalarAffine(shift=jnp.asarray([3., 3., 3.]))
transformed_dist = distrax.Transformed(distribution=dist, bijector=bij)
samples = transformed_dist.sample(seed=0, sample_shape=())
print(samples) # [2.7941577, 2.7941577, 2.7941577]
```

Note: the `batch_shape`, `event_shape`, and `dtype` properties of the
transformed distribution, as well as the `kl_divergence` method, are computed
on-demand via JAX tracing when requested. This assumes that the `forward`
Expand Down