steepest descent using armijo rule

67 vues (au cours des 30 derniers jours)
Kendall Donahoe
Kendall Donahoe le 16 Fév 2022
I need help using the armijo rule to find the steepest descent.
Here is the proplem I need to solve and the code I have so far. I know how to do it in 1-D but am having trouble translating that to 2-D.
Code a function to perform a generic steepest descent algorithm using the Armijo line-search rule. Your function should take as inputs, the number of iterations, the function to be minimized (fm), another function that returns the gradient of fm, some initial point x0, and the parameters needed for the line search. Turn in all of your code and the first five iterations when the algorithm is applied to minimizing the function
f(x,y)=(x-2y^2)(x-3y^2), starting at the initial point (-1,-1)
Use line-search parameters of s=1, beta=1/2, and sigma=0.1.
f=@(x) (x(1)-2*x(2).^2).*(x(1)-3*x(2).^2)
xk=[-1,-1]';
fg=@(x) [(x(1)-3*x(2).^2)+(x(1)-2*x(2).^2);4*x(2)*(x(1)-3*x(2).^2)+6*x(2)*(x(1)-2*x(2).^2)];
s=1;
beta=0.5;
sigma=0.1;
for j=1:6
xk(j+1)=armijostep(f,fg,-sign(fg(xk(j))),xk(j),s,beta,sigma); %inputs are f, fg, d, xk, s, beta, sigma in that order
end
hold on;
plot(xk,f(xk),'k*-')
xk
hold off;
  2 commentaires
Torsten
Torsten le 16 Fév 2022
Use xk{j} instead of xk(j) if xk is n-dimensional (n>1) (already set the inital xk as xk{1} = [-1,-1].')
Kendall Donahoe
Kendall Donahoe le 16 Fév 2022
I just tried that. I don't think it did anything. I'm not sure if I did it right. Before my main issue was getting an error on the number of array elements when trying to enter the gradient.

Connectez-vous pour commenter.

Réponses (1)

Brahmadev
Brahmadev le 8 Fév 2024
Assuming that 'armijostep' function written by you takes the x and y co-ordinates (2x1 vector) from the current iteration and returns the x and y co-ordinates for the next iteration as a 2x1 vector, we can store pre-allocate 'xk' and modify the code as shown below:
% Defining the function f
f=@(x) (x(1)-2*x(2).^2).*(x(1)-3*x(2).^2);
no_of_iter = 6; % Defining no. of iterations
xk = zeros([2, no_of_iter]); % Pre-allocating for each step
xk(:, 1)=[-1,-1]'; % Initial guess
% Defining the function fg
fg=@(x) [(x(1)-3*x(2).^2)+(x(1)-2*x(2).^2);4*x(2)*(x(1)-3*x(2).^2)+6*x(2)*(x(1)-2*x(2).^2)];
% Defining constants
s=1;
beta=0.5;
sigma=0.1;
% Calculating each new iteration and plotting it
hold on
for j=1:no_of_iter
xk(:, j+1) = armijostep(f, fg, -sign(fg(xk(:, j))), xk(:, j), s, beta, sigma); %inputs are f, fg, d, xk, s, beta, sigma in that order
plot(xk(:, j),f(xk(:, j)),'k*-'); % Plotting each iteration
end
hold off
Hope this helps in resolving your query!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by