build_pytorch_net: Build a Pytorch Multilayer Perceptron

View source: R/helpers_pycox.R

build_pytorch_netR Documentation

Build a Pytorch Multilayer Perceptron

Description

Utility function to build an MLP with a choice of activation function and weight initialization with optional dropout and batch normalization.

Usage

build_pytorch_net(
  n_in,
  n_out,
  nodes = c(32, 32),
  activation = "relu",
  act_pars = list(),
  dropout = 0.1,
  bias = TRUE,
  batch_norm = TRUE,
  batch_pars = list(eps = 1e-05, momentum = 0.1, affine = TRUE),
  init = "uniform",
  init_pars = list()
)

Arguments

n_in

(integer(1))
Number of input features.

n_out

(integer(1))
Number of targets.

nodes

(numeric())
Hidden nodes in network, each element in vector represents number of hidden nodes in respective layer.

activation

(character(1)|list())
Activation function, can either be a single character and the same function is used in all layers, or a list of length length(nodes). See get_pycox_activation for options.

act_pars

(list())
Passed to get_pycox_activation.

dropout

(numeric())
Optional dropout layer, if NULL then no dropout layer added otherwise either a single numeric which will be added to all layers or a vector of differing drop-out amounts.

bias

(logical(1))
If TRUE (default) then a bias parameter is added to all linear layers.

batch_norm

(logical(1))
If TRUE (default) then batch normalisation is applied to all layers.

batch_pars

(list())
Parameters for batch normalisation, see reticulate::py_help(torch$nn$BatchNorm1d).

init

(character(1))
Weight initialization method. See get_pycox_init for options.

init_pars

(list())
Passed to get_pycox_init.

Details

This function is a helper for R users with less Python experience. Currently it is limited to simple MLPs. More advanced networks will require manual creation with reticulate.

Value

No return value.


survivalmodels documentation built on May 29, 2024, 7:26 a.m.