📄 ex_9_8.m
字号:
%The script, HOPFIELD_ANALYSIS, is to aid with an analysis of a 2D neural net.
% The neural net is a modification of the net from the 1984 paper by Hopfield.
% The original neural net was also analyzed by Michel, Farrell, and Porod.
% Their paper appeared in the IEEE Transactions on Circuits and Systems, Vol. 36, No. 2, Feb 1989.
% The equations of the net are,
%
% u_1dot=-b1*u_1+A12*g_2(u_2), u_2dot=-1.1*u_2+g_1(u_1).
%
% A plot of the activation nonlinearity g_i(u_i) versus u_i is generated first.
% Then, one equilibrium state is computed.
% Plots of G(x_i)/x_i are generated and sigma_j2, j=1,2, are found.
% Negative definiteness of the matrix S is checked.
% Finally, a state plane portrait of the net is produced.
% last modified by S. H. Zak on December 5, 2002
clc
clear
disp('The neural net analyzed is described by')
disp('u_1dot=-b1*u_1+A12*g_2(u_2)')
disp('u_2dot=-1.1*u_2+g_1(u_1)')
disp('Parametrs b1 and A12 are chosen to make the net satisfy conditions for exponential stability')
disp('Activation nonlinearity is ploted first.')
disp('==============================')
disp('Press Enter to continue.')
pause
x=-5:0.001:5;
plot(x,eval('(2/pi)*atan(0.7*pi*x)')) %activation nonlinearity is ploted
set(gca,'Fontsize',12)
grid
xlabel('{\it u_i}','Fontsize',12)
ylabel('{\it g_i}({\it u_i})','Fontsize',12)
title('Plot of the activation nonlinearity (9.128)','Fontsize',12)
%===============equilibrium point is found
global b1 A12
b1=1.4;
A12=1.2;
alpha1=1;
x=-0.5:0.001:0.5;
rr=0.5;
figure
plot(x,eval('-b1*x+A12*(2/pi)*atan(0.7*pi*(2/(1.1*pi))*atan(0.7*pi*x))'))
axis([-rr rr -inf inf])
set(gca,'Fontsize',12)
grid
xlabel('{\it u}_1','Fontsize',12)
title('Computing the first coordinates of the equilibrium states in Example 9.8','Fontsize',12)
disp('Press ENTER to continue')
pause
figure
subplot(2,1,1)
x1=-0.4098;
y1=-0.4245;
r=0.4
x=-r:0.001:r;
plot(x,eval('(2./(pi*x)).*atan(0.7*pi*(x+x1))-(2./(pi*x)).*atan(0.7*pi*x1)'))
axis([-r r 0.4 1.2])
set(gca,'Fontsize',12)
grid
xlabel('{\it x}_1','Fontsize',12)
ylabel('{\it G}_1({\it x}_1)/{\it x}_1','Fontsize',12)
title('Plot of the terms {\it G}_1({\it x}_1)/{\it x}_1 and {\it G}_2({\it x}_2)/{\it x}_2','Fontsize',12)
sigma_12=(2/(pi*r))*atan(0.7*pi*(r+x1))-(2/(pi*r))*atan(0.7*pi*(x1))
subplot(2,1,2)
x=-r:0.001:r;
plot(x,eval('(2./(pi*x)).*atan(0.7*pi*(x+y1))-(2./(pi*x)).*atan(0.7*pi*y1)'))
axis([-r r 0.4 1.2])
set(gca,'Fontsize',12)
grid
xlabel('{\it x}_2','Fontsize',12)
ylabel('{\it G}_2({\it x}_2)/{\it x}_2','Fontsize',12)
%title('Plot of the term {\it G}_2({\it x}_2)/{\it x}_2','Fontsize',12)
sigma_22=(2./(pi*r)).*atan(0.7*pi*(r+y1))-(2./(pi*r))*atan(0.7*pi*y1)
S=[-b1*alpha1 0.5*(sigma_12+alpha1*abs(A12)*sigma_22);0.5*(sigma_12+alpha1*abs(A12)*sigma_22) -1.1]
disp('The eigenvalues of S are:')
disp(eig(S))
tspan=[0 20];
x0=[1 1]';
button=1;
figure
axis([-1 1 -1 1]);
axis square;
set(gca,'Fontsize',12)
hold on
xx=-1:0.3:1;
%x=0.2:0.03:0.65;
yy=xx;
[X,Y]=meshgrid(xx,yy);
dX=-b1*X+A12*(2/pi)*atan(1.4*pi*Y/2);
dY=-1.1*Y+2/pi*atan(1.4*pi*X/2);
quiver(X,Y,dX,dY)
xlabel('{\it u}_1','Fontsize',12)
ylabel('{\it u}_2','Fontsize',12)
title('Interactive phase portrait of the neural net of Example 9.8','Fontsize',12)
set(gca,'Fontsize',12)
while(button==1)
[t,x]=ode23s('hopfield2',tspan,x0);
plot(x(:,1),x(:,2))
[x_1,x_2,button]=ginput(1);
x0=[x_1 x_2]';
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -