P=[1,1,1;
1,2,3;
4,5,6;
7,8,9;
2,3,4;
3,5,7;
1,3,5;
2,4,6;
1,2,5;
1,4,7;
1,3,8;
1,4,9;
2,5,9
2,6,0;
4,6,9]’;
T=[3,6,15,24,9,15,9,12,8,12,12,14,17,8,19]; % T 为目标矢量
[PP,ps]=mapminmax(P,-1,1);
[TT,ps]=mapminmax(T,-1,1);
net=newff(minmax(PP),[2,1],{‘tansig’,‘purelin’},‘traingdm’)
inputWeights=net.IW{1,1}
%当前输入层权值和阈值
inputbias=net.b{1}
% 当前网络层权值和阈值
layerWeights=net.LW{2,1}
layerbias=net.b{2}
% 设置网络的训练参数
net.trainParam.show = 2;
net.trainParam.lr = 0.05;
net.trainParam.mc = 0.9;
net.trainParam.epochs =10000;
net.trainParam.goal = 1e-3;
% 调用 TRAINGDM 算法训练 BP 网络 (在构建net中有说明)
[net,tr]=train(net,PP,TT);
A = sim(net,PP) % 对 BP 网络进行仿真,
A=mapminmax(‘reverse’,A,ps) % 对A矩阵进行反归一化处理() % 计算仿真误差
E = T - A
MSE=mse(E)
inputWeights=net.IW{1,1}
%当前输入层权值和阈值
inputbias=net.b{1}
% 当前网络层权值和阈值
layerWeights=net.LW{2,1}
layerbias=net.b{2}
echo off
inputWeights =
1.0978 -1.3011 0.4617
1.0148 1.0337 -1.0064
inputbias =
-1.7639
1.7639
layerWeights =
-0.4430 0.0938
layerbias =
0.9150
A =
Columns 1 through 10
-0.9860 -0.7212 0.1437 0.9805 -0.3974 0.1329 -0.4424 -0.1482 -0.5587 -0.1733
Columns 11 through 15
-0.1056 0.0850 0.2641 -0.5102 0.5802
A =
Columns 1 through 10
3.1469 5.9272 15.0089 23.7948 9.3270 14.8951 8.8545 11.9435 7.6333 11.6801
Columns 11 through 15
12.3909 14.3925 16.2735 8.1433 19.5919
E =
Columns 1 through 10
-0.1469 0.0728 -0.0089 0.2052 -0.3270 0.1049 0.1455 0.0565 0.3667 0.3199
Columns 11 through 15
-0.3909 -0.3925 0.7265 -0.1433 -0.5919
MSE =
0.1102
inputWeights =
0.4501 -0.0385 0.6441
0.6781 1.3654 0.2104
inputbias =
-0.5015
1.9179
layerWeights =
1.0497 0.3944
layerbias =
0.0575