MATLAB: Is it possible to add softmax layer and use cross entropy with layrecnet

classificationMATLABneural networkrnn

I want to do classification using a RNN, but I am having difficulties adjusting the layrecnet to match a classification problem.
For classification, I would like to:
  • add a softmax layer before output
  • using cross-entropy for loss calculation
net = layrecnet(1:3, 10);
However, the trainlm does not support crossentropy, while transcg with crossentropy will result in error due to attempt of memory allocation of 30+ GB. My question is therefore:
How can I modify layrecnet to do classification instead of regression?

Best Answer

For c classes just use {0,1} c-dimensional unit vectors in the output.
The assigned class is obtained from the maximum value.
If you need a posterior probability estimate just use LOGSIG and divide the result by the sum.
Hope this helps.
Greg