Skip to content

Commit

Permalink
Full compile of some minimizers (#161)
Browse files Browse the repository at this point in the history
* Some initial corrections to DREAM for compile

* Most 'screener' identified problems with DREAM resolved

* All issues found via 'coder.screener('RATMain')' now cleared

* Fixed assignment problem in Gelman

* Most compile issues now cleared

* Fixed pre-allocation issue in refPrcentileconfInts

* Full compile working with Bayes commented out. Most Bayes issues theared though...

* Half way through re-configuring 'bayesOutputs' to be more sensible

* Cleared up to output structs. Now rationalising 'bayesOutputs'

* Almost compiles. A slight problem with assignment size of 'sldXdata' when assigning outputs in 'runDREAM'

* Fixes so the code compiles

* Dream now runs to completion, but this has messed up the outputs (ref_yVals{n})

* Full compile now working correctly

* Fixes unit test and removes unneeded files

* Addresses review comments

* Fixes kmeans

---------

Co-authored-by: arwelHughes <[email protected]>
  • Loading branch information
StephenNneji and arwelHughes authored Oct 20, 2023
1 parent 328e024 commit 907cf9d
Show file tree
Hide file tree
Showing 99 changed files with 1,305 additions and 633 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ __pycache__/
*.dll
*.lib
*.dylib
*.prj
2 changes: 1 addition & 1 deletion 3rdParty/paramonte/pmLogFunction.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

problem = unpackparams(problem,control);

[outProblem,results] = reflectivityCalculationWrapper(problem,cells,limits,control);
[outProblem,results] = reflectivityCalculation(problem,cells,limits,control);
chi = outProblem.calculations.sum_chi;
logFuncVal = -chi/2;

Expand Down
2 changes: 1 addition & 1 deletion 3rdParty/paramonte/processParamonteRuns.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
bayesOutputs.data = problemDefCells{2};
bayesOutputs.results.mean = mean(unscaledChain);

[problemDef,outProblemStruct,result,bayesResults] = processBayes_newMethod(bayesOutputs,allProblem);
[problemDef,outProblemStruct,result,bayesResults] = processBayes(bayesOutputs,allProblem);


result = parseResultToStruct(outProblemStruct,result);
Expand Down
2 changes: 1 addition & 1 deletion 3rdParty/paramonte/runParamonte.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
% output.bestPars = mean(unscaledChain);
% output.data = data;
%
% [problemDef,outProblem,result,bayesResults] = processBayes_newMethod(output,outProblem);
% [problemDef,outProblem,result,bayesResults] = processBayes(output,outProblem);

% pmpdOut = pmpd;

Expand Down
4 changes: 2 additions & 2 deletions API/RAT.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
end

tic
[outProblemStruct,problem,result,bayesResults] = RATMain(problemDef,problemDefCells,problemDefLimits,controls,priors);
[outProblemStruct,problem,result,bayesResults] = RATMain_mex(problemDef,problemDefCells,problemDefLimits,controls,priors);
sendTextOutput(sprintf('\n'));

if ~strcmpi(controls.display,'off')
Expand All @@ -92,7 +92,7 @@
originalProc = controls.proc;
controls.calcSld = 1;
controls.proc = 'calculate';
[outProblemStruct,problem,result,~] = RATMain(outProblemStruct,problemDefCells,problemDefLimits,controls,priors);
[outProblemStruct,problem,result,~] = RATMain_mex(outProblemStruct,problemDefCells,problemDefLimits,controls,priors);
controls.proc = originalProc;
end

Expand Down
40 changes: 26 additions & 14 deletions API/RATMain.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
function [outProblemDef,problem,results,bayesResults] = RATMain(problemDef,problemDefCells,problemDefLimits,controls,priors)


result = cell(6,1);
result = cell(1,1);
result{1} = {1};
results = repmat(result,1,6);

numberOfContrasts = problemDef.numberOfContrasts;
preAlloc = zeros(numberOfContrasts,1);

Expand All @@ -13,22 +16,31 @@
'nbsubs',preAlloc,...
'resolutions',preAlloc,...
'calculations',struct('all_chis',preAlloc,'sum_chi',0),...
'allSubRough',preAlloc);
'allSubRough',preAlloc,...
'resample',preAlloc);

% Make empty bayes results even though we may not fill it (for output purposes)
bayesResults.res = [];
bayesResults.chain = [];
bayesResults.s2chain = [];
bayesResults.ssChain = [];
bayesResults.bestPars = [];
if strcmpi(problemDef.TF,'domains')
domains = true;
else
domains = false;
end
bayesResults = makeEmptyBayesResultsStruct(1e3, problemDef.numberOfContrasts, domains, controls.nChains);
% bayesResults = struct('bayesRes',[],...
% 'chain',[],...
% 's2chain',[],...
% 'ssChain',[],...
% 'bestPars_Mean',[],...
% 'bestFitsMean',[],...
% 'predLims',[],...
% 'parConfInts',[]);

outProblemDef = problemDef;

