-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb067f2
commit 27a58e2
Showing
4 changed files
with
113 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
Base distribution objects | ||
========================== | ||
========================== | ||
|
||
.. autoclass:: torchflows.base_distributions.gaussian.DiagonalGaussian | ||
:members: __init__ | ||
|
||
.. autoclass:: torchflows.base_distributions.gaussian.DenseGaussian | ||
:members: __init__ | ||
|
||
.. autoclass:: torchflows.base_distributions.mixture.DiagonalGaussianMixture | ||
:members: __init__ | ||
|
||
.. autoclass:: torchflows.base_distributions.mixture.DenseGaussianMixture | ||
:members: __init__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,51 @@ | ||
Choosing a base distribution | ||
============================== | ||
============================== | ||
|
||
We may replace the default standard Gaussian distribution with any torch distribution that is also a module. | ||
Some custom distributions are already implemented. | ||
We show an example for a diagonal Gaussian base distribution with mean 3 and standard deviation 2. | ||
|
||
.. code-block:: python | ||
import torch | ||
from torchflows.flows import Flow | ||
from torchflows.architectures import RealNVP | ||
from torchflows.base_distributions.gaussian import DiagonalGaussian | ||
torch.manual_seed(0) | ||
event_shape = (10,) | ||
base_distribution = DiagonalGaussian( | ||
loc=torch.full(size=event_shape, fill_value=3.0), | ||
scale=torch.full(size=event_shape, fill_value=2.0), | ||
) | ||
flow = Flow(RealNVP(event_shape), base_distribution=base_distribution) | ||
x_new = flow.sample((10,)) | ||
Nontrivial event shapes | ||
------------------------ | ||
|
||
When the event has more than one axis, the base distribution must deal with flattened data. We show an example below. | ||
|
||
.. note:: | ||
|
||
The requirement to work with flattened data may change in the future. | ||
|
||
|
||
.. code-block:: python | ||
import torch | ||
from torchflows.flows import Flow | ||
from torchflows.architectures import RealNVP | ||
from torchflows.base_distributions.gaussian import DiagonalGaussian | ||
torch.manual_seed(0) | ||
event_shape = (2, 3, 5) | ||
event_size = int(torch.prod(torch.as_tensor(event_shape))) | ||
base_distribution = DiagonalGaussian( | ||
loc=torch.full(size=(event_size,), fill_value=3.0), | ||
scale=torch.full(size=(event_size,), fill_value=2.0), | ||
) | ||
flow = Flow(RealNVP(event_shape), base_distribution=base_distribution) | ||
x_new = flow.sample((10,)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters