-
Notifications
You must be signed in to change notification settings - Fork 0
/
directionSetMinimizer.m
54 lines (45 loc) · 1.32 KB
/
directionSetMinimizer.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function [xmin fres] = directionSetMinimizer(fun, x0, directions, tol)
%DIRECTIONSETMINIMIZER One-line description here, please.
%
% output = directionSetMinimizer(FUN, X0, DIRS)
% FUN is the function to minimize. It accepts a row vector as input, and
% returns a scalar.
% X0 is the initial guess of the minimum. It is a 1-by-N row vector.
% DIR is the direction seach. It is a 1-by-N row vector.
% TOL is the tolerance used by brentLineSearch.
%
% Example
% directionSetMinimizer
%
% See also
%
%
% ------
% Author: David Legland
% e-mail: [email protected]
% Created: 2010-08-10, using Matlab 7.9.0.529 (R2009b)
% Copyright 2010 INRA - Cepia Software Platform.
% number of iterations
MAX_ITER = 200;
dirIndex = 1;
% main loop
for iter = 1:MAX_ITER
% current direction
dir = directions(dirIndex, :);
% update direction index
dirIndex = mod(dirIndex, size(directions, 1)) + 1;
% use a function handle of 1 variable
fun1 = @(t) fun(x0 + t*dir);
% guess initial bounds of the function
ax = 0;
bx = 1;
[ax bx cx] = fMinBracket(fun1, ax, bx);
% search minimum along dimension DIR
tmin = brentLineSearch(fun1, ax, bx, cx, tol);
% construct new optimal point
x0 = x0 + tmin*dir;
end
xmin = x0;
if nargout>1
fres = fun(xmin);
end