?? createnet.m
字號:
%======================================================
% 我的神經網絡控制器
% See also: myneuro4.mdl
% Lions Wang BJUT IAIR tutor: Ruan Xiaogang.
% $Revision: 1.00 $
% 好現在開始
%======================================================
%計算設計網絡的時間
timer1=clock;
net=network;
%==========================================================================
%%定義網絡然后開始初始化
%==========================================================================
% Update the pendulum animation.
% net =
% Neural Network object:
% architecture:
% numInputs: 6
net.numInputs=6;
% numLayers: 3
net.numLayers=3;
% biasConnect: [0; 0; 0]
net.biasConnect=[0; 0; 0];
% inputConnect: [3x6 boolean]
net.inputConnect=[1 1 1 1 1 1;0 0 0 0 0 0; 0 0 0 0 0 0];
% layerConnect: [0 0 0; 0 0 0; 0 0 0]
net.layerConnect=[0 0 0;1 0 0;0 1 0];
% outputConnect: [0 0 0]
net.outputConnect=[0 0 1];
% targetConnect: [0 0 0]
net.targetConnect=[0 0 1];
% net.targets = [1x1 struct] [] []
% net.outputs= [] [] [1x1 struct]
% net.biases
% []
% []
% []
% numOutputs: 0 (read-only)
% numTargets: 0 (read-only)
% numInputDelays: 0 (read-only)
% numLayerDelays: 0 (read-only)
%
% subobject structures:
%
% inputs: {6x1 cell} of inputs
%sdandard input
net.inputs{1}.range=[-7 7];
net.inputs{2}.range=[-0.5 0.5];
net.inputs{3}.range=[-0.05 0.05];
net.inputs{4}.range=[-5 5];
net.inputs{5}.range=[-5 5];
net.inputs{6}.range=[-0.5 0.5];
% > net.layers{1}
% dimensions: 1
% distanceFcn: ''
% distances: []
% initFcn: 'initwb'
% netInputFcn: 'netsum'
% positions: 0
% size: 1
% topologyFcn: 'hextop'
% transferFcn: 'purelin'
% userdata: [1x1 struct]
%
net.layers{1}.size=6;
net.layers{1}.initFcn='initnw';
net.layers{1}.transferFcn='tansig';
% >> net.layers{2}
% dimensions: 1
% distanceFcn: ''
% distances: []
% initFcn: 'initwb'
% netInputFcn: 'netsum'
% positions: 0
% size: 1
% topologyFcn: 'hextop'
% transferFcn: 'purelin'
% userdata: [1x1 struct]
%
net.layers{2}.size=10;
net.layers{2}.initFcn='initnw';
net.layers{2}.transferFcn='logsig';
% >> net.layers{3}
% dimensions: 1
% distanceFcn: ''
% distances: []
% initFcn: 'initwb'
% netInputFcn: 'netsum'
% positions: 0
% size: 1
% transferFcn: 'hextop'
% transferFcn: 'purelin'
% userdata: [1x1 struct]
% layers: {3x1 cell} of layers
% outputs: {1x3 cell} containing no outputs
% targets: {1x3 cell} containing no targets
% biases: {3x1 cell} containing no biases
% inputWeights: {3x6 cell} containing no input weights
% layerWeights: {3x3 cell} containing no layer weights
%
% functions:
%
% adaptFcn: (none)
% initFcn: (none)
% performFcn: (none)
% trainFcn: (none)
%
% parameters:
%
% adaptParam: (none)
% initParam: (none)
% performParam: (none)
% trainParam: (none)
%net.inputWeights{2,1}.delays=[0 0.005];
net.initFcn='initlay';
net.performFcn='mse';
net.trainFcn='trainlm';
%==========================================================================
%%初步完成初始化神經網絡的參數如下
%==========================================================================
% net =
%
% Neural Network object:
%
% architecture:
%
% numInputs: 6
% numLayers: 3
% biasConnect: [0; 0; 0]
% inputConnect: [3x6 boolean]
% layerConnect: [0 0 0; 1 0 0; 0 1 0]
% outputConnect: [0 0 1]
% targetConnect: [1 0 0]
%
% numOutputs: 1 (read-only)
% numTargets: 1 (read-only)
% numInputDelays: 0 (read-only)
% numLayerDelays: 0 (read-only)
%
% subobject structures:
%
% inputs: {6x1 cell} of inputs
% layers: {3x1 cell} of layers
% outputs: {1x3 cell} containing 1 output
% targets: {1x3 cell} containing 1 target
% biases: {3x1 cell} containing no biases
% inputWeights: {3x6 cell} containing 6 input weights
% layerWeights: {3x3 cell} containing 2 layer weights
%
% functions:
%
% adaptFcn: (none)
% initFcn: 'initlay'
% performFcn: 'mse'
% trainFcn: 'trainlm'
%
% parameters:
%
% adaptParam: (none)
% initParam: (none)
% performParam: (none)
% trainParam: .epochs, .goal, .max_fail, .mem_reduc,
% .min_grad, .mu, .mu_dec, .mu_inc,
% .mu_max, .show, .time
%
% weight and bias values:
%
% IW: {3x6 cell} containing 6 input weight matrices
% LW: {3x3 cell} containing 2 layer weight matrices
% b: {3x1 cell} containing no bias vectors
%
% other:
%==========================================================================
%%對網絡進行閾值,權值初始化
%==========================================================================
net=init(net);
% userdata: (user stuff)
% weight and bias values:
%
% IW: {3x6 cell} containing no input weight matrices
% LW: {3x3 cell} containing no layer weight matrices
% b: {3x1 cell} containing no bias vectors
%
% other:
% %
% net.layerWeights= [] [] []
% [1x1 struct] [] []
% [] [1x1 struct] []
% >> net.layerWeights{2,1}= delays: 0
% initFcn: ''
% learn: 1
% learnFcn: ''
% learnParam: ''
% size: [6 6]
% userdata: [1x1 struct]
% weightFcn: 'dotprod'
%======================================================
%建成后先小訓一下
%======================================================
for i=1:1:4
for j=1:1:4
for k=1:1:4
for l=1:1:4
for m=1:1:4
for n=1:1:4
coun=j*4^4+k*4^3+l*4^2+m*4+n;
% coun=i*7^5+j*7^4+k*7^3+l*7^2+m*7+n;
p(1,coun)=1*(i-2)/4;
p(2,coun)=0.4*(j-2)/4;
p(3,coun)=0.04*(k-2)/4;
p(4,coun)=4*(l-2)/4;
p(5,coun)=4*(m-2)/4;
p(6,coun)=0.4*(n-2)/4;
t(coun)=p(1,coun)*1.00+p(2,coun)*(-231.110)+p(3,coun)*(326.3442)+p(4,coun)*0.9843+p(5,coun)*(-5.5640)+p(6,coun)*52.3631;
end
end
end
end
end
net=train(net,p,t);
end
%計算設計網絡的時間
datat=etime(clock,timer1)
save net;
%測試一下
p=[0 0.1 0 0 0 0 ]';
output=sim(net,p)
goal=p(1)*1.0000+p(2)*(-231.1100)+p(3)*(326.3442)+p(4)*0.9843+p(5)*(-5.5640)+p(5)*52.3631
% 程序結束,byebye!
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -