Created
July 5, 2018 06:28
-
-
Save sritee/59504b8b6096d056fb5f3f4c826d9ff3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function[]=visualize_2D_optimizer(f,traj) | |
| %input - trajectory matrix of size (2,n) containing n iterates of 2D optimizer's trajectory, f is a function which evaluates pointwise. | |
| x = linspace(-3,3,30); | |
| y = linspace(-3,3,30); | |
| [X,Y] = meshgrid(x,y); %creating grid of points to evaluate f for the contour. | |
| val=zeros(size(X)); | |
| for m=1:size(X,1) | |
| for n=1:size(X,2) | |
| val(m,n)=f([X(m,n);Y(m,n)]); | |
| end | |
| end | |
| contour(X,Y,val) | |
| hold on; | |
| %we now have the function contours. Let us plot the trajectory! | |
| for k=1:size(traj,2) | |
| plot(traj(1,k),traj(2,k),'*'); | |
| if k>1 | |
| line([traj(1,k-1),traj(1,k)],[traj(2,k-1),traj(2,k)]) %optimizer descent line. | |
| end | |
| end | |
| hold off |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment