diff --git a/API/controlsClass.m b/API/controlsClass.m index 620d09259..192ed0ffe 100644 --- a/API/controlsClass.m +++ b/API/controlsClass.m @@ -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 diff --git a/API/enums/displayOptions.m b/API/enums/displayOptions.m index 7ae064489..19b64d72b 100644 --- a/API/enums/displayOptions.m +++ b/API/enums/displayOptions.m @@ -17,7 +17,6 @@ enumeration Off ('off') Iter ('iter') - Notify ('notify') Final ('final') end end diff --git a/minimisers/simplex/fMinSearch.m b/minimisers/simplex/fMinSearch.m index d843d86c2..5cea857ec 100644 --- a/minimisers/simplex/fMinSearch.m +++ b/minimisers/simplex/fMinSearch.m @@ -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',[]); @@ -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'; @@ -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 @@ -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); @@ -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 @@ -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 @@ -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 @@ -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 @@ -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); @@ -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) @@ -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 - - diff --git a/minimisers/simplex/runSimplex.m b/minimisers/simplex/runSimplex.m index c002543bd..bb15f6dd3 100644 --- a/minimisers/simplex/runSimplex.m +++ b/minimisers/simplex/runSimplex.m @@ -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 diff --git a/tests/testControlsClass.m b/tests/testControlsClass.m index 18d8cc009..426e3d76b 100644 --- a/tests/testControlsClass.m +++ b/tests/testControlsClass.m @@ -51,8 +51,6 @@ function testDisplay(testCase) testCase.verifyEqual(testCase.controls.display, displayOptions.Off.value, 'set.display method is not working') testCase.controls.display = displayOptions.Iter.value; testCase.verifyEqual(testCase.controls.display, displayOptions.Iter.value, 'set.display method is not working') - testCase.controls.display = displayOptions.Notify; - testCase.verifyEqual(testCase.controls.display, displayOptions.Notify.value, 'set.display method is not working') testCase.verifyError(@setDisplay, exceptions.invalidOption.errorID); % bad display option function setDisplay testCase.controls.display = 'any'; @@ -424,7 +422,7 @@ function testSetProcedureWithDream(testCase) 'numSimulationPoints', 1000,... 'resampleMinAngle', 0.1,... 'resampleNPoints', 10,... - 'display', displayOptions.Notify.value); + 'display', displayOptions.Final.value); testCase.verifyEqual(testCase.controls.procedure, procedures.Dream.value, 'setProcedure method is not working'); testCase.verifyEqual(testCase.controls.nSamples, 70000, 'setProcedure method is not working'); testCase.verifyEqual(testCase.controls.nChains, 15, 'setProcedure method is not working'); @@ -436,7 +434,7 @@ function testSetProcedureWithDream(testCase) testCase.verifyEqual(testCase.controls.numSimulationPoints, 1000, 'setProcedure method is not working'); testCase.verifyEqual(testCase.controls.resampleMinAngle, 0.1, 'setProcedure method is not working'); testCase.verifyEqual(testCase.controls.resampleNPoints, 10, 'setProcedure method is not working'); - testCase.verifyEqual(testCase.controls.display, displayOptions.Notify.value, 'setProcedure method is not working'); + testCase.verifyEqual(testCase.controls.display, displayOptions.Final.value, 'setProcedure method is not working'); % Test passing invalid parameter values for dream procedure testCase.verifyError(@() testCase.controls.setProcedure(procedures.Dream.value, 'boundHandling', 'invalid'), exceptions.invalidOption.errorID); @@ -472,7 +470,7 @@ function testSetProcedureWithNS(testCase) 'numSimulationPoints', 1000,... 'resampleMinAngle', 0.1,... 'resampleNPoints', 10,... - 'display', displayOptions.Notify.value); + 'display', displayOptions.Final.value); testCase.verifyEqual(testCase.controls.procedure, procedures.NS.value, 'setProcedure method is not working'); testCase.verifyEqual(testCase.controls.nLive, 700, 'setProcedure method is not working'); testCase.verifyEqual(testCase.controls.nMCMC, 5, 'setProcedure method is not working'); @@ -482,7 +480,7 @@ function testSetProcedureWithNS(testCase) testCase.verifyEqual(testCase.controls.numSimulationPoints, 1000, 'setProcedure method is not working'); testCase.verifyEqual(testCase.controls.resampleMinAngle, 0.1, 'setProcedure method is not working'); testCase.verifyEqual(testCase.controls.resampleNPoints, 10, 'setProcedure method is not working'); - testCase.verifyEqual(testCase.controls.display, displayOptions.Notify.value, 'setProcedure method is not working'); + testCase.verifyEqual(testCase.controls.display, displayOptions.Final.value, 'setProcedure method is not working'); % Test passing wrong parameter for NS procedure testCase.verifyError(@() testCase.controls.setProcedure(procedures.NS.value, 'funcTolerance', 1e-6), exceptions.invalidOption.errorID); % Simplex Parameter @@ -521,7 +519,7 @@ function testSetProcedureWithDE(testCase) 'numSimulationPoints', 1000,... 'resampleMinAngle', 0.1,... 'resampleNPoints', 10,... - 'display', displayOptions.Notify.value,... + 'display', displayOptions.Final.value,... 'updateFreq', 1,... 'updatePlotFreq', 4); testCase.verifyEqual(testCase.controls.procedure, procedures.DE.value, 'setProcedure method is not working'); @@ -535,7 +533,7 @@ function testSetProcedureWithDE(testCase) testCase.verifyEqual(testCase.controls.numSimulationPoints, 1000, 'setProcedure method is not working'); testCase.verifyEqual(testCase.controls.resampleMinAngle, 0.1, 'setProcedure method is not working'); testCase.verifyEqual(testCase.controls.resampleNPoints, 10, 'setProcedure method is not working'); - testCase.verifyEqual(testCase.controls.display, displayOptions.Notify.value, 'setProcedure method is not working'); + testCase.verifyEqual(testCase.controls.display, displayOptions.Final.value, 'setProcedure method is not working'); testCase.verifyEqual(testCase.controls.updateFreq, 1, 'setProcedure method is not working'); testCase.verifyEqual(testCase.controls.updatePlotFreq, 4, 'setProcedure method is not working'); @@ -574,7 +572,7 @@ function testSetProcedureWithSimplex(testCase) 'numSimulationPoints', 1000,... 'resampleMinAngle', 0.1,... 'resampleNPoints', 10,... - 'display', displayOptions.Notify.value); + 'display', displayOptions.Final.value); testCase.verifyEqual(testCase.controls.procedure, procedures.Simplex.value, 'setProcedure method is not working'); testCase.verifyEqual(testCase.controls.xTolerance, 3e-6, 'setProcedure method is not working'); testCase.verifyEqual(testCase.controls.funcTolerance, 4e-6, 'setProcedure method is not working'); @@ -586,7 +584,7 @@ function testSetProcedureWithSimplex(testCase) testCase.verifyEqual(testCase.controls.numSimulationPoints, 1000, 'setProcedure method is not working'); testCase.verifyEqual(testCase.controls.resampleMinAngle, 0.1, 'setProcedure method is not working'); testCase.verifyEqual(testCase.controls.resampleNPoints, 10, 'setProcedure method is not working'); - testCase.verifyEqual(testCase.controls.display, displayOptions.Notify.value, 'setProcedure method is not working'); + testCase.verifyEqual(testCase.controls.display, displayOptions.Final.value, 'setProcedure method is not working'); % Test passing wrong parameter for Simplex procedure testCase.verifyError(@() testCase.controls.setProcedure(procedures.Simplex.value, 'crossoverProbability', 0.7), exceptions.invalidOption.errorID); % DE Parameter @@ -611,13 +609,13 @@ function testSetProcedureWithCalculate(testCase) 'numSimulationPoints', 1000,... 'resampleMinAngle', 0.1,... 'resampleNPoints', 10,... - 'display', displayOptions.Notify.value); + 'display', displayOptions.Final.value); testCase.verifyEqual(testCase.controls.procedure, procedures.Calculate.value, 'setProcedure method is not working'); testCase.verifyEqual(testCase.controls.parallel, parallelOptions.Contrasts.value, 'setProcedure method is not working'); testCase.verifyEqual(testCase.controls.numSimulationPoints, 1000, 'setProcedure method is not working'); testCase.verifyEqual(testCase.controls.resampleMinAngle, 0.1, 'setProcedure method is not working'); testCase.verifyEqual(testCase.controls.resampleNPoints, 10, 'setProcedure method is not working'); - testCase.verifyEqual(testCase.controls.display, displayOptions.Notify.value, 'setProcedure method is not working'); + testCase.verifyEqual(testCase.controls.display, displayOptions.Final.value, 'setProcedure method is not working'); % Test passing wrong parameter for Calculate procedure testCase.verifyError(@() testCase.controls.setProcedure(procedures.Calculate.value, 'maxIterations', 100), exceptions.invalidOption.errorID); % Simplex Parameter