概述:
1 人工神经网络介绍
2 人工神经元
3 MATLAB神经网络工具箱
4 感知器神经网络
5 感知器神经网络
5.1 设计实例分析
clear all;
close all;
P=[ ; ];
T=[ ];
%建立神经网络
net=newp(minmax(P),,'hardlim','learnp');
%对神经网络进行训练,net是建立网络,P是输入向量,T是目标向量
net=train(net,P,T);
%对网络进行仿真
Y=sim(net,P);
%绘制建模点
plotpv(P,T);
%绘制分界线
plotpc(net.iw{,},net.b{});
clear all;
close all;
P=[-0.5 -0.5 0.4 -0.1 -0.8;-0.5 0.5 -0.3 0.2 0.9];
T=[ ];
plotpv(P,T);
%建立感知器网络
net=newp(minmax(P),,'hardlim','learnpn');
hold on;
linehandle=plot(net.IW{},net.b{});
E=;
net.adaptParam.passes=;
%误差没有达到要求会持续不断的训练
while mae(E)
%进行感知器网络的训练
[net,Y,E]=adapt(net,P,T);
linehandle=plotpc(net.IW{},net.b{},linehandle);
drawnow;
end
%对训练好的网络进行保存,保存成net1
save net1 net;
set(gcf,'position',[,,,]);
clear all;
close all;
%加载网络
load net1.mat;
X=[-0.4 0.2 0.8;-0.7 0.3 0.9];
%对网络进行仿真,输入向量为X
Y=sim(net,X);
figure;
%绘制样本点和分界线
plotpv(X,Y);
plotpc(net.IW{},net.b{});
set(gcf,'position',[,,,]);
5.2 线性神经网络
clear all;
close all;
P=[1.0 2.1 ];
T=[2.0 4.01 5.9 8.0];
%获取最大的学习速率
lr=maxlinlr(P);
net=newlin(minmax(P),,,lr);
%最大学习次数是300
net.trainParam.epochs=;
%训练的目标误差为0.
net.trainParam.goal=0.05;
net=train(net,P,T);
Y=sim(net,P)
6 设计实例分析
clear all;
close all;
t=:pi/:*pi;
X=t.*sin(t);
T=*X+;
figure;
plot(t,X,'+-',t,T,'+--');
legend('系统输入','系统输出');
set(gca,'xlim',[ *pi]);
set(gcf,'position',[,,,]);
net=newlind(X,T);
%对网络进行仿真
y=sim(net,X);
figure;
plot(t,y,'+:',t,y-T,'r:');
legend('网络预测输出','误差');
set(gca,'xlim',[ *pi]);
set(gcf,'position',[,,,]);
7 BP网络
7.1 BP网络的创建
7.2 BP网络实例分析
clear all;
clear all;
P=[ ];
T=[ ];
%隐含层为10个神经元
net=newff(P,T,);
net.trainParam.epochs=;
%进行训练
net=train(net,P,T);
%对网络进行仿真
Y=sim(net,P);
figure;
plot(P,T,P,Y,'o');
- BP神经网络进行曲线拟合
clear all;
clear all;
P=-:0.05:;
T=sin(*pi*P)+0.1*randn(size(P));
net=newff(P,T,,{},'trainbr');
net.trainParam.show=;
net.trainParam.epochs=;
net=train(net,P,T);
Y=sim(net,P);
figure;
plot(P,T,'-',P,Y,'+');
legend('原始信号','网络输出信号');
set(gcf,'position',[,,,]);
8 径向基审计网络
clear all;
close all;
P=[ ];
T=[2.1 3.4 5.4 6.9 5.6];
net=newrb(P,T);
x=:0.5:
y=sim(net,x)
9 广义回归神经网络
clear all;
close all;
%输入向量
P=:;
%输出向量
T=*sin(P);
net=newgrnn(P,T,0.2);
y=sim(net,P);
figure;
plot(P,T,':+',P,T-y,'-o');
10 概率神经网络
clear all;
close all;
P=[:];
Tc=[ ];
T=ind2vec(Tc)
net=newpnn(P,T);
Y=sim(net,P);
Yc=vec2ind(Y)