How to do Gradient Descent Optimization Algorithm in MATLAB | MATLAB Tutorial

preview_player
Показать описание
2022 Gradient Descent Algorithm in MATLAB! How to optimize a function using Gradient Descent. 3D example with equations, code, and explanation for beginners.

#matlab #LearnMATLAB #GradientDescent

CHAPTERS
0:00 Overview
0:25 Equations
2:43 Algorithm
8:36 Learning Rate

MATLAB BASICS

ADVANCED MATLAB

HELP A BROTHER OUT
Thank you so much for watching! Please consider subscribing as a thank you if you benefited from this content! :D

HELPING MY BROTHERS AND SISTERS OUT
Comment below and I will happily answer all your questions, queries, and conundrums... whether or not they pertain to programming ;)
Рекомендации по теме
Комментарии
Автор

FINALLY a true video explaining gradient descent and the algorithm behind it

alexarunyan
Автор

Thanks for the explanation broken down in simple but detailed steps!

durlov
Автор

Nice one ...
Please make videos about divergence and others if you have time♥️♥️

mahadevanar
Автор

Great video!! Just one question... what is this anonymous function used for? f = 1/4*x^2 + y^2 ? Why did you select and use this function in particular?

s.a.
Автор

I have a question: I have to use GD for another type of function, but i got stuck.
I changed object function for both f and fs, respectively:
"f = @(x, y) x.*exp(-x.^2-y.^2);
syms fs xs ys
fs = xs.*exp(-xs.^2-ys.^2);" but i got this error:
"Not enough input arguments.
Error in symengine>@(xs, ys)exp(-xs.^2-ys.^2)-xs.^2.*exp(-xs.^2-ys.^2).*2.0
Error in Gradient_Descent (line 46)
pts(i+1, 1) = pts(i, 1) - gamma*grad_x(pts(i, 1));"
Code is the same, just changing domain, starting point and function.
Could be that exp create problems? Why that?
( Really appreciated your work, thanks for sharing <3 )

madreerdam
Автор

Thank you for the great explanation. I had a question. If I have weights in an equation and changing those weights changes the output value constant(F). Can I still use gradient descent on the constant and change the weights to get the lowest constant(F) possible?

maazmohammad
Автор

Man, thank you so much for your video. I've tried it myself to make a univeristy homework. but I've got a problem with my function:

f = @(x, y)

I've changed your code, to fit my function, but It did't work "well". One guy had same problem down the comment section ("Not enough input arguments."), I think I've caught how to solve it, but the resoult is shit :(

Here is what I did:

while err_x > 0.01 || err_y > 0.01

gradix = grad_x(pts(i, 1), pts(i, 2)); %first component of gradient
gradiy = grad_y(pts(i, 1), pts(i, 2)); %second component of gradient
grad_f = sqrt(gradix^2 + gradiy^2); %gradient length


pts(i+1, 1) = pts(i, 1) - betta/grad_f*grad_x(pts(i, 1), pts(i, 2)); %x
pts(i+1, 2) = pts(i, 2) - betta/grad_f*grad_y(pts(i, 1), pts(i, 2)); %y
pts(i+1, 3) = f(pts(i+1, 1), pts(i+1, 2)); %z (from x, y)
% Update difference between consecutive points
err_x = abs(pts(i+1, 1) - pts(i, 1));
err_y = abs(pts(i+1, 2) - pts(i, 2));
% increment i (move to next row)
i = i + 1;
% break loop if going too long
if i > 100
break
end
end


Where am I wrong?

Thank you, hope you will answer!

skidzeess
visit shbcf.ru