Learn R Programming

LBBNN (version 0.1.2)

LBBNN_Conv2d: Class to generate an LBBNN convolutional layer.

Description

It supports:

  • Prior inclusion probabilities for weights and biases in each layer.

  • Standard deviation priors for weights and biases in each layer.

  • Optional normalizing flows (RNVP) for a more flexible variational posterior.

  • Forward pass using either the full model or the Median Probability Model (MPM).

  • Computation of the KL-divergence.

Usage

LBBNN_Conv2d(
  in_channels,
  out_channels,
  kernel_size,
  prior_inclusion,
  standard_prior,
  density_init,
  flow = FALSE,
  num_transforms = 2,
  hidden_dims = c(200, 200),
  device = "cpu"
)

Value

A torch::nn_module object representing a convolutional LBBNN layer. The module has the following methods:

  • forward(input, MPM = FALSE): Computes activation (using the LRT at training time) of a batch of inputs.

  • kl_div(): Computes the KL-divergence.

  • sample_z(): Samples from the flow if flow = TRUE, in addition returns the log-determinant of the Jacobian of the transformation.

Arguments

in_channels

integer, number of input channels.

out_channels

integer, number of output channels.

kernel_size

size of the convolving kernel.

prior_inclusion

numeric scalar, prior inclusion probability for each weight and bias in the layer.

standard_prior

numeric scalar, prior standard deviation for weights and biases in each layer.

density_init

A numeric of size 2, used to initialize the inclusion parameters, one for each layer.

flow

logical, whether to use normalizing flows

num_transforms

integer, number of transformations for flow. Default is 2.

hidden_dims

numeric vector, dimension of the hidden layer(s) in the neural networks of the RNVP transform.

device

The device to be used. Default is CPU.

Examples

Run this code
# \donttest{
layer <- LBBNN_Conv2d(in_channels = 1,out_channels = 32,kernel_size = c(3,3),
prior_inclusion = 0.2,standard_prior = 1,density_init = c(-10,10),device = 'cpu')
x <-torch::torch_randn(100,1,28,28)
out <-layer(x)
print(dim(out))
# }

Run the code above in your browser using DataLab