-
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.
Merge pull request #19 from davidnabergoj/dev
Dev
- Loading branch information
Showing
12 changed files
with
191 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Using CUDA | ||
=========== | ||
|
||
Torchflows models are torch modules and thus seamlessly support CUDA (and other devices). | ||
When using the *fit* method, training data is automatically transferred onto the flow device. | ||
|
||
.. code-block:: python | ||
import torch | ||
from torchflows.flows import Flow | ||
from torchflows.architectures import RealNVP | ||
torch.manual_seed(0) | ||
event_shape = (10,) | ||
x_train = torch.randn(size=(1000, *event_shape)) | ||
flow = Flow(RealNVP(event_shape)).cuda() | ||
flow.fit(x_train, show_progress=True) |
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,22 @@ | ||
Complex event shapes | ||
====================== | ||
Event shapes | ||
====================== | ||
|
||
Torchflows supports modeling tensors with arbitrary shapes. For example, we can model events with shape `(2, 3, 5)` as follows: | ||
|
||
.. code-block:: python | ||
import torch | ||
from torchflows.flows import Flow | ||
from torchflows.architectures import RealNVP | ||
torch.manual_seed(0) | ||
event_shape = (2, 3, 5) | ||
n_data = 1000 | ||
x_train = torch.randn(size=(n_data, *event_shape)) | ||
print(x_train.shape) # (1000, 2, 3, 5) | ||
flow = Flow(RealNVP(event_shape)) | ||
flow.fit(x_train, show_progress=True) | ||
x_new = flow.sample((500,)) | ||
print(x_new.shape) # (500, 2, 3, 5) |
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,22 @@ | ||
Image modeling | ||
============== | ||
============== | ||
|
||
When modeling images, we can use specialized multiscale architectures which use convolutional neural network conditioners and specialized coupling schemes. | ||
These architectures expect event shapes to be *(channels, height, width)*. | ||
|
||
.. note:: | ||
Multiscale architectures are currently undergoing improvements. | ||
|
||
.. code-block:: python | ||
import torch | ||
from torchflows.flows import Flow | ||
from torchflows.architectures import MultiscaleRealNVP | ||
image_shape = (3, 28, 28) | ||
n_images = 100 | ||
torch.manual_seed(0) | ||
training_images = torch.randn(size=(n_images, *image_shape)) # synthetic data | ||
flow = Flow(MultiscaleRealNVP(image_shape)) | ||
flow.fit(training_images, show_progress=True) |
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
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
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
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