-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmyfminunc.m
68 lines (59 loc) · 1.87 KB
/
myfminunc.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function myfminunc()
fprintf('[myfminunc] Make sure that segmentationError output is appropriate!\n\n');
c = int16(clock());
p = Parameters();
p.initialize();
x0 = p.toVector();
year = sprintf('%d', c(1));
month = pad2(c(2));
day = pad2(c(3));
hour = pad2(c(4));
minute = pad2(c(5));
dateStr = sprintf('%s%s%s%s%s', year, month, day, hour, minute);
filename = sprintf('minNImP4-fminunc-%s.txt', dateStr);
fid = fopen(filename, 'w');
fprintf(fid, '%s-%s-%s %s:%s\n\n', year, month, day, hour, minute);
fprintf(fid, 'Initial Parameters: %s\n\n', p.toString());
os = optimset('Display', 'iter', 'MaxIter', 1000, 'MaxFunEvals', 10000, 'TolFun', 1e-8, 'Algorithm', 'simplex');
fprintf(fid, 'optimset:\n');
fieldNames = fieldnames(os);
for i = 1:numel(fieldNames)
fn = fieldNames{i};
val = os.(fn);
if ~isempty(val)
if ischar(val)
fprintf(fid, '%s: %s\n', fn, val);
else
if isnumeric(val)
fprintf(fid, '%s: %f\n', fn, val);
else
fprintf(fid, '%s: ???\n', fn);
end
end
end
end
fprintf(fid, '\n');
[x, fval, exitflag, output] = fminunc(@segmentationError, x0, os);
fprintf(fid, 'x = [%f', x(1));
for i = 2:numel(x)
fprintf(fid, ', %f', x(i));
end
fprintf(fid, ']\n');
fprintf(fid, 'fval = %f\n', fval);
fprintf(fid, 'exitflag = %d\n', exitflag);
fprintf(fid, 'output.iterations = %d\n', output.iterations);
fprintf(fid, 'output.funcCount = %d\n', output.funcCount);
fprintf(fid, 'output.firstorderopt = %d\n', output.firstorderopt);
fprintf(fid, 'output.algorithm = %s\n', output.algorithm);
fprintf(fid, 'output.stepsize = %s\n', output.stepsize);
fprintf(fid, 'output.message = %s\n', output.message);
fclose(fid);
fprintf('Wrote file %s\n', filename);
end
function s = pad2(intgr)
if intgr < 10
s = sprintf('0%d', intgr);
else
s = sprintf('%d', intgr);
end
end