scimba_torch.neural_nets.structure_preserving_nets.invertible_nn¶
An invertible neural network made of RealNVP layers.
Classes
|
An abstract class for an invertible layer. |
|
An invertible neural network made of RealNVP layers. |
|
Conservative volumes flow where the type of neural network is given by net. |
- class InvertibleLayer(in_size, out_size, **kwargs)[source]¶
Bases:
ScimbaModule,ABCAn abstract class for an invertible layer.
- class RealNVPFlowLayer(dim, p_dim, net_type=<class 'scimba_torch.neural_nets.coordinates_based_nets.mlp.GenericMLP'>, **kwargs)[source]¶
Bases:
InvertibleLayerConservative volumes flow where the type of neural network is given by net.
It is to approximate probability \(p(y\mid x)\).
Flow:
\[\begin{split}z[k:d] &= y[k:d] \exp^{s(y[1:k],x)} + t(y[1:k],x) \\ z[1:k] &= y[1:k]\end{split}\]with \(s\) the scale and \(t\) the shift/translation term.
- Parameters:
dim (
int) – the dimension of the input x of the flowp_dim (
int) – the dimension of the conditional input y of the flownet_type (
Module) – the type of neural network used**kwargs –
other arguments for the neural network:
parity: parity of the layerscale: to indicate whether we scale or notshift: to indicate whether we shift or not
- dim: int¶
dimension of the input x of the flow
- dim_p: int¶
dimension of the conditional input y of the flow
- net_type: nn.Module¶
type of neural network used
- parity: bool¶
parity of the layer
- scale: bool¶
scale the layer
- shift: bool¶
shift the layer
- forward(y, p, with_last_layer=True)[source]¶
Compute the flow.
- Parameters:
y (
Tensor) – the tensor of the data yp (
Tensor) – the tensor of the conditional data xwith_last_layer (
bool) – whether to use the last layer of the network or not (default: True)
- Return type:
Tensor- Returns:
the tensor containing the result
- backward(z, p, with_last_layer=True)[source]¶
Compute the backward flow.
- Parameters:
z (
Tensor) – the tensor of the data zp (
Tensor) – the tensor of the conditional data xwith_last_layer (
bool) – whether to use the last layer of the network or not (default: True)
- Return type:
Tensor- Returns:
the tensor containing the result
- class InvertibleNet(dim, p_dim, nb_layers=2, layer_type=<class 'scimba_torch.neural_nets.structure_preserving_nets.invertible_nn.RealNVPFlowLayer'>, net_type=<class 'scimba_torch.neural_nets.coordinates_based_nets.mlp.GenericMLP'>, **kwargs)[source]¶
Bases:
ScimbaModuleAn invertible neural network made of RealNVP layers.
- Parameters:
dim (
int) – dimension of the input datap_dim (
int) – dimension of the conditional input datanb_layers (
int) – number of invertible layerslayer_type (
InvertibleLayer) – type of invertible layer (default: RealNVPFlowLayer)net_type (
Module) – type of neural network used in each layer (default: GenericMLP)**kwargs – other arguments for the invertible layers.
- forward(inputs, with_last_layer=True)[source]¶
Applies the forward pass of the invertible network.
- Parameters:
inputs (
Tensor) – the input tensor of shape (batch_size, dim + p_dim).with_last_layer (
bool) – whether to use the last layer of the network or not (default: True)
- Return type:
Tensor- Returns:
The output tensor of shape (batch_size, dim + p_dim) after applying all layers.
- backward(inputs, with_last_layer=True)[source]¶
Applies the backward pass of the invertible network.
- Parameters:
inputs (
Tensor) – the input tensor of shape (batch_size, dim + p_dim).with_last_layer (
bool) – whether to use the last layer of the network or not (default: True)
- Return type:
Tensor- Returns:
- the output tensor of shape (batch_size, dim + p_dim) after applying
all layers in reverse order.