Skip to content

Commit

Permalink
Refactors the text progress bar so it can be disabled when controls.d…
Browse files Browse the repository at this point in the history
…isplay is off
  • Loading branch information
StephenNneji committed Aug 6, 2024
1 parent bf67b6f commit cd005d8
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 51 deletions.
4 changes: 2 additions & 2 deletions 3rdParty/mcmcstat/%mcmcrun_compile.m
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@

rej=0; reju=0; ii=1; rejl = 0;
%% setup waitbar
if (wbarupd && display); triggerEvent(coderEnums.eventTypes.Progress, 'init', 0); end
if (wbarupd && display); triggerEvent(coderEnums.eventTypes.Progress, 'Bayes', 0); end

% covariance update uses these to store previous values
covchain = []; meanchain = []; wsum = initqcovn; lasti = 0;
Expand Down Expand Up @@ -914,7 +914,7 @@
end
end

triggerEvent(coderEnums.eventTypes.Progress, 'end', 1);
triggerEvent(coderEnums.eventTypes.Progress, 'Bayes', 1);



Expand Down
4 changes: 2 additions & 2 deletions 3rdParty/mcmcstat/mcmcrun.m
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@

rej=0; reju=0; ii=1; rejl = 0;
%% setup waitbar
if wbarupd; triggerEvent(coderEnums.eventTypes.Progress, 'init', 0); end
if wbarupd; triggerEvent(coderEnums.eventTypes.Progress, 'Bayes', 0); end

% covariance update uses these to store previous values
covchain = []; meanchain = []; wsum = initqcovn; lasti = 0;
Expand Down Expand Up @@ -841,7 +841,7 @@
end
end

triggerEvent(coderEnums.eventTypes.Progress, 'end', 1);
triggerEvent(coderEnums.eventTypes.Progress, 'Bayes', 1);



Expand Down
4 changes: 2 additions & 2 deletions 3rdParty/mcmcstat/mcmcrun_compile.m
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@

rej=0; reju=0; ii=1; rejl = 0;
%% setup waitbar
if wbarupd; triggerEvent(coderEnums.eventTypes.Progress, 'init', 0); end
if wbarupd; triggerEvent(coderEnums.eventTypes.Progress, 'Bayes', 0); end

% covariance update uses these to store previous values
covchain = []; meanchain = []; wsum = initqcovn; lasti = 0;
Expand Down Expand Up @@ -887,7 +887,7 @@
end
end

triggerEvent(coderEnums.eventTypes.Progress, 'end', 1);
triggerEvent(coderEnums.eventTypes.Progress, 'Bayes', 1);



Expand Down
4 changes: 2 additions & 2 deletions 3rdParty/mcmcstat/mcmcrun_compile_scaled.m
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@

rej=0; reju=0; ii=1; rejl = 0;
%% setup waitbar
if wbarupd; triggerEvent(coderEnums.eventTypes.Progress, 'init', 0); end
if wbarupd; triggerEvent(coderEnums.eventTypes.Progress, 'Bayes', 0); end

% covariance update uses these to store previous values
covchain = []; meanchain = []; wsum = initqcovn; lasti = 0;
Expand Down Expand Up @@ -887,7 +887,7 @@
end
end

triggerEvent(coderEnums.eventTypes.Progress, 'end', 1);
triggerEvent(coderEnums.eventTypes.Progress, 'Bayes', 1);



Expand Down
9 changes: 5 additions & 4 deletions API/RAT.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
end

% Call the main RAT routine...

display = ~strcmpi(controls.display, displayOptions.Off.value);
textProgressBar(0, 0, display);
% If display is not silent print a line confirming RAT is starting
if ~strcmpi(controls.display, displayOptions.Off.value)
if display
fprintf('Starting RAT ________________________________________________________________________________________________\n\n');
end

tic
[problemStruct,result,bayesResults] = RATMain_mex(problemStruct,problemCells,problemLimits,controls,priors);

if ~strcmpi(controls.display, displayOptions.Off.value)
if display
toc
end

