Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/runTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Set up MATLAB
uses: matlab-actions/setup-matlab@v2
with:
release: R2023a
release: R2023b
products: Parallel_Computing_Toolbox
- name: Build Mex and Run Tests
uses: matlab-actions/run-command@v2
Expand Down
2 changes: 1 addition & 1 deletion API/controlsClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
% resampleNPoints : whole number, default: 50
% The number of initial points to use for resampling.
% display : displayOptions, default: displayOptions.Iter
% How much RAT should print to the terminal. Can be 'off', 'iter', 'notify', or 'final'.
% How much RAT should print to the terminal. Can be 'off', 'iter', or 'final'.
% updateFreq : whole number, default: 1
% [SIMPLEX, DE] Number of iterations between printing progress updates to the terminal.
% updatePlotFreq : whole number, default: 20
Expand Down
1 change: 0 additions & 1 deletion API/enums/displayOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
enumeration
Off ('off')
Iter ('iter')
Notify ('notify')
Final ('final')
end
end
194 changes: 9 additions & 185 deletions minimisers/simplex/fMinSearch.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
%
msg = 'ok';

defaultopt = struct('Display','notify','MaxIter','200*numberOfVariables',...
defaultopt = struct('Display','iter','MaxIter','200*numberOfVariables',...
'MaxFunEvals','200*numberOfVariables','TolX',1e-4,'TolFun',1e-4, ...
'FunValCheck','off','OutputFcn',[],'PlotFcns',[]);

Expand All @@ -65,18 +65,14 @@
maxiter = optimget(options,'MaxIter',defaultopt,'fast');

switch dis % Changed from TMW fminsearch
case {'notify','notify-detailed'}
prnt = 1;
case {'none','off'}
prnt = 0;
case {'iter','iter-detailed'}
prnt = 3;
case {'final','final-detailed'}
prnt = 2;
% case 'simplex'
% prnt = 4;
otherwise
case {'final','final-detailed'}
prnt = 1;
otherwise
prnt = 2;
end

header = ' Iteration Func-count min f(x) Procedure';
Expand Down Expand Up @@ -112,68 +108,17 @@
how = '';
% Initial simplex setup continues later

% Initialize the output and plot functions.
%
% ----------------------------------------
% RAT doesn't use output or plot functions...
%
% --------------------- AVH -----------

% if haveoutputfcn || haveplotfcn
% [xOutputfcn, optimValues, stop] = callOutputAndPlotFcns(outputfcn,plotfcns,v(:,1),xOutputfcn,'init',itercount, ...
% func_evals, how, fv(:,1),varargin{:});
% if stop
% [x,fval,exitflag,output] = cleanUpInterrupt(xOutputfcn,optimValues);
% if prnt > 0
% fprintf('%s \n', output.message)
% end
% return;
% end
% end

% Print out initial f(x) as 0th iteration
if prnt == 3
if prnt == 2
triggerEvent(coderEnums.eventTypes.Message, sprintf('\n%s\n', header));
triggerEvent(coderEnums.eventTypes.Message, ...
sprintf(' %5.0f %5.0f %12.6g %s\n', itercount, func_evals, fv(1), how));
% elseif prnt == 4
% Option never used in RAT


% formatsave.format = get(0,'format');
% formatsave.formatspacing = get(0,'formatspacing');
% % reset format when done
% oc1 = onCleanup(@()set(0,'format',formatsave.format));
% oc2 = onCleanup(@()set(0,'formatspacing',formatsave.formatspacing));
% format compact
% format short e
% fprintf('%s \n', ' ')
% fprintf('%s \n', how)
% fprintf('%s \n', 'v = ')
% fprintf('%g \n', v)
% fprintf('%s \n', 'fv = ')
% fprintf('%g \n', fv)
% fprintf('%s \n', 'func_evals = ')
% fprintf('%g \n', func_evals)
end

if doPlotEvent
triggerEvent(coderEnums.eventTypes.Plot, result, problemStruct);
end

% OutputFcn and PlotFcns call
% if haveoutputfcn || haveplotfcn
% [xOutputfcn, optimValues, stop] = callOutputAndPlotFcns(outputfcn,plotfcns,v(:,1),xOutputfcn,'iter',itercount, ...
% func_evals, how, fv(:,1),varargin{:});
% if stop % Stop per user request.
% [x,fval,exitflag,output] = cleanUpInterrupt(xOutputfcn,optimValues);
% if prnt > 0
% fprintf('%s \n', output.message)
% end
% return;
% end
% end

% Continue setting up the initial simplex.
% Following improvement suggested by L.Pfeffer at Stanford
usual_delta = 0.05; % 5 percent deltas for non-zero terms
Expand All @@ -200,18 +145,9 @@
how = 'initial simplex';
itercount = itercount + 1;
func_evals = n+1;
if prnt == 3 && rem(itercount, controls.updateFreq) == 0
if prnt == 2 && rem(itercount, controls.updateFreq) == 0
triggerEvent(coderEnums.eventTypes.Message, ...
sprintf(' %5.0f %5.0f %12.6g %s\n', itercount, func_evals, fv(1), how));
% elseif prnt == 4
% fprintf('%s \n', ' ')
% fprintf('%s \n', how)
% fprintf('%s \n', 'v = ')
% fprintf('%g \n', v)
% fprintf('%s \n', 'fv = ')
% fprintf('%g \n', fv)
% fprintf('%s \n', 'func_evals = ')
% fprintf('%g \n', func_evals)
end
if doPlotEvent && rem(itercount, controls.updatePlotFreq) == 0
triggerEvent(coderEnums.eventTypes.Plot, result, problemStruct);
Expand All @@ -220,19 +156,6 @@
[x, fval, exitflag, output] = cleanUpInterrupt(v(:,1), fv(:,1), itercount, func_evals, prnt);
return
end
% OutputFcn and PlotFcns call
% if haveoutputfcn || haveplotfcn
% [xOutputfcn, optimValues, stop] = callOutputAndPlotFcns(outputfcn,plotfcns,v(:,1),xOutputfcn,'iter',itercount, ...
% func_evals, how, fv(:,1),varargin{:});
% if stop % Stop per user request.
% [x,fval,exitflag,output] = cleanUpInterrupt(xOutputfcn,optimValues);
% if prnt > 0
% fprintf('%s \n', output.message)
% end
% return;
% end
% end
% exitflag = 1;

% Main algorithm: iterate until
% (a) the maximum coordinate difference between the current best point and the
Expand Down Expand Up @@ -324,17 +247,8 @@
[fv,j] = sort(fv);
v = v(:,j);
itercount = itercount + 1;
if prnt == 3 && rem(itercount, controls.updateFreq) == 0
if prnt == 2 && rem(itercount, controls.updateFreq) == 0
triggerEvent(coderEnums.eventTypes.Message, sprintf(' %5.0f %5.0f %12.6g %s\n', itercount, func_evals, fv(1), how));
% elseif prnt == 4
% fprintf('%s \n', ' ')
% fprintf('%s \n', num2str(how))
% fprintf('%s \n', 'v = ')
% fprintf('%s \n', v)
% fprintf('%s \n', 'fv = ')
% fprintf('%s \n', fv)
% fprintf('%s \n', 'func_evals = ')
% fprintf('%s \n', num2str(func_evals))
end
controls.calcSLD = false;
if doPlotEvent && rem(itercount, controls.updatePlotFreq) == 0
Expand All @@ -344,24 +258,12 @@
[x, fval, exitflag, output] = cleanUpInterrupt(v(:,1), fv(:,1), itercount, func_evals, prnt);
return
end
% OutputFcn and PlotFcns call
% if haveoutputfcn || haveplotfcn
% [xOutputfcn, optimValues, stop] = callOutputAndPlotFcns(outputfcn,plotfcns,v(:,1),xOutputfcn,'iter',itercount, ...
% func_evals, how, fv(:,1),varargin{:});
% if stop % Stop per user request.
% [x,fval,exitflag,output] = cleanUpInterrupt(xOutputfcn,optimValues);
% if prnt > 0
% fprintf('%s \n', output.message)
% end
% return;
% end
% end
end % while

x(:) = v(:,1);
fval = fv(:,1);

if prnt == 3 && rem(itercount, controls.updateFreq) ~= 0
if prnt == 2 && rem(itercount, controls.updateFreq) ~= 0
% This should ensure the final result is printed at the end of a run irrespective of update frequency
triggerEvent(coderEnums.eventTypes.Message, sprintf(' %5.0f %5.0f %12.6g %s\n', itercount, func_evals, fv(1), how));
end
Expand All @@ -370,11 +272,6 @@
triggerEvent(coderEnums.eventTypes.Plot, result, problemStruct);
end

% OutputFcn and PlotFcns call
% if haveoutputfcn || haveplotfcn
% callOutputAndPlotFcns(outputfcn,plotfcns,x,xOutputfcn,'done',itercount, func_evals, how, fval, varargin{:});
% end

if func_evals >= maxfun
printMsg = prnt > 0;
if buildOutputStruct || printMsg
Expand All @@ -390,7 +287,7 @@
end
exitflag = 0;
else
printMsg = prnt > 1;
printMsg = prnt > 0;
if buildOutputStruct || printMsg
msg = sprintf('Exiting - X satisfies termination criteria: TolX %e, TolF %e',tolx,tolf);

Expand All @@ -409,45 +306,6 @@
triggerEvent(coderEnums.eventTypes.Message, sprintf('\n%s\n', msg));
end
end
%--------------------------------------------------------------------------
% function [xOutputfcn, optimValues, stop] = callOutputAndPlotFcns(outputfcn,plotfcns,x,xOutputfcn,state,iter,...
% numf,how,f,varargin)
% CALLOUTPUTANDPLOTFCNS assigns values to the struct OptimValues and then calls the
% outputfcn/plotfcns.
%
% state - can have the values 'init','iter', or 'done'.

% For the 'done' state we do not check the value of 'stop' because the
% optimization is already done.
% optimValues.iteration = iter;
% optimValues.funccount = numf;
% optimValues.fval = f;
% optimValues.procedure = how;

% xOutputfcn(:) = x; % Set x to have user expected size
% stop = false;
% state = char(state);
% Call output functions

% ---- Remove these from function for compile - AVH
% if ~isempty(outputfcn)
% switch state
% case {'iter','init'}
% stop = callAllOptimOutputFcns(outputfcn,xOutputfcn,optimValues,state,varargin{:}) || stop;
% case 'done'
% callAllOptimOutputFcns(outputfcn,xOutputfcn,optimValues,state,varargin{:});
% end
% end
% % Call plot functions
% if ~isempty(plotfcns)
% switch state
% case {'iter','init'}
% stop = callAllOptimPlotFcns(plotfcns,xOutputfcn,optimValues,state,varargin{:}) || stop;
% case 'done'
% callAllOptimPlotFcns(plotfcns,xOutputfcn,optimValues,state,varargin{:});
% end
% end
% -----------------------------------

%--------------------------------------------------------------------------
function [x, fval, exitflag, output] = cleanUpInterrupt(optX, optVal, iteration, funccount, display)
Expand All @@ -462,37 +320,3 @@
triggerEvent(coderEnums.eventTypes.Message, sprintf('\n%s\n', output.message));
end
end

%--------------------------------------------------------------------------
% function f = checkfun(x,userfcn,varargin)
% CHECKFUN checks for complex or NaN results from userfcn.

% f = userfcn(x,varargin{:});
% Note: we do not check for Inf as FMINSEARCH handles it naturally.
% if isnan(f)
% error('MATLAB:fminsearch:checkfun:NaNFval','Target function is NaN');
% elseif ~isreal(f)
% error('MATLAB:fminsearch:checkfun:ComplexFval',...
% getString(message('MATLAB:optimfun:fminsearch:checkfun:ComplexFval', localChar( userfcn ))));
% error(sprintf('Target function is complex'));
% end

%--------------------------------------------------------------------------
% function strfcn = localChar(fcn)
% % Convert the fcn to a character array for printing
%
% if ischar(fcn)
% strfcn = fcn;
% elseif isstring(fcn) || isa(fcn,'inline')
% strfcn = char(fcn);
% elseif isa(fcn,'function_handle')
% strfcn = func2str(fcn);
% else
% try
% strfcn = char(fcn);
% catch
% strfcn = getString(message('MATLAB:optimfun:fminsearch:NameNotPrintable'));
% end
% end


2 changes: 0 additions & 2 deletions minimisers/simplex/runSimplex.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
dis = 'none';
case coderEnums.displayOptions.Iter
dis = 'iter';
case coderEnums.displayOptions.Notify
dis = 'notify';
case coderEnums.displayOptions.Final
dis = 'final';
otherwise
Expand Down
Loading
Loading