Learn R Programming

LBBNN (version 0.1.2)

FLOW: Class to generate a normalizing flow

Description

Used inLBBNN_Net when the argument flow = TRUE. Contains a torch::nn_module where the initial vector gets transformed through all the layers in the module. Also computes the log-determinant of the Jacobian for the entire transformation, which is just the sum of log-determinant of the independent layers.

Usage

FLOW(input_dim, transform_type, num_transforms)

Value

A torch::nn_module object representing the normalizing flow. The module provides:

forward(z)

Applies all flow transformation layers to the input tensor z. Returns a named list containing:

z

A torch_tensor containing the transformed version of the input, with the same shape as z.

logdet

A scalar torch_tensor equal to the sum of the log-determinants of all transformation layers.

Arguments

input_dim

numeric vector, the dimensionality of each layer. The first item is the input vector size.

transform_type

Type of transformation. Currently only RNVP is implemented.

num_transforms

integer, how many layers of transformations to include in the flow.

Examples

Run this code
# \donttest{
flow <- FLOW(c(200,100,100),transform_type = 'RNVP',num_transforms = 3)
flow$to(device = 'cpu')
x <- torch::torch_rand(200,device = 'cpu')
output <- flow(x)
z_out <- output$z
print(dim(z_out))
log_det <- output$logdet
print(log_det)
# }

Run the code above in your browser using DataLab