I will use this function layer to definte a custom LossFunction in the net. How do I construct a NetGraph to implement this function?
$\begingroup$
$\endgroup$
1
The Documentation page for Accumulate
provides us with a hint, namely that:
Accumulate is equivalent to a particular case of FoldList:
In[1]:= FoldList[Plus, {a, b, c, d}] == Accumulate[{a, b, c, d}]
Out[1]= True
With this in mind, we turn to the new structural net operators, NetFoldOperator
, and in-fact the very first example is this particular case!
core =NetGraph[{Plus}, {{NetPort["Input"], NetPort["State"]} -> 1}];
fold = NetFoldOperator[core];
fold[Range[10]]
Out[30]= {1., 3., 6., 10., 15., 21., 28., 36., 45., 55.}