NetFoldOperator

NetFoldOperator[net]

represents a net in which net is folded over a sequence of inputs, maintaining a recurrent state.

NetFoldOperator[net,{"outi""in1",}]

represents a net in which net is folded over its inputs, maintaining a recurrent state by feeding the outi of each step back to the ini of the next step.

NetFoldOperator[net,feedback,{"const1","const2",}]

treats the inputs consti to net as being constant instead of mapped over.

NetFoldOperator[net,feedback,constants,{"out1",}]

returns the sequence of values for the specific outputs outi.

Details

  • NetFoldOperator[net] is equivalent to NetFoldOperator[net,{"Output"->"State"}] and specifies that the output called "Output" of the folded net will be fed back to the input called "State".
  • NetFoldOperator[] represents a net that takes one or more sequences and outputs one or more sequences of the same length.
  • NetFoldOperator[net,{"out1""in1",}] accepts the same inputs as net, except for those ini given by one of the feedback connections "outi"->"ini".
  • NetFoldOperator[net,feedback,constants] will map over any inputs that are not specified in feedback or constants. All mapped-over inputs should have the same length.
  • In the typical case in which net has two inputs named "Input" and "State" and one output named "Output", the single argument form NetFoldOperator[net] accepts a single input sequence {x1,x2,,xn} named "Input" and an initial state s0 named "State" and produces a sequence of states {s1,s2,,sn} named "Output", computed by applying the net repeatedly to xi and si-1 to compute si , effectively using net[<|"Input"->xi,"State"->si-1|>].
  • NetFoldOperator[net,{"out1""in1",}] will have state ports named for all the recurrent ports ini whose values are fed back.
  • When given a NumericArray as input, the output will be a NumericArray.
  • Within a NetGraph, a connection of the form src->NetPort[layer,"state"] can be used to provide the initial value of a recurrent state of a NetFoldOperator. Similarly, a connection of the form NetPort[layer,"state"]->dst can be used to obtain the final value of a recurrent state. If left unconnected, these states can be tracked by NetStateObject.
  • NetFoldOperator[net,] can be seen as allowing a form of weight sharing between multiple copies of net, one for each sequence element that is being mapped over.
  • NetFoldOperator[,"Input"->shape] allows the shape of the input to be specified. Possible forms for shape are:
  • NetEncoder[]encoder producing an array
    na vector of length n
    {n1,n2,}an array of dimensions n1×n2×
    "Varying"a vector whose length is variable
    {"Varying",n2,n3,}an array whose first dimension is variable and remaining dimensions are n2×n3×

Examples

open all close all

Basic Examples  (1)

Create a "core" net that takes a state and an input and produces an output:

In[1]:=
Click for copyable input
Out[1]=

Evaluate the core on an input:

In[2]:=
Click for copyable input
Out[2]=

Create a NetFoldOperator that uses the core to operate on sequences of arrays:

In[3]:=
Click for copyable input
Out[3]=

Evaluate the net on an input sequence of length-2 vectors:

In[4]:=
Click for copyable input
Out[4]=

Scope  (5)

Applications  (1)

Introduced in 2017
(11.1)
|
Updated in 2019
(12.0)