|
a |
|
b/combinedDeepLearningActiveContour/minFunc/taylorModel.m |
|
|
1 |
function [f,g,H] = taylorModel(d,f,g,H,T) |
|
|
2 |
|
|
|
3 |
p = length(d); |
|
|
4 |
|
|
|
5 |
fd3 = 0; |
|
|
6 |
gd2 = zeros(p,1); |
|
|
7 |
Hd = zeros(p); |
|
|
8 |
for t1 = 1:p |
|
|
9 |
for t2 = 1:p |
|
|
10 |
for t3 = 1:p |
|
|
11 |
fd3 = fd3 + T(t1,t2,t3)*d(t1)*d(t2)*d(t3); |
|
|
12 |
|
|
|
13 |
if nargout > 1 |
|
|
14 |
gd2(t3) = gd2(t3) + T(t1,t2,t3)*d(t1)*d(t2); |
|
|
15 |
end |
|
|
16 |
|
|
|
17 |
if nargout > 2 |
|
|
18 |
Hd(t2,t3) = Hd(t2,t3) + T(t1,t2,t3)*d(t1); |
|
|
19 |
end |
|
|
20 |
end |
|
|
21 |
|
|
|
22 |
end |
|
|
23 |
end |
|
|
24 |
|
|
|
25 |
f = f + g'*d + (1/2)*d'*H*d + (1/6)*fd3; |
|
|
26 |
|
|
|
27 |
if nargout > 1 |
|
|
28 |
g = g + H*d + (1/2)*gd2; |
|
|
29 |
end |
|
|
30 |
|
|
|
31 |
if nargout > 2 |
|
|
32 |
H = H + Hd; |
|
|
33 |
end |
|
|
34 |
|
|
|
35 |
if any(abs(d) > 1e5) |
|
|
36 |
% We want the optimizer to stop if the solution is unbounded |
|
|
37 |
g = zeros(p,1); |
|
|
38 |
end |