Skip to content

Commit

Permalink
Refactors contrasts class and struct (#179)
Browse files Browse the repository at this point in the history
* Renames field of "priors" struct

* Renames "nba" and "nbs" to "bulkIn" and "bulkOut" respectively in "contrastsClass.m"

* Refactors "getNames" routines

* Renames fields in contrasts struct

* Renames contrasts fields in "parseClassToStructs"

* Renames "packpriors.m" and "unpackpriors.m" to camel case

* Fixes priors bug
  • Loading branch information
DrPaulSharp authored Nov 30, 2023
1 parent 0e87e9f commit 84306bc
Show file tree
Hide file tree
Showing 102 changed files with 423 additions and 450 deletions.
6 changes: 3 additions & 3 deletions 3rdParty/mcmcstat/%runDram.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
debug = 0;

checks = controls.checks;
[problemDef,fitNames] = packparams(problemDef,problemDefCells,problemDefLimits,checks);
[problemDef,fitNames] = packParams(problemDef,problemDefCells,problemDefLimits,checks);
%fitPriors = packPriors(priors,checks);

% Seed the Random Number Generator
rng(0);


%fitPriors = packpriors(priors,checks);
%fitPriors = packPriors(priors,checks);

%First deal with priors.
%Make uniform priors from the
Expand Down Expand Up @@ -66,7 +66,7 @@
bayesResults.predlims = output.predlims;

problemDef.fitpars = output.bestPars;
problemDef = unpackparams(problemDef,controls);
problemDef = unpackParams(problemDef,controls);
[problem,result] = reflectivityCalculation(problemDef,problemDefCells,controls);

% Pre-processor directives for Matlab Coder.
Expand Down
2 changes: 1 addition & 1 deletion 3rdParty/mcmcstat/refModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
problemDefCells = problem{4};

problemDef.fitpars = pars;
problemDef = unpackparams(problemDef,controls);
problemDef = unpackParams(problemDef,controls);
[problem,result] = reflectivityCalculation(problemDef,problemDefCells,controls);

ySim = result{1}{contrast};
Expand Down
2 changes: 1 addition & 1 deletion 3rdParty/mcmcstat/refModel_scaled.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
pars = unscalePars(pars,constr);

problemDef.fitpars = pars;
problemDef = unpackparams(problemDef,controls);
problemDef = unpackParams(problemDef,controls);
[problem,result] = reflectivityCalculation(problemDef,problemDefCells,controls);

ySim = result{1}{contrast};
Expand Down
2 changes: 1 addition & 1 deletion 3rdParty/mcmcstat/reflectivity_fitModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


problemDef.fitpars = pars;
problemDef = unpackparams(problemDef,controls);
problemDef = unpackParams(problemDef,controls);
%setappdata(0,'problem',problem);
%problem = reflectivityCalculation(problem);
[problemDef,result] = reflectivityCalculation(problemDef,problemDefCells,controls);
Expand Down
2 changes: 1 addition & 1 deletion 3rdParty/mcmcstat/reflectivity_fitModel_scaled.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
pars = unscalePars(pars,constr);

problemDef.fitpars = pars;
problemDef = unpackparams(problemDef,controls);
problemDef = unpackParams(problemDef,controls);
%setappdata(0,'problem',problem);
%problem = reflectivityCalculation(problem);
[problemDef,result] = reflectivityCalculation(problemDef,problemDefCells,controls);
Expand Down
2 changes: 1 addition & 1 deletion 3rdParty/mcmcstat/runBayes.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
% outSld = mcmcpred_compile_sld(results,chain,[],data,problem,500);
%
% problemDef.fitpars = output.bestPars;
% problemDef = unpackparams(problemDef,controls);
% problemDef = unpackParams(problemDef,controls);
% [problem,result] = reflectivityCalculation(problemDef,problemDefCells,controls);
%
% output.bestFits = result{1};
Expand Down
104 changes: 52 additions & 52 deletions 3rdParty/mcmcstat/runDram.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
%coder.varsize('problemDef.contrastBacks',[1 Inf],[0 1]);

checks = controls.checks;
[problemDef,fitNames] = packparams(problemDef,problemDefCells,problemDefLimits,checks);
[problemDef,fitNames] = packParams(problemDef,problemDefCells,problemDefLimits,checks);
%fitPriors = packPriors(priors,checks);

% Seed the Random Number Generator
rng(0);

%fitPriors = packpriors(priors,checks);
%fitPriors = packPriors(priors,checks);

%First deal with priors.
prior = {};
Expand All @@ -23,83 +23,83 @@
params{i} = cell(1,6);
end

% We have a list of 'fitPars' which is created by packparams.m
% packparams doesn't do the same for our priors however. So we need
% We have a list of 'fitPars' which is created by packParams.m
% packParams doesn't do the same for our priors however. So we need
% to make an array of the priors for the fitted parameters
% so that we can then build the params array for the algorithm

% Put all the priors into one array
% ** This won't work for code generation **
% priorsGroup = [priors.paramPriors ; ...
% priors.backgroundParamPriors ; ...
% priors.resolutionParamPriors ; ...
% priors.bulkInPriors ; ...
% priors.bulkOutPriors ; ...
% priors.qzshiftPriors ;
% priors.scalefactorPriors];

% totalNumber = size(priors.paramPriors,1) + size(priors.backgroundParamPriors,1) + ...
% size(priors.resolutionParamPriors,1) + size(priors.bulkInPriors,1) + size(priors.bulkOutPriors,1) + ...
% size(priors.qzshiftPriors,1) + size(priors.scalefactorPriors,1);
% priorsGroup = [priors.param ; ...
% priors.backgroundParam ; ...
% priors.resolutionParam ; ...
% priors.bulkIn ; ...
% priors.bulkOut ; ...
% priors.qzshift ;
% priors.scalefactor];

% totalNumber = size(priors.param,1) + size(priors.backgroundParam,1) + ...
% size(priors.resolutionParam,1) + size(priors.bulkIn,1) + size(priors.bulkOut,1) + ...
% size(priors.qzshift,1) + size(priors.scalefactor,1);

% Expand the individual cells..
%allPriors = cell(totalNumber,2); %Will be a char type....
% allPriors = strings(totalNumber,2);
% allPriorVals = cell(totalNumber,2);
% cellCount = 1;
% for i = 1:size(priors.paramPriors,1)
% allPriors(cellCount,1) = string(priors.paramPriors{i}{1});
% allPriors(cellCount,2) = string(priors.paramPriors{i}{2});
% allPriorVals{cellCount,1} = priors.paramPriors{i}{3};
% allPriorVals{cellCount,2} = priors.paramPriors{i}{4};
% for i = 1:size(priors.param,1)
% allPriors(cellCount,1) = string(priors.param{i}{1});
% allPriors(cellCount,2) = string(priors.param{i}{2});
% allPriorVals{cellCount,1} = priors.param{i}{3};
% allPriorVals{cellCount,2} = priors.param{i}{4};
% cellCount = cellCount + 1;
% end
%
% for i = 1:size(priors.backgroundParamPriors,1)
% allPriors(cellCount,1) = priors.backgroundParamPriors{i}{1};
% allPriors(cellCount,2) = priors.backgroundParamPriors{i}{2};
% allPriorVals{cellCount,1} = priors.backgroundParamPriors{i}{3};
% allPriorVals{cellCount,2} = priors.backgroundParamPriors{i}{4};
% for i = 1:size(priors.backgroundParam,1)
% allPriors(cellCount,1) = priors.backgroundParam{i}{1};
% allPriors(cellCount,2) = priors.backgroundParam{i}{2};
% allPriorVals{cellCount,1} = priors.backgroundParam{i}{3};
% allPriorVals{cellCount,2} = priors.backgroundParam{i}{4};
% cellCount = cellCount + 1;
% end
%
% for i = 1:size(priors.resolutionParamPriors,1)
% allPriors(cellCount,1) = priors.resolutionParamPriors{i}{1};
% allPriors(cellCount,2) = priors.resolutionParamPriors{i}{2};
% allPriorVals{cellCount,1} = priors.resolutionParamPriors{i}{3};
% allPriorVals{cellCount,2} = priors.resolutionParamPriors{i}{4};
% for i = 1:size(priors.resolutionParam,1)
% allPriors(cellCount,1) = priors.resolutionParam{i}{1};
% allPriors(cellCount,2) = priors.resolutionParam{i}{2};
% allPriorVals{cellCount,1} = priors.resolutionParam{i}{3};
% allPriorVals{cellCount,2} = priors.resolutionParam{i}{4};
% cellCount = cellCount + 1;
% end
%
% for i = 1:size(priors.bulkInPriors,1)
% allPriors(cellCount,1) = priors.bulkInPriors{i}{1};
% allPriors(cellCount,2) = priors.bulkInPriors{i}{2};
% allPriorVals{cellCount,1} = priors.bulkInPriors{i}{3};
% allPriorVals{cellCount,2} = priors.bulkInPriors{i}{4};
% for i = 1:size(priors.bulkIn,1)
% allPriors(cellCount,1) = priors.bulkIn{i}{1};
% allPriors(cellCount,2) = priors.bulkIn{i}{2};
% allPriorVals{cellCount,1} = priors.bulkIn{i}{3};
% allPriorVals{cellCount,2} = priors.bulkIn{i}{4};
% cellCount = cellCount + 1;
% end
%
% for i = 1:size(priors.bulkOutPriors,1)
% allPriors(cellCount,1) = priors.bulkOutPriors{i}{1};
% allPriors(cellCount,2) = priors.bulkOutPriors{i}{2};
% allPriorVals{cellCount,1} = priors.bulkOutPriors{i}{3};
% allPriorVals{cellCount,2} = priors.bulkOutPriors{i}{4};
% for i = 1:size(priors.bulkOut,1)
% allPriors(cellCount,1) = priors.bulkOut{i}{1};
% allPriors(cellCount,2) = priors.bulkOut{i}{2};
% allPriorVals{cellCount,1} = priors.bulkOut{i}{3};
% allPriorVals{cellCount,2} = priors.bulkOut{i}{4};
% cellCount = cellCount + 1;
% end
%
% for i = 1:size(priors.qzshiftPriors,1)
% allPriors(cellCount,1) = priors.qzshiftPriors{i}{1};
% allPriors(cellCount,2) = priors.qzshiftPriors{i}{2};
% allPriorVals{cellCount,1} = priors.qzshiftPriors{i}{3};
% allPriorVals{cellCount,2} = priors.qzshiftPriors{i}{4};
% for i = 1:size(priors.qzshift,1)
% allPriors(cellCount,1) = priors.qzshift{i}{1};
% allPriors(cellCount,2) = priors.qzshift{i}{2};
% allPriorVals{cellCount,1} = priors.qzshift{i}{3};
% allPriorVals{cellCount,2} = priors.qzshift{i}{4};
% cellCount = cellCount + 1;
% end
%
% for i = 1:size(priors.scalefactorPriors,1)
% allPriors(cellCount,1) = priors.scalefactorPriors{i}{1};
% allPriors(cellCount,2) = priors.scalefactorPriors{i}{2};
% allPriorVals{cellCount,1} = priors.scalefactorPriors{i}{3};
% allPriorVals{cellCount,2} = priors.scalefactorPriors{i}{4};
% for i = 1:size(priors.scalefactor,1)
% allPriors(cellCount,1) = priors.scalefactor{i}{1};
% allPriors(cellCount,2) = priors.scalefactor{i}{2};
% allPriorVals{cellCount,1} = priors.scalefactor{i}{3};
% allPriorVals{cellCount,2} = priors.scalefactor{i}{4};
% cellCount = cellCount + 1;
% end

Expand Down Expand Up @@ -171,15 +171,15 @@
%
% % Calulate Max best fit curves
% problemDef.fitpars = bestPars_max;
% problemDef = unpackparams(problemDef,controls);
% problemDef = unpackParams(problemDef,controls);
% [outProblem,result] = reflectivityCalculation(problemDef,problemDefCells,controls);
% bestFitMax_Ref = result(1);
% bestFitMax_Sld = result(5);
% bestFitMax_chi = outProblem.calculations.sum_chi;
%
% % Calculate 'mean' best fit curves
% problemDef.fitpars = bestPars_mean;
% problemDef = unpackparams(problemDef,controls);
% problemDef = unpackParams(problemDef,controls);
% [outProblem,result] = reflectivityCalculation(problemDef,problemDefCells,controls);
% bestFitMean_Ref = result(1);
% bestFitMean_Sld = result(5);
Expand Down
2 changes: 1 addition & 1 deletion 3rdParty/mcmcstat/sldModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
controls.calcSldDuringFit = true;

problemDef.fitpars = pars;
problemDef = unpackparams(problemDef,controls);
problemDef = unpackParams(problemDef,controls);
[~,result] = reflectivityCalculation(problemDef,problemDefCells,controls);

sld = result{5}{contrast};
Expand Down
2 changes: 1 addition & 1 deletion 3rdParty/paramonte/pmLogFunction.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
problem = unscalePars(problem);
end

problem = unpackparams(problem,obj.controls);
problem = unpackParams(problem,obj.controls);

[outProblem,~] = reflectivityCalculation_mex(problem,obj.problemDefCells,obj.controls);
chi = outProblem.calculations.sum_chi;
Expand Down
4 changes: 2 additions & 2 deletions 3rdParty/paramonte/processParamonteRuns.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[problemDef,problemDefCells,problemDefLimits,~,controls] = parseClassToStructs(problem,controls);

[problemDef,fitNames] = packparams(problemDef,problemDefCells,problemDefLimits,controls.checks);
[problemDef,fitNames] = packParams(problemDef,problemDefCells,problemDefLimits,controls.checks);

pm = paramonte();
pmpd = pm.ParaDRAM();
Expand Down Expand Up @@ -55,7 +55,7 @@

result = mergeStructs(result,bayesResults);

[~,fitNames] = packparams(problemDef,problemDefCells,problemDefLimits,controls.checks);
[~,fitNames] = packParams(problemDef,problemDefCells,problemDefLimits,controls.checks);
result.fitNames = fitNames;

outProblemDef = parseOutToProjectClass(problem,problemDef);
Expand Down
4 changes: 2 additions & 2 deletions API/RAT.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function [outProblemDef,result] = RAT(problemDefInput,controls)

[problemDef,problemDefCells,problemDefLimits,priors,controls] = parseClassToStructs(problemDefInput,controls);
[problemDef,~] = packparams(problemDef,problemDefCells,problemDefLimits,controls.checks);
[problemDef,~] = packParams(problemDef,problemDefCells,problemDefLimits,controls.checks);

% Set controls.calCls always to 1
% if we are doing customXY
Expand Down Expand Up @@ -45,7 +45,7 @@
result = mergeStructs(result,bayesResults);
end

[~,fitNames] = packparams(problemDef,problemDefCells,problemDefLimits,controls.checks);
[~,fitNames] = packParams(problemDef,problemDefCells,problemDefLimits,controls.checks);
result.fitNames = fitNames;

outProblemDef = parseOutToProjectClass(problemDefInput,outProblemStruct);
Expand Down
Loading

0 comments on commit 84306bc

Please sign in to comment.