-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
134 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 53 additions & 53 deletions
106
helper_methods/gui_setup/plot/optimplotconstrviolationKsptot.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,53 @@ | ||
function stop = optimplotconstrviolationKsptot(x,optimValues,state,varargin) | ||
% OPTIMPLOTCONSTRVIOLATION Plot max constraint violation at each iteration. | ||
% | ||
% STOP = OPTIMPLOTCONSTRVIOLATION(X,OPTIMVALUES,STATE) plots | ||
% OPTIMVALUES.constrviolation. | ||
% | ||
% Example: | ||
% Create an options structure that will use OPTIMPLOTCONSTRVIOLATION as | ||
% the plot function | ||
% options = optimoptions('fmincon','PlotFcn',@optimplotconstrviolation); | ||
% | ||
% Pass the options into an optimization problem to view the plot | ||
% fmincon(@(x) 3*sin(x(1))+exp(x(2)),[1;1],[],[],[],[],[0 0],[],[],options) | ||
|
||
% Copyright 2006-2015 The MathWorks, Inc. | ||
|
||
persistent plotavailable plotconstrviolation plotconstrviolationParent | ||
stop = false; | ||
|
||
switch state | ||
case 'init' | ||
if isfield(optimValues,'constrviolation') | ||
plotavailable = true; | ||
else | ||
plotavailable = false; | ||
title(getString(message('optim:optimplot:TitleMaxConstrViol', ... | ||
getString(message('optim:optimplot:NotAvailable')))),'interp','none'); | ||
end | ||
case 'iter' | ||
if plotavailable | ||
if optimValues.iteration == 0 | ||
% The 'iter' case is called during the zeroth iteration, | ||
% but it now has values that were empty during the 'init' case | ||
plotconstrviolation = plot(optimValues.iteration,optimValues.constrviolation,'kd', ... | ||
'MarkerFaceColor',[1 0 1]); | ||
plotconstrviolationParent = plotconstrviolation.Parent; | ||
title(getString(message('optim:optimplot:TitleMaxConstrViol', ... | ||
sprintf('%g',optimValues.constrviolation))),'interp','none'); | ||
xlabel(getString(message('optim:optimplot:XlabelIter')),'interp','none'); | ||
ylabel(getString(message('optim:optimplot:YlabelConstrViol')),'interp','none'); | ||
set(plotconstrviolation,'Tag','optimplotconstrviolation'); | ||
else | ||
% plotconstrviolation = findobj(get(gca,'Children'),'Tag','optimplotconstrviolation'); | ||
% plotconstrviolation.Parent = plotconstrviolationParent; | ||
newX = [get(plotconstrviolation,'Xdata') optimValues.iteration]; | ||
newY = [get(plotconstrviolation,'Ydata') optimValues.constrviolation]; | ||
set(plotconstrviolation,'Xdata',newX, 'Ydata',newY); | ||
set(get(plotconstrviolationParent,'Title'),'String', ... | ||
getString(message('optim:optimplot:TitleMaxConstrViol', ... | ||
sprintf('%g',optimValues.constrviolation)))); | ||
end | ||
end | ||
end | ||
function stop = optimplotconstrviolationKsptot(x,optimValues,state,varargin) | ||
% OPTIMPLOTCONSTRVIOLATION Plot max constraint violation at each iteration. | ||
% | ||
% STOP = OPTIMPLOTCONSTRVIOLATION(X,OPTIMVALUES,STATE) plots | ||
% OPTIMVALUES.constrviolation. | ||
% | ||
% Example: | ||
% Create an options structure that will use OPTIMPLOTCONSTRVIOLATION as | ||
% the plot function | ||
% options = optimoptions('fmincon','PlotFcn',@optimplotconstrviolation); | ||
% | ||
% Pass the options into an optimization problem to view the plot | ||
% fmincon(@(x) 3*sin(x(1))+exp(x(2)),[1;1],[],[],[],[],[0 0],[],[],options) | ||
|
||
% Copyright 2006-2015 The MathWorks, Inc. | ||
|
||
persistent plotavailable plotconstrviolation plotconstrviolationParent | ||
stop = false; | ||
|
||
switch state | ||
case 'init' | ||
if isfield(optimValues,'constrviolation') | ||
plotavailable = true; | ||
else | ||
plotavailable = false; | ||
title(getString(message('optim:optimplot:TitleMaxConstrViol', ... | ||
getString(message('optim:optimplot:NotAvailable')))),'interp','none'); | ||
end | ||
case 'iter' | ||
if plotavailable | ||
if optimValues.iteration == 0 | ||
% The 'iter' case is called during the zeroth iteration, | ||
% but it now has values that were empty during the 'init' case | ||
plotconstrviolation = plot(optimValues.iteration,optimValues.constrviolation,'kd', ... | ||
'MarkerFaceColor',[1 0 1]); | ||
plotconstrviolationParent = plotconstrviolation.Parent; | ||
title(getString(message('optim:optimplot:TitleMaxConstrViol', ... | ||
sprintf('%g',optimValues.constrviolation))),'interp','none'); | ||
xlabel(getString(message('optim:optimplot:XlabelIter')),'interp','none'); | ||
ylabel(getString(message('optim:optimplot:YlabelConstrViol')),'interp','none'); | ||
set(plotconstrviolation,'Tag','optimplotconstrviolation'); | ||
else | ||
% plotconstrviolation = findobj(get(gca,'Children'),'Tag','optimplotconstrviolation'); | ||
% plotconstrviolation.Parent = plotconstrviolationParent; | ||
newX = [get(plotconstrviolation,'Xdata') optimValues.iteration]; | ||
newY = [get(plotconstrviolation,'Ydata') optimValues.constrviolation]; | ||
set(plotconstrviolation,'Xdata',newX, 'Ydata',newY); | ||
set(get(plotconstrviolationParent,'Title'),'String', ... | ||
getString(message('optim:optimplot:TitleMaxConstrViol', ... | ||
sprintf('%g',optimValues.constrviolation)))); | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,80 @@ | ||
function stop = optimplotfvalKsptot(~,optimValues,state,varargin) | ||
% OPTIMPLOTFVAL Plot value of the objective function at each iteration. | ||
% | ||
% STOP = OPTIMPLOTFVAL(X,OPTIMVALUES,STATE) plots OPTIMVALUES.fval. If | ||
% the function value is not scalar, a bar plot of the elements at the | ||
% current iteration is displayed. If the OPTIMVALUES.fval field does not | ||
% exist, the OPTIMVALUES.residual field is used. | ||
% | ||
% Example: | ||
% Create an options structure that will use OPTIMPLOTFVAL as the plot | ||
% function | ||
% options = optimset('PlotFcns',@optimplotfval); | ||
% | ||
% Pass the options into an optimization problem to view the plot | ||
% fminbnd(@sin,3,10,options) | ||
|
||
% Copyright 2006-2010 The MathWorks, Inc. | ||
|
||
stop = false; | ||
switch state | ||
case 'iter' | ||
if isfield(optimValues,'fval') | ||
if isscalar(optimValues.fval) | ||
plotscalar(optimValues.iteration,optimValues.fval); | ||
else | ||
plotvector(optimValues.iteration,optimValues.fval); | ||
end | ||
else | ||
plotvector(optimValues.iteration,optimValues.residual); | ||
end | ||
end | ||
|
||
function plotscalar(iteration,fval) | ||
% PLOTSCALAR initializes or updates a line plot of the function value | ||
% at each iteration. | ||
persistent plotfval plotfvalParent | ||
|
||
if iteration == 0 | ||
plotfval = plot(iteration,fval,'kd','MarkerFaceColor',[1 0 1]); | ||
plotfvalParent = plotfval.Parent; | ||
title(getString(message('MATLAB:optimfun:funfun:optimplots:TitleCurrentFunctionValue',sprintf('%g',fval))),'interp','none'); | ||
xlabel(getString(message('MATLAB:optimfun:funfun:optimplots:LabelIteration')),'interp','none'); | ||
set(plotfval,'Tag','optimplotfval'); | ||
ylabel(getString(message('MATLAB:optimfun:funfun:optimplots:LabelFunctionValue')),'interp','none') | ||
else | ||
% plotfval = findobj(get(gca,'Children'),'Tag','optimplotfval'); | ||
% plotfval.Parent = plotfvalParent; | ||
newX = [get(plotfval,'Xdata') iteration]; | ||
newY = [get(plotfval,'Ydata') fval]; | ||
set(plotfval,'Xdata',newX, 'Ydata',newY); | ||
set(get(plotfvalParent,'Title'),'String',getString(message('MATLAB:optimfun:funfun:optimplots:TitleCurrentFunctionValue',sprintf('%g',fval)))); | ||
end | ||
|
||
function plotvector(iteration,fval) | ||
% PLOTVECTOR creates or updates a bar plot of the function values or | ||
% residuals at the current iteration. | ||
persistent plotfval | ||
|
||
if iteration == 0 | ||
xlabelText = getString(message('MATLAB:optimfun:funfun:optimplots:LabelNumberOfFunctionValues0',sprintf('%g',length(fval)))); | ||
% display up to the first 100 values | ||
if numel(fval) > 100 | ||
xlabelText = {xlabelText,getString(message('MATLAB:optimfun:funfun:optimplots:LabelShowingOnlyFirst100Values'))}; | ||
fval = fval(1:100); | ||
end | ||
plotfval = bar(fval); | ||
title(getString(message('MATLAB:optimfun:funfun:optimplots:TitleCurrentFunctionValues')),'interp','none'); | ||
set(plotfval,'edgecolor','none') | ||
set(plotfvalParent,'xlim',[0,1 + length(fval)]) | ||
xlabel(xlabelText,'interp','none') | ||
set(plotfval,'Tag','optimplotfval'); | ||
ylabel(getString(message('MATLAB:optimfun:funfun:optimplots:LabelFunctionValue')),'interp','none') | ||
else | ||
% plotfval = findobj(get(gca,'Children'),'Tag','optimplotfval'); | ||
% display up to the first 100 values | ||
if numel(fval) > 100 | ||
fval = fval(1:100); | ||
end | ||
set(plotfval,'Ydata',fval); | ||
end | ||
function stop = optimplotfvalKsptot(~,optimValues,state,varargin) | ||
% OPTIMPLOTFVAL Plot value of the objective function at each iteration. | ||
% | ||
% STOP = OPTIMPLOTFVAL(X,OPTIMVALUES,STATE) plots OPTIMVALUES.fval. If | ||
% the function value is not scalar, a bar plot of the elements at the | ||
% current iteration is displayed. If the OPTIMVALUES.fval field does not | ||
% exist, the OPTIMVALUES.residual field is used. | ||
% | ||
% Example: | ||
% Create an options structure that will use OPTIMPLOTFVAL as the plot | ||
% function | ||
% options = optimset('PlotFcns',@optimplotfval); | ||
% | ||
% Pass the options into an optimization problem to view the plot | ||
% fminbnd(@sin,3,10,options) | ||
|
||
% Copyright 2006-2010 The MathWorks, Inc. | ||
|
||
stop = false; | ||
switch state | ||
case 'iter' | ||
if isfield(optimValues,'fval') | ||
if isscalar(optimValues.fval) | ||
plotscalar(optimValues.iteration,optimValues.fval); | ||
else | ||
plotvector(optimValues.iteration,optimValues.fval); | ||
end | ||
else | ||
plotvector(optimValues.iteration,optimValues.residual); | ||
end | ||
end | ||
|
||
function plotscalar(iteration,fval) | ||
% PLOTSCALAR initializes or updates a line plot of the function value | ||
% at each iteration. | ||
persistent plotfval plotfvalParent | ||
|
||
if iteration == 0 | ||
plotfval = plot(iteration,fval,'kd','MarkerFaceColor',[1 0 1]); | ||
plotfvalParent = plotfval.Parent; | ||
title(getString(message('MATLAB:optimfun:funfun:optimplots:TitleCurrentFunctionValue',sprintf('%g',fval))),'interp','none'); | ||
xlabel(getString(message('MATLAB:optimfun:funfun:optimplots:LabelIteration')),'interp','none'); | ||
set(plotfval,'Tag','optimplotfval'); | ||
ylabel(getString(message('MATLAB:optimfun:funfun:optimplots:LabelFunctionValue')),'interp','none') | ||
else | ||
% plotfval = findobj(get(gca,'Children'),'Tag','optimplotfval'); | ||
% plotfval.Parent = plotfvalParent; | ||
newX = [get(plotfval,'Xdata') iteration]; | ||
newY = [get(plotfval,'Ydata') fval]; | ||
set(plotfval,'Xdata',newX, 'Ydata',newY); | ||
set(get(plotfvalParent,'Title'),'String',getString(message('MATLAB:optimfun:funfun:optimplots:TitleCurrentFunctionValue',sprintf('%g',fval)))); | ||
end | ||
|
||
function plotvector(iteration,fval) | ||
% PLOTVECTOR creates or updates a bar plot of the function values or | ||
% residuals at the current iteration. | ||
persistent plotfval | ||
|
||
if iteration == 0 | ||
xlabelText = getString(message('MATLAB:optimfun:funfun:optimplots:LabelNumberOfFunctionValues0',sprintf('%g',length(fval)))); | ||
% display up to the first 100 values | ||
if numel(fval) > 100 | ||
xlabelText = {xlabelText,getString(message('MATLAB:optimfun:funfun:optimplots:LabelShowingOnlyFirst100Values'))}; | ||
fval = fval(1:100); | ||
end | ||
plotfval = bar(fval); | ||
title(getString(message('MATLAB:optimfun:funfun:optimplots:TitleCurrentFunctionValues')),'interp','none'); | ||
set(plotfval,'edgecolor','none') | ||
set(plotfvalParent,'xlim',[0,1 + length(fval)]) | ||
xlabel(xlabelText,'interp','none') | ||
set(plotfval,'Tag','optimplotfval'); | ||
ylabel(getString(message('MATLAB:optimfun:funfun:optimplots:LabelFunctionValue')),'interp','none') | ||
else | ||
% plotfval = findobj(get(gca,'Children'),'Tag','optimplotfval'); | ||
% display up to the first 100 values | ||
if numel(fval) > 100 | ||
fval = fval(1:100); | ||
end | ||
set(plotfval,'Ydata',fval); | ||
end |