?? example6_2.m
字號(hào):
%定義存儲(chǔ)在網(wǎng)絡(luò)中的目標(biāo)平衡點(diǎn)
T = [+1 -1;-1 +1]';
plot(T(1,:),T(2,:),'r*');
axis([-1.1 1.1 -1.1 1.1]);
title('Hopfield神經(jīng)網(wǎng)絡(luò)狀態(tài)空間');
xlabel('a(1)');
ylabel('a(2)');
%建立網(wǎng)絡(luò),并得到權(quán)重和閾值
net=newhop(T);
W=net.LW{1,1}
b=net.b{1,1}
%使用原始平衡點(diǎn)仿真網(wǎng)絡(luò)
[Y,Pf,Af] = sim(net,2,[],T);
Y
%使用一個(gè)隨機(jī)點(diǎn)仿真網(wǎng)絡(luò),并繪出其到達(dá)穩(wěn)定點(diǎn)的軌跡
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神經(jīng)網(wǎng)絡(luò)狀態(tài)空間');
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,:));
%用多個(gè)隨機(jī)點(diǎn)仿真網(wǎng)絡(luò),并繪出相應(yīng)的軌跡
figure;
color = 'rgbmy';
axis([-1.1 1.1 -1.1 1.1]);
title('Hopfield神經(jīng)網(wǎng)絡(luò)狀態(tài)空間');
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;
%給網(wǎng)絡(luò)指定特殊初始權(quán)重進(jìn)行仿真,得到相應(yīng)的軌跡
figure;
plot(T(1,:),T(2,:),'r*');
axis([-1.1 1.1 -1.1 1.1]);
title('Hopfield神經(jīng)網(wǎng)絡(luò)狀態(tài)空間');
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
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -