|
1 | | -function stop = optimplotfvalKsptot(~,optimValues,state,varargin) |
2 | | -% OPTIMPLOTFVAL Plot value of the objective function at each iteration. |
3 | | -% |
4 | | -% STOP = OPTIMPLOTFVAL(X,OPTIMVALUES,STATE) plots OPTIMVALUES.fval. If |
5 | | -% the function value is not scalar, a bar plot of the elements at the |
6 | | -% current iteration is displayed. If the OPTIMVALUES.fval field does not |
7 | | -% exist, the OPTIMVALUES.residual field is used. |
8 | | -% |
9 | | -% Example: |
10 | | -% Create an options structure that will use OPTIMPLOTFVAL as the plot |
11 | | -% function |
12 | | -% options = optimset('PlotFcns',@optimplotfval); |
13 | | -% |
14 | | -% Pass the options into an optimization problem to view the plot |
15 | | -% fminbnd(@sin,3,10,options) |
16 | | - |
17 | | -% Copyright 2006-2010 The MathWorks, Inc. |
18 | | - |
19 | | -stop = false; |
20 | | -switch state |
21 | | - case 'iter' |
22 | | - if isfield(optimValues,'fval') |
23 | | - if isscalar(optimValues.fval) |
24 | | - plotscalar(optimValues.iteration,optimValues.fval); |
25 | | - else |
26 | | - plotvector(optimValues.iteration,optimValues.fval); |
27 | | - end |
28 | | - else |
29 | | - plotvector(optimValues.iteration,optimValues.residual); |
30 | | - end |
31 | | -end |
32 | | - |
33 | | -function plotscalar(iteration,fval) |
34 | | -% PLOTSCALAR initializes or updates a line plot of the function value |
35 | | -% at each iteration. |
36 | | -persistent plotfval plotfvalParent |
37 | | - |
38 | | -if iteration == 0 |
39 | | - plotfval = plot(iteration,fval,'kd','MarkerFaceColor',[1 0 1]); |
40 | | - plotfvalParent = plotfval.Parent; |
41 | | - title(getString(message('MATLAB:optimfun:funfun:optimplots:TitleCurrentFunctionValue',sprintf('%g',fval))),'interp','none'); |
42 | | - xlabel(getString(message('MATLAB:optimfun:funfun:optimplots:LabelIteration')),'interp','none'); |
43 | | - set(plotfval,'Tag','optimplotfval'); |
44 | | - ylabel(getString(message('MATLAB:optimfun:funfun:optimplots:LabelFunctionValue')),'interp','none') |
45 | | -else |
46 | | -% plotfval = findobj(get(gca,'Children'),'Tag','optimplotfval'); |
47 | | -% plotfval.Parent = plotfvalParent; |
48 | | - newX = [get(plotfval,'Xdata') iteration]; |
49 | | - newY = [get(plotfval,'Ydata') fval]; |
50 | | - set(plotfval,'Xdata',newX, 'Ydata',newY); |
51 | | - set(get(plotfvalParent,'Title'),'String',getString(message('MATLAB:optimfun:funfun:optimplots:TitleCurrentFunctionValue',sprintf('%g',fval)))); |
52 | | -end |
53 | | - |
54 | | -function plotvector(iteration,fval) |
55 | | -% PLOTVECTOR creates or updates a bar plot of the function values or |
56 | | -% residuals at the current iteration. |
57 | | -persistent plotfval |
58 | | - |
59 | | -if iteration == 0 |
60 | | - xlabelText = getString(message('MATLAB:optimfun:funfun:optimplots:LabelNumberOfFunctionValues0',sprintf('%g',length(fval)))); |
61 | | - % display up to the first 100 values |
62 | | - if numel(fval) > 100 |
63 | | - xlabelText = {xlabelText,getString(message('MATLAB:optimfun:funfun:optimplots:LabelShowingOnlyFirst100Values'))}; |
64 | | - fval = fval(1:100); |
65 | | - end |
66 | | - plotfval = bar(fval); |
67 | | - title(getString(message('MATLAB:optimfun:funfun:optimplots:TitleCurrentFunctionValues')),'interp','none'); |
68 | | - set(plotfval,'edgecolor','none') |
69 | | - set(plotfvalParent,'xlim',[0,1 + length(fval)]) |
70 | | - xlabel(xlabelText,'interp','none') |
71 | | - set(plotfval,'Tag','optimplotfval'); |
72 | | - ylabel(getString(message('MATLAB:optimfun:funfun:optimplots:LabelFunctionValue')),'interp','none') |
73 | | -else |
74 | | -% plotfval = findobj(get(gca,'Children'),'Tag','optimplotfval'); |
75 | | - % display up to the first 100 values |
76 | | - if numel(fval) > 100 |
77 | | - fval = fval(1:100); |
78 | | - end |
79 | | - set(plotfval,'Ydata',fval); |
80 | | -end |
| 1 | +function stop = optimplotfvalKsptot(~,optimValues,state,varargin) |
| 2 | +% OPTIMPLOTFVAL Plot value of the objective function at each iteration. |
| 3 | +% |
| 4 | +% STOP = OPTIMPLOTFVAL(X,OPTIMVALUES,STATE) plots OPTIMVALUES.fval. If |
| 5 | +% the function value is not scalar, a bar plot of the elements at the |
| 6 | +% current iteration is displayed. If the OPTIMVALUES.fval field does not |
| 7 | +% exist, the OPTIMVALUES.residual field is used. |
| 8 | +% |
| 9 | +% Example: |
| 10 | +% Create an options structure that will use OPTIMPLOTFVAL as the plot |
| 11 | +% function |
| 12 | +% options = optimset('PlotFcns',@optimplotfval); |
| 13 | +% |
| 14 | +% Pass the options into an optimization problem to view the plot |
| 15 | +% fminbnd(@sin,3,10,options) |
| 16 | + |
| 17 | +% Copyright 2006-2010 The MathWorks, Inc. |
| 18 | + |
| 19 | +stop = false; |
| 20 | +switch state |
| 21 | + case 'iter' |
| 22 | + if isfield(optimValues,'fval') |
| 23 | + if isscalar(optimValues.fval) |
| 24 | + plotscalar(optimValues.iteration,optimValues.fval); |
| 25 | + else |
| 26 | + plotvector(optimValues.iteration,optimValues.fval); |
| 27 | + end |
| 28 | + else |
| 29 | + plotvector(optimValues.iteration,optimValues.residual); |
| 30 | + end |
| 31 | +end |
| 32 | + |
| 33 | +function plotscalar(iteration,fval) |
| 34 | +% PLOTSCALAR initializes or updates a line plot of the function value |
| 35 | +% at each iteration. |
| 36 | +persistent plotfval plotfvalParent |
| 37 | + |
| 38 | +if iteration == 0 |
| 39 | + plotfval = plot(iteration,fval,'kd','MarkerFaceColor',[1 0 1]); |
| 40 | + plotfvalParent = plotfval.Parent; |
| 41 | + title(getString(message('MATLAB:optimfun:funfun:optimplots:TitleCurrentFunctionValue',sprintf('%g',fval))),'interp','none'); |
| 42 | + xlabel(getString(message('MATLAB:optimfun:funfun:optimplots:LabelIteration')),'interp','none'); |
| 43 | + set(plotfval,'Tag','optimplotfval'); |
| 44 | + ylabel(getString(message('MATLAB:optimfun:funfun:optimplots:LabelFunctionValue')),'interp','none') |
| 45 | +else |
| 46 | +% plotfval = findobj(get(gca,'Children'),'Tag','optimplotfval'); |
| 47 | +% plotfval.Parent = plotfvalParent; |
| 48 | + newX = [get(plotfval,'Xdata') iteration]; |
| 49 | + newY = [get(plotfval,'Ydata') fval]; |
| 50 | + set(plotfval,'Xdata',newX, 'Ydata',newY); |
| 51 | + set(get(plotfvalParent,'Title'),'String',getString(message('MATLAB:optimfun:funfun:optimplots:TitleCurrentFunctionValue',sprintf('%g',fval)))); |
| 52 | +end |
| 53 | + |
| 54 | +function plotvector(iteration,fval) |
| 55 | +% PLOTVECTOR creates or updates a bar plot of the function values or |
| 56 | +% residuals at the current iteration. |
| 57 | +persistent plotfval |
| 58 | + |
| 59 | +if iteration == 0 |
| 60 | + xlabelText = getString(message('MATLAB:optimfun:funfun:optimplots:LabelNumberOfFunctionValues0',sprintf('%g',length(fval)))); |
| 61 | + % display up to the first 100 values |
| 62 | + if numel(fval) > 100 |
| 63 | + xlabelText = {xlabelText,getString(message('MATLAB:optimfun:funfun:optimplots:LabelShowingOnlyFirst100Values'))}; |
| 64 | + fval = fval(1:100); |
| 65 | + end |
| 66 | + plotfval = bar(fval); |
| 67 | + title(getString(message('MATLAB:optimfun:funfun:optimplots:TitleCurrentFunctionValues')),'interp','none'); |
| 68 | + set(plotfval,'edgecolor','none') |
| 69 | + set(plotfvalParent,'xlim',[0,1 + length(fval)]) |
| 70 | + xlabel(xlabelText,'interp','none') |
| 71 | + set(plotfval,'Tag','optimplotfval'); |
| 72 | + ylabel(getString(message('MATLAB:optimfun:funfun:optimplots:LabelFunctionValue')),'interp','none') |
| 73 | +else |
| 74 | +% plotfval = findobj(get(gca,'Children'),'Tag','optimplotfval'); |
| 75 | + % display up to the first 100 values |
| 76 | + if numel(fval) > 100 |
| 77 | + fval = fval(1:100); |
| 78 | + end |
| 79 | + set(plotfval,'Ydata',fval); |
| 80 | +end |
0 commit comments