This is a static copy of a profile reportHome
optimset (1720 calls, 5.268 sec)
Generated 05-Aug-2011 13:01:21 using cpu time.
function in file /usr/local/MATLAB/R2011a/toolbox/matlab/funfun/optimset.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
194 | j = strmatch(lowArg,names); | 6880 | 3.006 s | 57.1% |  |
223 | checkfield(Names{j,:},arg,opti... | 6880 | 0.645 s | 12.2% |  |
121 | options = struct(structinput{:... | 1720 | 0.525 s | 10.0% |  |
188 | if ~expectval | 13760 | 0.153 s | 2.9% |  |
150 | names = lower(Names); | 1720 | 0.153 s | 2.9% |  |
All other lines | | | 0.787 s | 14.9% |  |
Totals | | | 5.268 s | 100% | |
Children (called functions)
Code Analyzer results
Line number | Message |
136 | The value assigned to variable 'ME' might be unused. |
194 | STRMATCH will be removed in a future release. Use STRNCMP instead. |
204 | STRMATCH will be removed in a future release. Replace STRMATCH(STR, STRARRAY, 'exact') with STRCMP(STR, STRARRAY). |
209 | The variable 'msg' appears to change size on every loop iteration. Consider preallocating for speed. |
211 | The variable 'msg' appears to change size on every loop iteration. Consider preallocating for speed. |
213 | The variable 'msg' appears to change size on every loop iteration. Consider preallocating for speed. |
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 232 |
Non-code lines (comments, blank lines) | 110 |
Code lines (lines that can run) | 122 |
Code lines that did run | 43 |
Code lines that did not run | 79 |
Coverage (did run/can run) | 35.25 % |
Function listing
time calls line
1 function options = optimset(varargin)
2 %OPTIMSET Create/alter optimization OPTIONS structure.
3 % OPTIONS = OPTIMSET('PARAM1',VALUE1,'PARAM2',VALUE2,...) creates an
4 % optimization options structure OPTIONS in which the named parameters have
5 % the specified values. Any unspecified parameters are set to [] (parameters
6 % with value [] indicate to use the default value for that parameter when
7 % OPTIONS is passed to the optimization function). It is sufficient to type
8 % only the leading characters that uniquely identify the parameter. Case is
9 % ignored for parameter names.
10 % NOTE: For values that are strings, the complete string is required.
11 %
12 % OPTIONS = OPTIMSET(OLDOPTS,'PARAM1',VALUE1,...) creates a copy of OLDOPTS
13 % with the named parameters altered with the specified values.
14 %
15 % OPTIONS = OPTIMSET(OLDOPTS,NEWOPTS) combines an existing options structure
16 % OLDOPTS with a new options structure NEWOPTS. Any parameters in NEWOPTS
17 % with non-empty values overwrite the corresponding old parameters in
18 % OLDOPTS.
19 %
20 % OPTIMSET with no input arguments and no output arguments displays all
21 % parameter names and their possible values, with defaults shown in {}
22 % when the default is the same for all functions that use that parameter.
23 % Use OPTIMSET(OPTIMFUNCTION) to see parameters for a specific function.
24 %
25 % OPTIONS = OPTIMSET (with no input arguments) creates an options structure
26 % OPTIONS where all the fields are set to [].
27 %
28 % OPTIONS = OPTIMSET(OPTIMFUNCTION) creates an options structure with all
29 % the parameter names and default values relevant to the optimization
30 % function named in OPTIMFUNCTION. For example,
31 % optimset('fminbnd')
32 % or
33 % optimset(@fminbnd)
34 % returns an options structure containing all the parameter names and
35 % default values relevant to the function 'fminbnd'.
36 %
37 %OPTIMSET PARAMETERS for MATLAB
38 %Display - Level of display [ off | iter | notify | final ]
39 %MaxFunEvals - Maximum number of function evaluations allowed
40 % [ positive integer ]
41 %MaxIter - Maximum number of iterations allowed [ positive scalar ]
42 %TolFun - Termination tolerance on the function value [ positive scalar ]
43 %TolX - Termination tolerance on X [ positive scalar ]
44 %FunValCheck - Check for invalid values, such as NaN or complex, from
45 % user-supplied functions [ {off} | on ]
46 %OutputFcn - Name(s) of output function [ {[]} | function ]
47 % All output functions are called by the solver after each
48 % iteration.
49 %PlotFcns - Name(s) of plot function [ {[]} | function ]
50 % Function(s) used to plot various quantities in every iteration
51 %
52 % Note to Optimization Toolbox users:
53 % To see the parameters for a specific function, check the documentation page
54 % for that function. For instance, enter
55 % doc fmincon
56 % to open the reference page for fmincon.
57 %
58 % You can also see the options in the Optimization Tool. Enter
59 % optimtool
60 %
61 % Examples:
62 % To create an options structure with the default parameters for FZERO
63 % options = optimset('fzero');
64 % To create an options structure with TolFun equal to 1e-3
65 % options = optimset('TolFun',1e-3);
66 % To change the Display value of options to 'iter'
67 % options = optimset(options,'Display','iter');
68 %
69 % See also OPTIMGET, FZERO, FMINBND, FMINSEARCH, LSQNONNEG.
70
71 % Copyright 1984-2010 The MathWorks, Inc.
72 % $Revision: 1.34.4.31 $ $Date: 2010/11/17 11:26:34 $
73
74 % Check to see if Optimization Toolbox options are available
0.02 1720 75 optimtbx = uselargeoptimstruct;
76
77 % Print out possible values of properties.
1720 78 if (nargin == 0) && (nargout == 0)
79 if optimtbx
80 fprintf([' Display: [ off | iter | iter-detailed | ', ...
81 'notify | notify-detailed | final | final-detailed ]\n']);
82 else
83 fprintf([' Display: [ off | iter | ', ...
84 'notify | final ]\n']);
85 end
86 fprintf(' MaxFunEvals: [ positive scalar ]\n');
87 fprintf(' MaxIter: [ positive scalar ]\n');
88 fprintf(' TolFun: [ positive scalar ]\n');
89 fprintf(' TolX: [ positive scalar ]\n');
90 fprintf(' FunValCheck: [ on | {off} ]\n');
91 fprintf(' OutputFcn: [ function | {[]} ]\n');
92 fprintf(' PlotFcns: [ function | {[]} ]\n');
93
94 % Display specialized options if appropriate
95 if optimtbx
96 optimoptions;
97 else
98 fprintf('\n');
99 end
100 return;
101 end
102
103 % Create a cell array of all the field names
0.01 1720 104 allfields = {'Display'; 'MaxFunEvals';'MaxIter';'TolFun';'TolX'; ...
105 'FunValCheck';'OutputFcn';'PlotFcns'};
106
107 % Include specialized options if appropriate
1720 108 if optimtbx
0.08 1720 109 optimfields = optimoptiongetfields;
0.01 1720 110 allfields = [allfields; optimfields];
1720 111 end
112
113 % Create a struct of all the fields with all values set to []
114 % create cell array
0.02 1720 115 structinput = cell(2,length(allfields));
116 % fields go in first row
0.04 1720 117 structinput(1,:) = allfields';
118 % []'s go in second row
0.01 1720 119 structinput(2,:) = {[]};
120 % turn it into correctly ordered comma separated list and call struct
0.52 1720 121 options = struct(structinput{:});
122
1720 123 numberargs = nargin; % we might change this value, so assign it
124 % If we pass in a function name then return the defaults.
0.01 1720 125 if (numberargs==1) && (ischar(varargin{1}) || isa(varargin{1},'function_handle') )
126 if ischar(varargin{1})
127 funcname = lower(varargin{1});
128 if ~exist(funcname,'file')
129 error(message('MATLAB:optimset:FcnNotFoundOnPath', funcname));
130 end
131 elseif isa(varargin{1},'function_handle')
132 funcname = func2str(varargin{1});
133 end
134 try
135 optionsfcn = feval(varargin{1},'defaults');
136 catch ME
137 error(message('MATLAB:optimset:NoDefaultsForFcn', funcname));
138 end
139 % The defaults from the optim functions don't include all the fields
140 % typically, so run the rest of optimset as if called with
141 % optimset(options,optionsfcn)
142 % to get all the fields.
143 varargin{1} = options;
144 varargin{2} = optionsfcn;
145 numberargs = 2;
146 end
147
0.01 1720 148 Names = allfields;
0.01 1720 149 m = size(Names,1);
0.15 1720 150 names = lower(Names);
151
1720 152 i = 1;
1720 153 while i <= numberargs
1720 154 arg = varargin{i};
1720 155 if ischar(arg) % arg is an option name
1720 156 break;
157 end
158 if ~isempty(arg) % [] is a valid options argument
159 if ~isa(arg,'struct')
160 error(message('MATLAB:optimset:NoParamNameOrStruct', i));
161 end
162 for j = 1:m
163 if any(strcmp(fieldnames(arg),Names{j,:}))
164 val = arg.(Names{j,:});
165 else
166 val = [];
167 end
168 if ~isempty(val)
169 if ischar(val)
170 val = lower(deblank(val));
171 end
172 checkfield(Names{j,:},val,optimtbx);
173 options.(Names{j,:}) = val;
174 end
175 end
176 end
177 i = i + 1;
178 end
179
180 % A finite state machine to parse name-value pairs.
1720 181 if rem(numberargs-i+1,2) ~= 0
182 error(message('MATLAB:optimset:ArgNameValueMismatch'));
183 end
0.01 1720 184 expectval = 0; % start expecting a name, not a value
1720 185 while i <= numberargs
0.05 13760 186 arg = varargin{i};
187
0.15 13760 188 if ~expectval
6880 189 if ~ischar(arg)
190 error(message('MATLAB:optimset:InvalidParamName', i));
191 end
192
0.03 6880 193 lowArg = lower(arg);
3.01 6880 194 j = strmatch(lowArg,names);
0.04 6880 195 if isempty(j) % if no matches
196 % Error out - compose internationalization-friendly message with hyperlinks
197 stringWithLink = formatStringWithHyperlinks(sprintf('Link to reference page'),'doc optimset');
198 error('MATLAB:optimset:InvalidParamName',...
199 ['Unrecognized parameter name ''%s''. Please see the optimset' ...
200 ' reference page in the documentation for a list of acceptable' ...
201 ' option parameters. %s'],arg,stringWithLink);
0.03 6880 202 elseif length(j) > 1 % if more than one match
203 % Check for any exact matches (in case any names are subsets of others)
204 k = strmatch(lowArg,names,'exact');
205 if length(k) == 1
206 j = k;
207 else
208 msg = sprintf('Ambiguous parameter name ''%s'' ', arg);
209 msg = [msg '(' Names{j(1),:}];
210 for k = j(2:length(j))'
211 msg = [msg ', ' Names{k,:}];
212 end
213 msg = [msg,'.'];
214 error('MATLAB:optimset:AmbiguousParamName', msg);
215 end
216 end
0.04 6880 217 expectval = 1; % we expect a value next
218
6880 219 else
0.01 6880 220 if ischar(arg)
0.04 3440 221 arg = lower(deblank(arg));
3440 222 end
0.64 6880 223 checkfield(Names{j,:},arg,optimtbx);
0.07 6880 224 options.(Names{j,:}) = arg;
0.01 6880 225 expectval = 0;
0.02 6880 226 end
0.07 13760 227 i = i + 1;
0.05 13760 228 end
229
1720 230 if expectval
231 error(message('MATLAB:optimset:NoValueForParam', arg));
232 end
Other subfunctions in this file are not included in this listing.