forked from markomil/vilin-numerical-optimization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCorrPrevIter.m
More file actions
60 lines (48 loc) · 2.26 KB
/
CorrPrevIter.m
File metadata and controls
60 lines (48 loc) · 2.26 KB
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
55
56
57
58
59
function [ outT, outX, outVal, outGr, evalNumbers ] = CorrPrevIter( functionName, params )
% ------------------ ******************* ------------------
% * *
% * ************************************* *
% * * * *
% * * Corrected by previous * *
% * * iteration line search * *
% * * * *
% * ************************************* *
% * *
% ------------------ ******************* ------------------
% This is simple method for computing current step size parameter t.
% It is computed based on the previous stepsize value
% as well as current function value.
% It is heuristic that follows simple rule:
% if newFunVal > currFunVal
% stepsize = coef * stepsize
% end
% where coef < 1; usually coef = 0.5
% It is still not published anywhere.
% ------------------ ******************* ------------------
% set initial values
evalNumbers = EvaluationNumbers(0,0,0);
x0 = params.startingPoint;
vals = params.vals;
val = vals(end); % take last (current) function value
dir = params.dir;
it = 1; % number of iteration
%t = params.tInitStart; % starting value for t
t = params.tPrev; % starting value for t
coef = 0.5;
[val1, ~, ~] = feval(functionName, x0+t*dir, [1 0 0]);
evalNumbers.incrementBy([1 0 0]);
% process
while (val1 >= val)
t = t * coef;
it = it + 1;
[val1, ~, ~] = feval(functionName, x0+t*dir, [1 0 0]);
evalNumbers.incrementBy([1 0 0]);
end;
% save output values
xmin = x0 + t*dir;
outX = xmin; outT = t;
outVal = val1;
% compute gradient in current point xmin
[~, outGr, ~] = feval(functionName, xmin, [0 1 0]);
evalNumbers.incrementBy([0 1 0]);
end