Weights are not updated after training
2 次查看(过去 30 天)
显示 更早的评论
I am designing this network , 7 inputs , 3 outputs , the input data are imported from a simulink file , and the weights are exported to the same simulink model after the training , the training is done , unfortunately weights are not updated
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/191668/image.png)
net = network; net.name = 'Test'; net.numInputs = 7; net.numLayers = 6; net.biasConnect = ones(net.numLayers,1);
numHidden = 3 ; % Number of the Hidden Layers
%Connecting the inputs with the hidden layer for i=1:net.numInputs net.inputs{i}.size =1; for j=1:numHidden net.inputConnect(j,i) = 1; end end
%Connection 1,2,3 Hidden neuron to output 1,2,3 neuron net.layerConnect(4,1)=1; net.layerConnect(5,2)=1; net.layerConnect(6,3)=1;
%Configuration of the Hidden Layers for i=1:numHidden net.layers{i}.size = 1; net.layers{i}.transferFcn = 'logsig'; net.layers{i}.initFcn = 'initwb'; end
%%Kp,Ki, Kd Hidden Layer name net.layers{1}.name = 'Hidden Layer Kp'; net.layers{2}.name = 'Hidden Layer Ki'; net.layers{3}.name = 'Hidden Layer Kd';
%Configuration of the Output Layers for i=numHidden+1:net.numLayers net.layers{i}.size = 1; net.layers{i}.transferFcn = 'logsig'; net.layers{i}.initFcn = 'initwb'; end
%Kp,Ki, Kd Output Layer name net.layers{4}.name = 'Output Kp'; net.layers{5}.name = 'Output Ki'; net.layers{6}.name = 'Output Kd';
%Connecting the Hidden with the Outputs for i=numHidden+1:net.numLayers net.outputConnect(i) = 1; end
%Kp,Ki, Kd Outputs name net.outputs{4}.name = 'Kp'; net.outputs{5}.name = 'Ki'; net.outputs{6}.name = 'Kd';
%Wheight Initialization for i=1:net.numLayers %Input Weights for j=1:net.numInputs net.inputWeights{i,j}.initFcn = 'rands'; end end
for i=1:net.numLayers %Layers Weights for j=1:net.numLayers net.layerWeights{i,j}.initFcn = 'rands'; end end
for i=1:net.numLayers %bias Weights net.biases{i}.initFcn = 'rands'; end
%Network and Training Configuration net.divideFcn = 'dividetrain'; net.initFcn = 'initlay'; net=init(net); % net.trainFcn = 'traingd'; % net.trainParam.epochs=100000; % net.trainParam.lr=0.000001; % net.trainParam.goal=1e-6; % net.trainParam.min_grad=0.004;
net.performFcn='mse'; net.performParam.ratio=0.00005; Input_Weights = net.IW; Layer_Weights = net.LW; Bias_Weights = net.b;
%% Train Network % clc % net.adaptFcn = 'adaptwb'; % net.adaptParam = for i=1:100 simout=sim('ModelName');
p = [un,un1,yn,y1,cn,cn1,en];
p = p';
y=[Kp,Ki,Kd];
y=y';
pS(:,i) = p(:,2);
yS(:,i) = y(:,2);
wS(i)=net.IW{1,1};
% net =train(net,p,y);
[net,y,E] = adapt(net,p,y);
net.adaptFcn
net.adaptParam='learnpn';
end
0 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!