⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example6_2.m

📁 BP神经网络基于MATLAB实际实现例子
💻 M
字号:
%定义存储在网络中的目标平衡点
T = [+1 -1;-1 +1]';
plot(T(1,:),T(2,:),'r*');
axis([-1.1 1.1 -1.1 1.1]);
title('Hopfield神经网络状态空间');
xlabel('a(1)');
ylabel('a(2)');
%建立网络,并得到权重和阈值
net=newhop(T);
W=net.LW{1,1}
b=net.b{1,1}
%使用原始平衡点仿真网络
[Y,Pf,Af] = sim(net,2,[],T);
Y
%使用一个随机点仿真网络,并绘出其到达稳定点的轨迹
a = {rands(2,1)};
[y,Pf,Af] = sim(net,{1 20},{},a);
figure;
plot(T(1,:),T(2,:),'r*');
axis([-1.1 1.1 -1.1 1.1]);
title('Hopfield神经网络状态空间');
xlabel('a(1)');
ylabel('a(2)');
record=[cell2mat(a) cell2mat(y)];
start=cell2mat(a);
hold on
plot(start(1,1),start(2,1),'bx',record(1,:),record(2,:));
%用多个随机点仿真网络,并绘出相应的轨迹
figure;
color = 'rgbmy';
axis([-1.1 1.1 -1.1 1.1]);
title('Hopfield神经网络状态空间');
xlabel('a(1)');
ylabel('a(2)');
hold on
for i=1:25
   a = {rands(2,1)};
   [y,Pf,Af] = sim(net,{1 20},{},a);
   record=[cell2mat(a) cell2mat(y)];
   start=cell2mat(a);
   plot(start(1,1),start(2,1),'kx',record(1,:),record(2,:),color(rem(i,5)+1));
   drawnow
end;
%给网络指定特殊初始权重进行仿真,得到相应的轨迹
figure;
plot(T(1,:),T(2,:),'r*');
axis([-1.1 1.1 -1.1 1.1]);
title('Hopfield神经网络状态空间');
xlabel('a(1)');
ylabel('a(2)');
hold on
plot(0,0,'ko');
P = [-1.0 -0.5 0.0 +0.5 +1.0;  -1.0 -0.5 0.0 +0.5 +1.0];
color = 'rgbmy';
for i=1:5
   a = {P(:,i)};
   [y,Pf,Af] = sim(net,{1 50},{},a);
   record=[cell2mat(a) cell2mat(y)];  
   start=cell2mat(a);
   plot(start(1,1),start(2,1),'kx',record(1,:),record(2,:),color(rem(i,5)+1))
   drawnow
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -