-
-
Save lukicdarkoo/68702878ef31815d1b80 to your computer and use it in GitHub Desktop.
Hook - Jeeves method - Multidimensional Optimization
This file contains 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
% Moved from http://pastebin.com/YD8FGFL8 | |
function t = hj(f, x0, step, e) | |
d = eye(length(x0)); | |
t = x0; | |
xb = x0; | |
while step > e | |
% Pretrazivanje u okolini tacke | |
for i = 1:length(d) | |
t_p = t + step * d(i, :); | |
t_m = t - step * d(i, :); | |
if (f(t_p) < f(t)) | |
t = t_p; | |
elseif (f(t_m) < f(t)) | |
t = t_m; | |
end | |
end | |
% Skok | |
tb = t + (t - xb); | |
if f(tb) > f(t) | |
continue; | |
end | |
% Pretrazujemo u okolini skoka | |
for i = 1:length(d) | |
t_p = tb + step * d(i, :); | |
t_m = tb - step * d(i, :); | |
if (f(t_p) < f(xb)) | |
xb = t_p; | |
elseif (f(t_m) < f(xb)) | |
xb = t_m; | |
else | |
step = step / 2; | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment