real_nvp module¶
Implementation of realNVP: a coupling cell with an affine transform
- class ElementWiseAffineTransform(*args, **kwargs)[source]¶
Bases:
zunis.models.flows.coupling_cells.transforms.InvertibleTransform
Invertible element-wise affine transform
Constructor for InvertibleTransform
No arguments, no returns, this is just encapsulation for a function and its inverse
- class FakeRealNVP(*args, **kwargs)[source]¶
Bases:
zunis.models.flows.coupling_cells.real_nvp.GeneralRealNVP
Fake real NVP with position independent affine parameters for basic debugging and training tests
- Parameters
d (int) – dimension of the space
transform (
InvertibleTransform
) – bijective variable transform that maps the unit hypercube (ind-sum(mask)
dimensions) to itself given some parameters.mask (list of bool) – indicates which variables are passed (y_N) through and which are transformed (y_M)
- class FakeT(s=0.0, t=0.0)[source]¶
Bases:
torch.nn.modules.module.Module
Fake neural net for the test FakeRealNVP that returns a trainable constant
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- class GeneralRealNVP(*args, **kwargs)[source]¶
Bases:
zunis.models.flows.coupling_cells.general_coupling.InvertibleCouplingCell
Coupling cell based on affine transforms without a specific parameter prediction function
- Parameters
d (int) – dimension of the space
transform (
InvertibleTransform
) – bijective variable transform that maps the unit hypercube (ind-sum(mask)
dimensions) to itself given some parameters.mask (list of bool) – indicates which variables are passed (y_N) through and which are transformed (y_M)
- class RealNVP(*args, **kwargs)[source]¶
Bases:
zunis.models.flows.coupling_cells.real_nvp.GeneralRealNVP
Real non-volume-preserving coupling cell.
This implements a bijective mapping R^d -> R^d by transforming some subset of the coordinates defined by the mask through a coordinate-wise affine transformation. As with other coupling cells the parameters of the affine transformation are the output of a neural network taking the un-tranformed coordinates as input.
- Parameters
d (int) – dimension of the space
mask (list of bool) – mask defining which variables are transformed
d_hidden (int, 256) – width of the neural network
n_hidden (int, 8) – depth of the neural network
input_activation – activation function applied before going through the neural network
hidden_activation – activation function applied after each hidden layer of the neural network
output_activation – activation function applied after the last layer of the neural network
use_batch_norm (bool) – whether to use batch normalization after each hidden layer of the neural network
- element_wise_affine(x, st, compute_jacobian=True)[source]¶
Transform x element-wise through an affine function y = exp(s)*x + t where s = st[…,0] and t = st[…,1] with s.shape == x.shape == t.shape
The Jacobian for this transformation is the coordinate-wise product of the scaling factors J = prod(es[…,i],i)
- inverse_element_wise_affine(x, st, compute_jacobian=True)[source]¶
Transform x element-wise through an affine function y = exp(-s)*(x - t) where s = st[…,0] and t = st[…,1] with s.shape == x.shape == t.shape This is the inverse of
element_wise_affine
above for the same set of parameters stThe Jacobian for this transformation is the coordinate-wise product of the scaling factors J = prod(es[…,i],i)