%Decide what we are doing....
action = controls.proc;
switch lower(action)
case 'calculate' %Just a single reflectivity calculation
[problem,results] = reflectivityCalculationWrapper(problemDef,problemDefCells,problemDefLimits,controls);
[problem,results] = reflectivityCalculation(problemDef,problemDefCells,problemDefLimits,controls);
outProblemDef = problemDef;
case 'simplex'
if ~strcmpi(controls.display,'off')
Expand All @@ -40,11 +52,11 @@
sendTextOutput(sprintf('\nRunning Differential Evolution\n\n'));
end
[outProblemDef,problem,results] = runDE(problemDef,problemDefCells,problemDefLimits,controls);
case 'ns'
if ~strcmpi(controls.display,'off')
sendTextOutput(sprintf('\nRunning Nested Sampler\n\n'));
end
[outProblemDef,problem,results,bayesResults] = runNestedSampler(problemDef,problemDefCells,problemDefLimits,controls);
% case 'ns'
% if ~strcmpi(controls.display,'off')
% sendTextOutput(sprintf('\nRunning Nested Sampler\n\n'));
% end
% [outProblemDef,problem,results,bayesResults] = runNestedSampler(problemDef,problemDefCells,problemDefLimits,controls);
case 'dream'
if ~strcmpi(controls.display,'off')
sendTextOutput(sprintf('\nRunning DREAM\n\n'));
Expand Down
20 changes: 16 additions & 4 deletions API/parseClassToStructs.m
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,27 @@
currentPrior = priorFields{i};
for j = 1:size(priors.(currentPrior), 1)
allPriors{cellCount,1} = priors.(currentPrior){j}{1};
allPriors{cellCount,2} = priors.(currentPrior){j}{2};
allPriors{cellCount,3} = num2str(priors.(currentPrior){j}{3});
allPriors{cellCount,4} = num2str(priors.(currentPrior){j}{4});

% Check prior type.....
thisType = priors.(currentPrior){j}{2};

if strcmpi(thisType,'uniform')
priorType = 1;
elseif strcmpi(thisType,'gaussian')
priorType = 2;
else
priorType = 3;
end
allPriors{cellCount,2} = priorType;

allPriors{cellCount,3} = priors.(currentPrior){j}{3};
allPriors{cellCount,4} = priors.(currentPrior){j}{4};
cellCount = cellCount + 1;
end
end

priors.priorNames = allPriors(:, 1);
priors.priorVals = allPriors(:, 2:end);
priors.priorVals = cell2mat(allPriors(:, 2:end)); % Note move to double now for this...


%% Split up the contrastBacks array
Expand Down
6 changes: 4 additions & 2 deletions API/parseResultToStruct.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
result.allLayers = results{6}; % Resampled layers

result.calculationResults = problem.calculations;
problem = rmfield(problem,'calculations');

% For compile, we can't remove a field, so just clear it for now...
%problem = rmfield(problem,'calculations');
result.contrastParams = problem;

end
end
16 changes: 11 additions & 5 deletions API/textProgressBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ function textProgressBar(curm,pct)

persistent lastNchar

strDotsMax = 40;

if strcmpi(curm,'init')
%fprintf('\n');
lastNchar = 0;
Expand All @@ -18,12 +20,16 @@ function textProgressBar(curm,pct)
end

%curm = 'progress';
progressmsg=[183-uint8((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(char(8),1,lastNchar),progressmsg);

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);

end

1 change: 1 addition & 0 deletions addPaths.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
eventCompilePath;
fullfile(root,'compile','customWrapper');
fullfile(root,'compile','reflectivityCalculation');
fullfile(root,'compile','fullCompile');
fullfile(root,'compile','simplex');
fullfile(root,'compile');

Expand Down
4 changes: 4 additions & 0 deletions buildScript.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
% Now generate the source....
reflectivityCalculationCodeOnlyScript;

compilePath = fullfile(thisPath,'compile','fullCompile');
cd(compilePath);
ratMainCompileScript;

% Finally, change the paths back or the tests might fail...
% setCompilePaths('mex');
compilePath = fullfile(thisPath, 'compile', 'events');
Expand Down
4 changes: 2 additions & 2 deletions compile/DE/%reflectivityCalculationWrapper.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function [problem,result] = reflectivityCalculationWrapper(problemDef,problemDefCells,problemDefLimits,controls)
function [problem,result] = reflectivityCalculation(problemDef,problemDefCells,problemDefLimits,controls)

% Dummy reflectivityCalculationWrapper for compiles
% Dummy reflectivityCalculation for compiles

% This is just a wrapper function for choosing between
% the Matlab and Mex version of reflectivityCalculation.
Expand Down
2 changes: 1 addition & 1 deletion compile/Dram_compile/%reflectivityCalculationWrapper.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [problem,result] = reflectivityCalculationWrapper(problemDef,problemDefCells,problemDefLimits,controls)
function [problem,result] = reflectivityCalculation(problemDef,problemDefCells,problemDefLimits,controls)


% Overloaded wrapper function for compile (i.e. we can't have the 'mex'
Expand Down
2 changes: 1 addition & 1 deletion compile/RAT_main_compile/RAT_main.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
action = controls.proc;
switch lower(action)
case 'calculate' %Just a single reflectivity calculation
[problem,results] = reflectivityCalculationWrapper(problemDef,problemDefCells,problemDefLimits,controls);
[problem,results] = reflectivityCalculation(problemDef,problemDefCells,problemDefLimits,controls);
outProblemDef = problemDef;
case 'simplex'
if ~strcmpi(controls.display,'off')
Expand Down
4 changes: 2 additions & 2 deletions compile/RAT_main_compile/reflectivityCalculationWrapper.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function [problem,result] = reflectivityCalculationWrapper(problemDef,problemDefCells,problemDefLimits,controls)
function [problem,result] = reflectivityCalculation(problemDef,problemDefCells,problemDefLimits,controls)

% Dummy reflectivityCalculationWrapper for compiles
% Dummy reflectivityCalculation for compiles

% This is just a wrapper function for choosing between
% the Matlab and Mex version of reflectivityCalculation.
Expand Down
Loading

0 comments on commit 907cf9d

Please sign in to comment.