WLganzhiqi.m(有错,待改正)
P=[-0.5 -0.6 0.7;0.8 0 0.1];
T=[1 1 0];
net=newp([-1 1;-1 1],1);
%newp的调用格式为:net=newp(PT,1,'hardlims','learnpn') PT是一个R*2维的矩阵
handle=plotpc(net.iw{1},net.b{1});
%返回画线的句柄,下一次绘制分类线时将旧的删除
net.trainParam.epochs=10;
%设置训练次数最大为10次
net=train(net,P,T);
Q=[0.6 0.9 -0.1;-0.1 -0.5 0.5];
Y=sim(net,Q);
plot(P(1,:),P(2,:),'*b');hold on
plotpv(Q,Y);
handle=plotpc(net.iw{1},net.b{1},handle);
WANGLUO_som.m
P=[0.270 0.142 6.46 5.5 35.8 21 1.03;
0.171 0.115 3.46 6.3 33.0 60 0.78;
0.114 0.101 2.43 6.4 26.5 25 1.13;
0.173 0.123 3.30 5.8 28.9 65 1.09;
0.145 0.131 3.28 6.0 28.5 25 1.03;
0.173 0.140 3.45 5.8 33.4 60 0.98;
0.250 0.177 5.51 7.2 42.5 45 0.93;
0.237 0.189 5.37 6.1 32.9 27 1.00;
0.319 0.227 7.04 5.8 35.9 24 1.03;
0.163 0.124 3.73 6.2 30.6 61 1.28]';
net=newsom(minmax(P),[6 4]);
a=[10 100 1000];
yc=ones(3,10);
for i=1:3
yc(i,:)=rands(1,10);
net.trainParam.epochs=a(i);
net=train(net,P);
y=sim(net,P);
yc(i,:)=vec2ind(y);
end
WANGLUO_BPguzhang.m(有错 待改正)
P=[]
%被分类的对象数据
T=[ ]';
%描述分类结果
rang=[0 1;..;0 1];
%描述输入向量的最大值和最小值
net=newff(rang,[ , ],{'tansig','logsig'},'trainlm');
%tansig输出范围是[-1 1] logsig输出范围是[0 1]
%在三层网络中,隐含层神经元个数n2和输入层神经元个数n1关系约为 n2=2*n1+1
%net=newff(PR,[S1 S2...SNl],{TF1 TF2...TFNl},BTF,BLF,PF) takes,
%PR -- R x 2 matrix of min and max values for R input elements
%Si -- Size of ith layer, for Nl layers
%TFi -- Transfer function of ith layer, default = 'tansig'
%TF -- Backpropagation network training function, default = 'traingdx'
%BLF -- Backpropagation weight/bias learning function, default = 'learngdm'
%PF -- Performance function, default = 'mse'
net.trainParam.epochs=1000;
net.trainParam.goal=0.01;
LP.lr=0.1;
net=train(net,P,T);
P_test=[]';
Y=sim(net,P_test)
WANGLUO_BP_shujunihehanshu.m
P=-1:0.1:1;
for i=1:21
T(i)=sin(P(i).*pi);
end
s=3:8;
res=1:6;
for i=1:6
net=newff(minmax(P),[s(i),1],{'tansig','tansig'},'traingdx');
net.trainParam.epochs=2000;
net.trainParam.goals=0.001;
net=train(net,P,T);
y=sim(net,P);
error=y-T;
res(i)=norm(error);
end
plot(P,T,'o');hold on
yend=sim(net,P);
plot(P,yend,'r*')