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

📄 hopfield.m

📁 多种人工神经网络:MATLAB源程序用于训练测试
💻 M
字号:
%指定存储在网络中的目标平衡点
T = [+1 +1;-1 +1; -1 -1]
axis([-1 1 -1 1 -1 1])';
set(gca,'box','on');
axis manual;
hold on;
plot3(T(1,:),T(2,:),T(3,:),'r*');
title('Hopfield神经网络状态空间');
xlabel('a(1)');
ylabel('a(2)');
zlabel('a(3)');
view([37.5 30]);

%建立网络,并得到权重和阈值
net=newhop(T);
W=net.LW{1,1}
b=net.b{1,1}

%使用一个随机点仿真网络,并绘出其到达稳定点的轨迹
a = {rands(3,1)};
[y,Pf,Af] = sim(net,{1 10},{},a);
figure;
axis([-1 1 -1 1 -1 1])';
set(gca,'box','on');
axis manual;
hold on;
plot3(T(1,:),T(2,:),T(3,:),'r*');
record=[cell2mat(a) cell2mat(y)];
start=cell2mat(a);
plot3(start(1,1),start(2,1),start(3,1),'bx',record(1,:),record(2,:),record(3,:));
view([37.5 30]);
title('Hopfield神经网络状态空间');
xlabel('a(1)');
ylabel('a(2)');
zlabel('a(3)');

%用多个随机点仿真网络,并绘出相应的轨迹
figure;
axis([-1 1 -1 1 -1 1])';
set(gca,'box','on');
axis manual;
hold on;
view([37.5 30]);
plot3(T(1,:),T(2,:),T(3,:),'r*');
color = 'rgbmy';
for i=1:25
    a = {rands(3,1)};
    [y,Pf,Af] = sim(net,{1 10},{},a);
    record=[cell2mat(a) cell2mat(y)];
    start=cell2mat(a);
    plot3(start(1,1),start(2,1),start(3,1),'kx',record(1,:),record(2,:),record(3,:),color(rem(i,5)+1))
    drawnow
end
title('Hopfield神经网络状态空间');
xlabel('a(1)');
ylabel('a(2)');
zlabel('a(3)');

%指定一些特殊的初始点进行仿真,并绘出相应的轨迹
figure;
axis([-1 1 -1 1 -1 1])';
set(gca,'box','on');
axis manual;
hold on;
P = [ 1.0  -1.0  -0.5  1.00  1.00  0.0; 0.0   0.0   0.0 
 0.00  0.00 -0.0;-1.0   1.0   0.5 -1.01 -1.00  0.0];
view([37.5 30]);
color ='rgbmy';
for i=1:6
    a = {P(:,i)}; 
    [y,Pf,Af] = sim(net,{1 10},{},a);
    record=[cell2mat(a) cell2mat(y)];
    start=cell2mat(a);
    plot3(start(1,1),start(2,1),start(3,1),'kx',record(1,:),record(2,:),record(3,:),color(rem(i,5)+1))
    drawnow
end
title('Hopfield神经网络状态空间');
xlabel('a(1)');
ylabel('a(2)');
zlabel('a(3)');

⌨️ 快捷键说明

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