How do I add layer to a custom NN while keeping the weights and biases of trained layer constant?
2 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
回答(1 个)
Greg Heath
2018-8-27
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
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!