the Accumulate layer

I will use this function layer to definte a custom LossFunction in the net. How do I construct a NetGraph to implement this function?


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];
Out[30]= {1., 3., 6., 10., 15., 21., 28., 36., 45., 55.}
  • $\begingroup$ It works, many thanks! $\endgroup$ – cmc Jan 25 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.