-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSIMPSASET.m
171 lines (157 loc) · 6.21 KB
/
SIMPSASET.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
function options = SIMPSASET(varargin)
%SIMPSASET Create/alter simpsa optimization OPTIONS structure.
% OPTIONS = SIMPSASET('PARAM1',VALUE1,'PARAM2',VALUE2,...) creates an
% optimization options structure OPTIONS in which the named parameters have
% the specified values. Any unspecified parameters are set to [] (parameters
% with value [] indicate to use the default value for that parameter when
% OPTIONS is passed to the optimization function). It is sufficient to type
% only the leading characters that uniquely identify the parameter. Case is
% ignored for parameter names.
% NOTE: For values that are strings, the complete string is required.
%
% OPTIONS = SIMPSASET(OLDOPTS,'PARAM1',VALUE1,...) creates a copy of OLDOPTS
% with the named parameters altered with the specified values.
%
% OPTIONS = SIMPSASET(OLDOPTS,NEWOPTS) combines an existing options structure
% OLDOPTS with a new options structure NEWOPTS. Any parameters in NEWOPTS
% with non-empty values overwrite the corresponding old parameters in
% OLDOPTS.
%
% SIMPSASET with no input arguments and no output arguments displays all
% parameter names and their possible values, with defaults shown in {}
% when the default is the same for all functions that use that option -- use
% SIMPSASET(OPTIMFUNCTION) to see options for a specific function.
%
% OPTIONS = SIMPSASET (with no input arguments) creates an options structure
% OPTIONS where all the fields are set to [].
% See also SIMPSAGET, SIMPSA
%
% Copyright (C) 2006 Brecht Donckels, BIOMATH, [email protected]
%
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
% USA.
% Print out possible values of properties.
if (nargin == 0) && (nargout == 0)
fprintf(' TEMP_START: [ positive scalar ]\n');
fprintf(' TEMP_END: [ positive scalar ]\n');
fprintf(' COOL_RATE: [ positive scalar ]\n');
fprintf(' INITIAL_ACCEPTANCE_RATIO: [ positive scalar < 1 {0.95} ]\n');
fprintf(' MIN_COOLING_FACTOR: [ positive scalar < 1 {0.9}]\n');
fprintf(' MAX_ITER_TEMP_FIRST: [ positive scalar {100} ]\n');
fprintf(' MAX_ITER_TEMP_LAST: [ positive scalar {20} ]\n');
fprintf(' MAX_ITER_TOTAL: [ positive scalar {2500} ]\n');
fprintf(' MAX_TIME: [ positive scalar {2500} ]\n');
fprintf(' MAX_FUN_EVALS: [ positive scalar {2500} ]\n');
fprintf(' TOLX: [ positive scalar {1e-6} ]\n');
fprintf(' TOLFUN: [ positive scalar {1e-6} ]\n');
fprintf(' DISPLAY: [ ''iter'' or ''none'' {''iter''} ]\n');
fprintf(' OUTPUT_FCN: [ function_handle ]\n');
fprintf('\n');
return;
end
Names = [
'TEMP_START '
'TEMP_END '
'COOL_RATE '
'INITIAL_ACCEPTANCE_RATIO '
'MIN_COOLING_FACTOR '
'MAX_ITER_TEMP_FIRST '
'MAX_ITER_TEMP_LAST '
'MAX_ITER_TEMP '
'MAX_ITER_TOTAL '
'MAX_TIME '
'MAX_FUN_EVALS '
'TOLX '
'TOLFUN '
'DISPLAY '
'OUTPUT_FCN '
];
m = size(Names,1);
names = lower(Names);
% Combine all leading options structures o1, o2, ... in odeset(o1,o2,...).
options = [];
for j = 1:m
options.(deblank(Names(j,:))) = [];
end
i = 1;
while i <= nargin
arg = varargin{i};
if ischar(arg) % arg is an option name
break;
end
if ~isempty(arg) % [] is a valid options argument
if ~isa(arg,'struct')
error('MATLAB:odeset:NoPropNameOrStruct',...
['Expected argument %d to be a string property name ' ...
'or an options structure\ncreated with SIMANSET.'], i);
end
for j = 1:m
if any(strcmp(fieldnames(arg),deblank(Names(j,:))))
val = arg.(deblank(Names(j,:)));
else
val = [];
end
if ~isempty(val)
options.(deblank(Names(j,:))) = val;
end
end
end
i = i + 1;
end
% A finite state machine to parse name-value pairs.
if rem(nargin-i+1,2) ~= 0
error('MATLAB:odeset:ArgNameValueMismatch',...
'Arguments must occur in name-value pairs.');
end
expectval = 0; % start expecting a name, not a value
while i <= nargin
arg = varargin{i};
if ~expectval
if ~ischar(arg)
error('MATLAB:odeset:NoPropName',...
'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('MATLAB:odeset:InvalidPropName',...
'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('MATLAB:odeset:AmbiguousPropName', msg);
end
end
expectval = 1; % we expect a value next
else
options.(deblank(Names(j,:))) = arg;
expectval = 0;
end
i = i + 1;
end
if expectval
error('MATLAB:odeset:NoValueForProp',...
'Expected value for property ''%s''.', arg);
end
end