Skip to content

Instantly share code, notes, and snippets.

@lukicdarkoo
Last active July 29, 2016 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukicdarkoo/68702878ef31815d1b80 to your computer and use it in GitHub Desktop.
Save lukicdarkoo/68702878ef31815d1b80 to your computer and use it in GitHub Desktop.
Hook - Jeeves method - Multidimensional Optimization
% 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