%
clf;
clear;
close all hidden;
%%%
%% Steepest Descent Dynamics
%%% remove graph = clf
%%% Data clear = clear
%%%%%%%%%%%%%%%%%%%%%%%% Constants %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
AAA = 5.0; %%%
BBB = 0.02; %%%
CCC = 2; %%%
VECT=0.3;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
KURIKAESHI=100;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
GRADFIELD=0; %%% gradient vector
OPTIMIZE=1; %%% optimization
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ETA=0.1; %%%%% homework 0.01 0.1 0.2
ALPHA=0.0; %%%%% homework 0.0 0.3 0.8
LANGEVIN=0.0; %%%%% homework 0.0 0.5 1.0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
X0 = 1.4; %%% initial point
Y0 = -2.5; %%% initial point
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
V1=-9:0.5:9;
NNN=LANGEVIN*sqrt(2.0*ETA);
[X1 Y1]=meshgrid(V1);
Z1 = AAA*sin(X1)-Y1;
Z2 = Z1.*Z1 + BBB*X1.^4 - CCC*X1.^2;
[PX1,PY1]=gradient(Z2);
contour(V1,V1,Z2,20); hold on
if(GRADFIELD==1)
quiver(V1,V1,-VECT*PX1,-VECT*PY1); hold on
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1);
plot(X0,Y0,'ro'); hold on
title('Steepest Descent');
if(OPTIMIZE==1)
X2 = 0.0;
Y2 = 0.0;
III=zeros(1,KURIKAESHI);
FFF=zeros(1,KURIKAESHI);
for i=1:1:KURIKAESHI
Z0 = AAA*sin(X0)-Y0;
DX = AAA*Z0*cos(X0)+4*BBB*X0^3 - 2.0*CCC*X0;
DY = -2.0*Z0;
X1 = X0 -ETA*DX + ALPHA*X2+ NNN*randn(1,1);
Y1 = Y0 -ETA*DY + ALPHA*Y2 + NNN*randn(1,1);
X2 = X1-X0;
Y2 = Y1-Y0;
Z1 = AAA*sin(X1)-Y1;
III(i)=i;
FFF(i) = Z1.*Z1 + BBB*X1.^4 - CCC*X1.^2;
p0 =[X0 X1];
p1 =[Y0 Y1];
plot(X1,Y1,'ro'); hold on
plot(p0,p1,'r-'); hold on
%%%% drawnow;
X0=X1;
Y0=Y1;
end
hold off
figure(2);
plot(III,FFF,'b-');
xlabel('Cycle');
ylabel('Evaluation');
end