-
Notifications
You must be signed in to change notification settings - Fork 0
/
nagd_settings.m
70 lines (58 loc) · 2.11 KB
/
nagd_settings.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
69
70
function [ options ] = nagd_settings(varargin)
% Create the options
options = nagd_core_options();
Names = fieldnames(options);
names = lower(Names);
% A finite state machine to parse name-value pairs.
if rem(nargin,2) ~= 0
error('Arguments must occur in name-value pairs.');
end
expectval = 0; % start expecting a name, not a value
i = 1;
while i <= nargin
arg = varargin{i};
if ~expectval
if ~ischar(arg)
error(sprintf('Expected argument %d to be a string property name.', i));
end
lowArg = lower(arg);
j = strmatch(lowArg,names);
if isempty(j) % if no matches
error(sprintf('Unrecognized property name ''%s''.', arg));
elseif length(j) > 1 % if more than one match
% Check for any exact matches (in case any names are subsets of others)
k = strmatch(lowArg,names,'exact');
if (length(k) == 1)
j = k;
else
msg = sprintf('Ambiguous property name ''%s'' ', arg);
msg = [msg '(' deblank(Names{j(1)})];
for k = j(2:length(j))'
msg = [msg ', ' deblank(Names{k})];
end
msg = sprintf('%s).', msg);
error(msg);
end
end
expectval = 1; % we expect a value next
else
eval(['options.' Names{j} '= arg;']);
expectval = 0;
end
i = i + 1;
end
if expectval
error(sprintf('Expected value for property ''%s''.', arg));
end
end
function options = nagd_core_options
% termination criteria
options.gradient_tol = 1e-4; % gradient tolerance
options.MaxIter = 50;
options.time_limit = inf;
% parameters for Armijo line search
options.armijo_max = 30;
options.tau = 0.5;
% options for printing out results
options.verbose = 1;
end