textProgressBar(0, 0, true);
if any(strcmpi(controls.procedure, {procedures.NS.value, procedures.Dream.value}))
result = mergeStructs(result, bayesResults);
end
Expand Down
2 changes: 1 addition & 1 deletion API/controlsClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
% Target stopping tolerance for Nested Sampler (Default: 0.1)
nsTolerance = 0.1

% Total number of samples for DREAM (Default: 50000)
% Total number of samples for DREAM (Default: 20000)
nSamples = 20000;
% Number of MCMC chains (Default: 10)
nChains = 10
Expand Down
8 changes: 4 additions & 4 deletions minimisers/DREAM/functions/ratDREAM.m
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@
% Now print to screen all the settings
controls = ratInputs.controls;
if ~strcmpi(controls.display, coderEnums.displayOptions.Off)
fprintf('------------------ Summary of the main settings used ------------------');
fprintf('------------------ Summary of the main settings used ------------------\n');
disp(DREAMPar);
fprintf('-----------------------------------------------------------------------');
fprintf('-----------------------------------------------------------------------\n');
end
% Now check how the measurement sigma is arranged (estimated or defined)
%
Expand All @@ -180,7 +180,7 @@
[chain,output,X,fx,CR,pCR,lCR,delta_tot,log_L] = initializeDREAM(DREAMPar,paramInfo,Meas_info,chain,output,log_L,ratInputs);

% Initialize waitbar.
triggerEvent(coderEnums.eventTypes.Progress, 'init', 0);
triggerEvent(coderEnums.eventTypes.Progress, 'DREAM', 0);
totaccept = 0; tic;

% Now start iteration ...
Expand Down Expand Up @@ -297,6 +297,6 @@
output.iloc = iloc;

% Close the waitbar
triggerEvent(coderEnums.eventTypes.Progress, 'end', 1);
triggerEvent(coderEnums.eventTypes.Progress, 'DREAM', 1);
%close(h);
end
84 changes: 50 additions & 34 deletions utilities/textProgressBar.m
Original file line number Diff line number Diff line change
@@ -1,35 +1,51 @@
function textProgressBar(curm,pct)

persistent lastNchar

strDotsMax = 40;

if strcmpi(curm,'init')
%fprintf('\n');
lastNchar = 0;
return;
end

if strcmpi(curm,'end')
fprintf('\n');
return;
end

if isempty(lastNchar)
lastNchar = 0;
end

%curm = 'progress';

nDots = floor(pct * strDotsMax);
progressmsg = ['[' repmat('*',1,nDots) repmat('.',1,strDotsMax-nDots) ']'];

% progressmsg=[183-uint16((1:40)<=(pct*40)).*(183-'*') ''];
% %curmtxt=sprintf('% 9.3g\n',curm(1:min(end,20),1));
progressmsg=sprintf('\n %s %5.1f%% %s',curm,(pct*100),progressmsg);

fprintf('%s%s',repmat(sprintf('\b'),1,lastNchar),progressmsg);
drawnow
lastNchar=length(progressmsg);

function textProgressBar(curm, pct, varargin)
% Draws a progress bar in the console. The inputs are the message (char array) and
% percentage progress expressed as a decimal (i.e., between 0 and 1).
% Optionally a boolean value can be provided to disable the progress
% bar.
%
% textProgressBar("DREAM", 0.5, false)
persistent lastNchar
persistent display

if ~isempty(varargin)
display = varargin{1};
elseif isempty(display)
display = true;
end

if ~display
return;
end

strDotsMax = 40;

if pct == 0
%fprintf('\n');
lastNchar = 0;
return;
end

if lastNchar==0 && pct>=1
return
end

if isempty(lastNchar)
lastNchar = 0;
end

nDots = floor(pct * strDotsMax);
progressmsg = ['[' repmat('*',1,nDots) repmat('.',1,strDotsMax-nDots) ']'];

progressmsg=sprintf('\n%s %5.1f%% %s',curm,fix(pct*1000)/10,progressmsg);

fprintf('%s%s',repmat(sprintf('\b'),1,lastNchar),progressmsg);
drawnow
lastNchar=length(progressmsg);

if pct == 1
fprintf('\n');
lastNchar = 0;
return;
end
end

0 comments on commit cd005d8

Please sign in to comment.