?? example6_2.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 + -