How do I add layer to a custom NN while keeping the weights and biases of trained layer constant?

2 views (last 30 days)
Hi, I have trained a custom Neural Network with 3 inputs and 1 output to emulate my system.You can find the code for the emulator at the end. Now I want to add two layers to the network that get two of the inputs(F and Y) and give back the other input(U), in a way that the output of my Neural Network emulator is my desired output. But i want my emulator stay as it is and just the added layers are trained. Thank you in Advance
p1=tonndata(F,true,false); p2=tonndata(Y,true,false); p3=tonndata(U,true,false); t=tonndata(Y_dot,true,false);
net=network; net.numInputs = 3;
net.numLayers = 4;
net.biasConnect(1)=1; net.biasConnect(2)=1; net.biasConnect(3)=1; net.biasConnect(4)=1;
net.inputConnect(1,1)=1; net.inputConnect(2,2)=1; net.inputConnect(3,3)=1;
net.layerConnect(4,1)=1; net.layerConnect(4,2)=1; net.layerConnect(4,3)=1;
net.outputConnect(4)=1;
net.layers{1}.size=10; net.layers{1}.transferFcn='tansig'; net.layers{1}.initFcn='initnw';
net.layers{2}.size=5; net.layers{2}.transferFcn='tansig'; net.layers{2}.initFcn='initnw';
net.layers{3}.size=5; net.layers{3}.transferFcn='tansig'; net.layers{3}.initFcn='initnw';
net.layers{4}.size=3; net.layers{4}.transferFcn='purelin'; net.layers{4}.initFcn='initnw';
net.inputWeights{1,1}.delays=1:12; net.inputWeights{2,2}.delays=1:12; net.inputWeights{3,3}.delays=1:12;
net.initFcn= 'initlay';
net.performFcn='mse';
net.trainFcn='trainbr';
net.trainParam.show=1;
net.trainParam.goal=1e-8; net.trainParam.epochs=200; net.trainParam.show=1;
[net,tr]=train(net,[p1;p2;p3],t);

Answers (1)

Greg Heath
Greg Heath on 27 Aug 2018
What I have done is to store the signals that will be inputs to the addition.
Then I use that stored data set to train the addition.
Hope this helps.
Thank you for formally accepting my answer
Greg
  1 Comment
Mohammadmahdi Malakizandi
Mohammadmahdi Malakizandi on 28 Aug 2018
Thanks for the reply but I think I may have misrepresented what I wanted to do. The problem is I don't know what the inputs should be. So I don't have the signals. What I have is the output of the emulator. I want the output of the new NN be in the way that when I use it as the input of the emulator, the output of the emulator be what I want.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!