Skip to contents

Using a list of formulas as input, dagnn generates an nn_module() neural network with a compact syntax

Usage

nndag(
  ...,
  .fns = list(torch::nn_linear),
  .args = list(),
  .act = list(torch::nn_relu)
)

Arguments

...

A list of formulas specifying a directed acyclic graph (DAG). See details for the correct syntax.

.fns

A list of functions for generating neural network layers. Named elements are mapped to layer names in the DAG, a single unnamed element can be included which acts as the default. [.] syntax is accepted for list names (see details).

.args

A list of named argument lists. Each element should be a named list with arguments to be passed to the corresponding .fns. In the upper level list, named elements are mapped to layer names in the DAG, and a single unnamed element can be included which acts as the default. [.] syntax is accepted for list names (see details).

.act

A list of functions for generating neural network activation for corresponding layers. Named elements are mapped to layer names in the DAG, a single unnamed element can be included which acts as the default. [.] syntax is accepted for list names (see details).

Value

A dagnn object, which subclasses a nn_module().

Examples

dag <- nndag(i_1 = ~ 19,
             c = ~ 1,
             p_1 = i_1 + c ~ 11,
            `e_[.]` = p_1 + c ~ c(32, 16, 8))
print(dag)
#> An `nn_module` containing 1,599 parameters.
#> 
#> ── Modules ─────────────────────────────────────────────────────────────────────
#> • layers: <nn_module_list> #1,599 parameters
#> • activations: <nn_module_list> #0 parameters
print(dag$layers)
#> An `nn_module` containing 1,599 parameters.
#> 
#> ── Modules ─────────────────────────────────────────────────────────────────────
#> • 0: <nn_linear> #231 parameters
#> • 1: <nn_linear> #416 parameters
#> • 2: <nn_linear> #720 parameters
#> • 3: <nn_linear> #232 parameters