Network with custom defined Regression Layer Output

1 view (last 30 days)
Hello everybody, I'm having problems creating a neural network.
Basically, my network has one input and one output; however I have no target, but the output will be fed into a library which approximates numerically a PDE and returns a vector such that I can interpret the loss function as the sum of the elements of this vector.
From my understanding of https://it.mathworks.com/help/deeplearning/ug/define-custom-regression-output-layer.html I am able to define an output layer with my specific loss function, defining in this template the following loss function:
function loss = forwardLoss(layer,Y)
% loss = forwardLoss(layer, Y) returns the loss function
% exploiting the predictions Y.
e = C_main2D('Test1',Y);
loss = sum(e);
end
The idea would be to have a vector of inputs in order to train the network by using the trainNetwork function, but the problem arises when I get to the definition of the Layer array.
I get that the regression layer I have defined should be the last element, but I don't understand how to properly define the layers in order to be able to pass the vector of inputs, a couple of hidden layers and then the regression output layer.
Thanks in advance for helping me.

Answers (1)

Srivardhan Gadila
Srivardhan Gadila on 30 Sep 2020
As per my knowledge and above information, I think using the custom training loop would be a good Idea. You can refer to Train Network Using Custom Training Loop & Deep Learning Custom Training Loops for more information.
  1 Comment
Andrea Malinverni
Andrea Malinverni on 4 Oct 2020
Thanks for answering, however I'm finding it hard to adapt the examples (which are almost uniquely related to images) to my case.
For what concerns the training loop, I've understood pretty much how I should work, my difficulties are with the definition of the network
By reading https://it.mathworks.com/help/deeplearning/ug/list-of-deep-learning-layers.html I realised the only input layer that fits my needs should be featureInputLayer with 1 feature, but I don't get how to combine the other layers before my output layer, mainly because of how many groups of layers there are.
My idea would be a fairly trivial network: input, two hidden layers and output; could you help me with that?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!