Skip to content

Commit

Permalink
split resample params into two params
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhroom committed Sep 2, 2024
1 parent 6fad34d commit 79f7aac
Show file tree
Hide file tree
Showing 15 changed files with 176 additions and 129 deletions.
113 changes: 68 additions & 45 deletions API/controlsClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
procedure = procedures.Calculate.value
% Indicates if SLD should be calculated (Default: false)
calcSldDuringFit = false
resampleParams = [0.9 50]
% minimum angle for resampling (Default: 0.9)
resampleMinAngle = 0.9
% number of points for resampling (Default: 50)
resampleNPoints = 50
% Display Option (Default: displayOptions.Iter)
display = displayOptions.Iter.value
updateFreq = 1
Expand Down Expand Up @@ -91,20 +94,19 @@
obj.updatePlotFreq = val;
end

function set.resampleParams(obj,val)
if length(val) ~= 2
throw(exceptions.invalidValue('resampleParams must have length of 2'));
function set.resampleMinAngle(obj,val)
if (val < 0 || val > 1)
throw(exceptions.invalidValue('resampleMinAngle must be between 0 and 1'));
end
obj.resampleMinAngle = val;
end

validateNumber(val, 'resampleParams must be a number array');

if (val(1) < 0 || val(1) > 1)
throw(exceptions.invalidValue('resampleParams(0) must be between 0 and 1'));
end
if val(2) <= 0
throw(exceptions.invalidValue('resampleParams(1) must be greater than 0'));
function set.resampleNPoints(obj,val)
validateNumber(val, 'resampleNPoints must be a whole number', true);
if (val <= 0)
throw(exceptions.invalidValue('resampleNPoints must be greater than 0'));
end
obj.resampleParams = val;
obj.resampleNPoints = val;
end

% Simplex control methods
Expand Down Expand Up @@ -361,7 +363,8 @@
'nMCMC', {obj.nMCMC},...
'propScale', {obj.propScale},...
'nsTolerance', {obj.nsTolerance},...
'resampleParams', {obj.resampleParams},...
'resampleMinAngle', {obj.resampleMinAngle},...
'resampleNPoints', {obj.resampleNPoints},...
'nSamples', {obj.nSamples},...
'nChains', {obj.nChains},...
'jumpProbability', {obj.jumpProbability},...
Expand Down Expand Up @@ -426,31 +429,35 @@
% The parameters that can be set when using calculate procedure are
% 1) parallel
% 2) calcSldDuringFit
% 3) resampleParams
% 4) display
% 3) resampleMinAngle
% 4) resampleNPoints
% 5) display

% The default values for Calculate
defaultParallel = parallelOptions.Single.value;
defaultCalcSldDuringFit = false;
defaultResampleParams = [0.9 50];
defaultMinAngle = 0.9;
defaultNPoints = 50;
defaultDisplay = displayOptions.Iter.value;

% Creates the input parser for the calculate parameters
p = inputParser;
addParameter(p,'parallel', defaultParallel, @(x) isText(x) || isenum(x));
addParameter(p,'calcSldDuringFit', defaultCalcSldDuringFit, @islogical);
addParameter(p,'resampleParams', defaultResampleParams, @isnumeric);
addParameter(p,'resampleMinAngle', defaultMinAngle, @isnumeric);
addParameter(p,'resampleNPoints', defaultNPoints, @isnumeric);
addParameter(p,'display', defaultDisplay, @(x) isText(x) || isenum(x));
properties = varargin{:};

% Parses the input or raises invalidOption error
errorMsg = 'Only parallel, calcSldDuringFit, resampleParams and display can be set while using the Calculate procedure';
errorMsg = 'Only parallel, calcSldDuringFit, resampleMinAngle, resampleNPoints and display can be set while using the Calculate procedure';
inputBlock = obj.parseInputs(p, properties, errorMsg);

% Sets the values the for Calculate parameters
obj.parallel = inputBlock.parallel;
obj.calcSldDuringFit = inputBlock.calcSldDuringFit;
obj.resampleParams = inputBlock.resampleParams;
obj.resampleMinAngle = inputBlock.resampleMinAngle;
obj.resampleNPoints = inputBlock.resampleNPoints;
obj.display = inputBlock.display;
end

Expand All @@ -468,8 +475,9 @@
% 6) updatePlotFreq
% 7) parallel
% 8) calcSldDuringFit
% 9) resampleParams
% 10) display
% 9) resampleMinAngle
% 10) resampleNPoints
% 11) display

% The simplex default values
defaultXTolerance = 1e-6;
Expand All @@ -480,7 +488,8 @@
defaultUpdatePlotFreq = 20;
defaultParallel = parallelOptions.Single.value;
defaultCalcSldDuringFit = false;
defaultResampleParams = [0.9 50];
defaultMinAngle = 0.9;
defaultNPoints = 50;
defaultDisplay = displayOptions.Iter.value;

% Parses the input for simplex parameters
Expand All @@ -493,12 +502,13 @@
addParameter(p,'updatePlotFreq', defaultUpdatePlotFreq, @isnumeric);
addParameter(p,'parallel', defaultParallel, @(x) isText(x) || isenum(x));
addParameter(p,'calcSldDuringFit', defaultCalcSldDuringFit, @islogical);
addParameter(p,'resampleParams', defaultResampleParams, @isnumeric);
addParameter(p,'resampleMinAngle', defaultMinAngle, @isnumeric);
addParameter(p,'resampleNPoints', defaultNPoints, @isnumeric);
addParameter(p,'display', defaultDisplay, @(x) isText(x) || isenum(x));
properties = varargin{:};

% Parses the input or raises invalidOption error
errorMsg = 'Only xTolerance, funcTolerance, maxFuncEvals, maxIterations, updateFreq, updatePlotFreq, parallel, calcSldDuringFit, resampleParams and display can be set while using the Simplex procedure.';
errorMsg = 'Only xTolerance, funcTolerance, maxFuncEvals, maxIterations, updateFreq, updatePlotFreq, parallel, calcSldDuringFit, resampleMinAngle, resampleNPoints and display can be set while using the Simplex procedure.';
inputBlock = obj.parseInputs(p, properties, errorMsg);

% Sets the values the for simplex parameters
Expand All @@ -510,7 +520,8 @@
obj.updatePlotFreq = inputBlock.updatePlotFreq;
obj.parallel = inputBlock.parallel;
obj.calcSldDuringFit = inputBlock.calcSldDuringFit;
obj.resampleParams = inputBlock.resampleParams;
obj.resampleMinAngle = inputBlock.resampleMinAngle;
obj.resampleNPoints = inputBlock.resampleNPoints;
obj.display = inputBlock.display;
end

Expand All @@ -528,10 +539,11 @@
% 6) numGenerations
% 7) parallel
% 8) calcSldDuringFit
% 9) resampleParams
% 10) display
% 11) updateFreq
% 12) updatePlotFreq
% 9) resampleMinAngle
% 10) resampleNPoints
% 11) display
% 12) updateFreq
% 13) updatePlotFreq

% The default values for DE
defaultPopulationSize = 20;
Expand All @@ -542,7 +554,8 @@
defaultNumGenerations = 500;
defaultParallel = parallelOptions.Single.value;
defaultCalcSldDuringFit = false;
defaultResampleParams = [0.9 50];
defaultMinAngle = 0.9;
defaultNPoints = 50;
defaultDisplay = displayOptions.Iter.value;
defaultUpdateFreq = 1;
defaultUpdatePlotFreq = 20;
Expand All @@ -557,14 +570,15 @@
addParameter(p,'numGenerations', defaultNumGenerations, @isnumeric);
addParameter(p,'parallel', defaultParallel, @(x) isText(x) || isenum(x));
addParameter(p,'calcSldDuringFit', defaultCalcSldDuringFit, @islogical);
addParameter(p,'resampleParams', defaultResampleParams, @isnumeric);
addParameter(p,'resampleMinAngle', defaultMinAngle, @isnumeric);
addParameter(p,'resampleNPoints', defaultNPoints, @isnumeric);
addParameter(p,'display', defaultDisplay, @(x) isText(x) || isenum(x));
addParameter(p,'updateFreq', defaultUpdateFreq, @isnumeric);
addParameter(p,'updatePlotFreq', defaultUpdatePlotFreq, @isnumeric);
properties = varargin{:};

% Parses the input or raises invalidOption error
errorMsg = 'Only populationSize, fWeight, crossoverProbability, strategy, targetValue, numGenerations, parallel, calcSldDuringFit, resampleParams, display, updateFreq, and updatePlotFreq can be set while using the Differential Evolution procedure';
errorMsg = 'Only populationSize, fWeight, crossoverProbability, strategy, targetValue, numGenerations, parallel, calcSldDuringFit, resampleMinAngle, resampleNPoints, display, updateFreq, and updatePlotFreq can be set while using the Differential Evolution procedure';
inputBlock = obj.parseInputs(p, properties, errorMsg);

% Sets the values the for DE parameters
Expand All @@ -576,7 +590,8 @@
obj.numGenerations = inputBlock.numGenerations;
obj.parallel = inputBlock.parallel;
obj.calcSldDuringFit = inputBlock.calcSldDuringFit;
obj.resampleParams = inputBlock.resampleParams;
obj.resampleMinAngle = inputBlock.resampleMinAngle;
obj.resampleNPoints = inputBlock.resampleNPoints;
obj.display = inputBlock.display;
obj.updateFreq = inputBlock.updateFreq;
obj.updatePlotFreq = inputBlock.updatePlotFreq;
Expand All @@ -594,8 +609,9 @@
% 4) nsTolerance
% 5) parallel
% 6) calcSldDuringFit
% 7) resampleParams
% 8) display
% 7) resampleMinAngle
% 8) resampleNPoints
% 9) display

% The default values for NS
defaultnLive = 150;
Expand All @@ -604,7 +620,8 @@
defaultNsTolerance = 0.1;
defaultParallel = parallelOptions.Single.value;
defaultCalcSldDuringFit = false;
defaultResampleParams = [0.9 50];
defaultMinAngle = 0.9;
defaultNPoints = 50;
defaultDisplay = displayOptions.Iter.value;

% Creates the input parser for the NS parameters
Expand All @@ -615,12 +632,13 @@
addParameter(p,'nsTolerance', defaultNsTolerance, @isnumeric);
addParameter(p,'parallel', defaultParallel, @(x) isText(x) || isenum(x));
addParameter(p,'calcSldDuringFit', defaultCalcSldDuringFit, @islogical);
addParameter(p,'resampleParams', defaultResampleParams, @isnumeric);
addParameter(p,'resampleMinAngle', defaultMinAngle, @isnumeric);
addParameter(p,'resampleNPoints', defaultNPoints, @isnumeric);
addParameter(p,'display', defaultDisplay, @(x) isText(x) || isenum(x));
properties = varargin{:};

% Parses the input or raises invalidOption error
errorMsg = 'Only nLive, nMCMC, propScale, nsTolerance, parallel, calcSldDuringFit, resampleParams and display can be set while using the Nested Sampler procedure';
errorMsg = 'Only nLive, nMCMC, propScale, nsTolerance, parallel, calcSldDuringFit, resampleMinAngle, resampleNPoints and display can be set while using the Nested Sampler procedure';
inputBlock = obj.parseInputs(p, properties, errorMsg);

% Sets the values the for NS parameters
Expand All @@ -630,7 +648,8 @@
obj.nsTolerance = inputBlock.nsTolerance;
obj.parallel = inputBlock.parallel;
obj.calcSldDuringFit = inputBlock.calcSldDuringFit;
obj.resampleParams = inputBlock.resampleParams;
obj.resampleMinAngle = inputBlock.resampleMinAngle;
obj.resampleNPoints = inputBlock.resampleNPoints;
obj.display = inputBlock.display;
end

Expand All @@ -648,8 +667,9 @@
% 6) adaptPCR
% 7) parallel
% 8) calcSldDuringFit
% 9) resampleParams
% 10) display
% 9) resampleMinAngle
% 10) resampleNPoints
% 11) display

% The default values for Dream
defaultNSamples = 50000;
Expand All @@ -660,7 +680,8 @@
defaultAdaptPCR = false;
defaultParallel = parallelOptions.Single.value;
defaultCalcSldDuringFit = false;
defaultResampleParams = [0.9 50];
defaultMinAngle = 0.9;
defaultNPoints = 50;
defaultDisplay = displayOptions.Iter.value;

% Creates the input parser for the Dream parameters
Expand All @@ -673,12 +694,13 @@
addParameter(p,'adaptPCR', defaultAdaptPCR, @islogical);
addParameter(p,'parallel', defaultParallel, @(x) isText(x) || isenum(x));
addParameter(p,'calcSldDuringFit', defaultCalcSldDuringFit, @islogical);
addParameter(p,'resampleParams', defaultResampleParams, @isnumeric);
addParameter(p,'resampleMinAngle', defaultMinAngle, @isnumeric);
addParameter(p,'resampleNPoints', defaultNPoints, @isnumeric);
addParameter(p,'display', defaultDisplay, @(x) isText(x) || isenum(x));
properties = varargin{:};

% Parses the input or raises invalidOption error
errorMsg = 'Only nSamples, nChains, jumpProbability, pUnitGamma, boundHandling, adaptPCR, parallel, calcSldDuringFit, resampleParams and display can be set while using the DREAM procedure';
errorMsg = 'Only nSamples, nChains, jumpProbability, pUnitGamma, boundHandling, adaptPCR, parallel, calcSldDuringFit, resampleMinAngle, resampleNPoints and display can be set while using the DREAM procedure';
inputBlock = obj.parseInputs(p, properties, errorMsg);

% Sets the values the for Dream parameters
Expand All @@ -690,7 +712,8 @@
obj.adaptPCR = inputBlock.adaptPCR;
obj.parallel = inputBlock.parallel;
obj.calcSldDuringFit = inputBlock.calcSldDuringFit;
obj.resampleParams = inputBlock.resampleParams;
obj.resampleMinAngle = inputBlock.resampleMinAngle;
obj.resampleNPoints = inputBlock.resampleNPoints;
obj.display = inputBlock.display;
end

Expand Down
3 changes: 2 additions & 1 deletion API/parseClassToStructs.m
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@
%% Now deal with the controls class
controls.procedure = inputControls.procedure;
controls.parallel = inputControls.parallel;
controls.resampleParams = inputControls.resampleParams;
controls.resampleMinAngle = inputControls.resampleMinAngle;
controls.resampleNPoints = inputControls.resampleNPoints;
controls.calcSldDuringFit = inputControls.calcSldDuringFit;
controls.display = inputControls.display;
controls.xTolerance = inputControls.xTolerance;
Expand Down
3 changes: 2 additions & 1 deletion compile/fullCompile/makeCompileArgsFull.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
ARGS_1_4 = struct;
ARGS_1_4.procedure = coder.typeof('X',[1 maxArraySize],[0 1]);
ARGS_1_4.parallel = coder.typeof('X',[1 maxArraySize],[0 1]);
ARGS_1_4.resampleParams = coder.typeof(0,[1 2]);
ARGS_1_4.resampleMinAngle = coder.typeof(0);
ARGS_1_4.resampleNPoints = coder.typeof(0);
ARGS_1_4.calcSldDuringFit = coder.typeof(true);
ARGS_1_4.display = coder.typeof('X',[1 maxArraySize],[0 1]);
ARGS_1_4.xTolerance = coder.typeof(0);
Expand Down
3 changes: 2 additions & 1 deletion compile/reflectivityCalculation/makeCompileArgs.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
ARGS_1_4 = struct;
ARGS_1_4.procedure = coder.typeof('X',[1 maxArraySize],[0 1]);
ARGS_1_4.parallel = coder.typeof('X',[1 maxArraySize],[0 1]);
ARGS_1_4.resampleParams = coder.typeof(0,[1 2]);
ARGS_1_4.resampleMinAngle = coder.typeof(0);
ARGS_1_4.resampleNPoints = coder.typeof(0);
ARGS_1_4.calcSldDuringFit = coder.typeof(true);
ARGS_1_4.display = coder.typeof('X',[1 maxArraySize],[0 1]);
ARGS_1_4.xTolerance = coder.typeof(0);
Expand Down
2 changes: 1 addition & 1 deletion examples/miscellaneous/absorption/absorptionDPPC50.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@

% Now make a controls block....
controls = controlsClass();
controls.resampleParams(2) = 150;
controls.resampleMinAngle = 150;
controls.parallel = 'contrasts';

[problem,results] = RAT(problem,controls);
Expand Down
13 changes: 7 additions & 6 deletions targetFunctions/+domainsTF/customLayers.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

calcSld = controls.calcSldDuringFit;
parallel = controls.parallel;
resampleParams = controls.resampleParams;
resampleMinAngle = controls.resampleMinAngle;
resampleNPoints = controls.resampleNPoints;

% Pre-Allocation of output arrays...
backgroundParams = zeros(numberOfContrasts,1);
Expand Down Expand Up @@ -111,7 +112,7 @@
backgroundParamArray,qzshiftArray,scalefactorArray,bulkInArray,...
bulkOutArray,resolutionParamArray,domainRatioArray,dataPresent(i),...
data{i},dataLimits{i},simLimits{i},repeatLayers{i},...
contrastBackgroundActions(i),nParams,parallel,resampleParams,...
contrastBackgroundActions(i),nParams,parallel,resampleMinAngle,resampleNPoints,...
useImaginary,resample(i),geometry,subRoughs(i),calcSld,...
calcAllLayers1{i},calcAllLayers2{i});

Expand All @@ -132,7 +133,7 @@
backgroundParamArray,qzshiftArray,scalefactorArray,bulkInArray,...
bulkOutArray,resolutionParamArray,domainRatioArray,dataPresent(i),...
data{i},dataLimits{i},simLimits{i},repeatLayers{i},...
contrastBackgroundActions(i),nParams,parallel,resampleParams,...
contrastBackgroundActions(i),nParams,parallel,resampleMinAngle,resampleNPoints,...
useImaginary,resample(i),geometry,subRoughs(i),calcSld,...
calcAllLayers1{i},calcAllLayers2{i});

Expand Down Expand Up @@ -165,7 +166,7 @@
qzshiftIndex,scalefactorIndex,bulkInIndex,bulkOutIndex,resolutionParamIndex,...
domainRatioIndex,backgroundParams,qzshifts,scalefactors,bulkIns,bulkOuts,...
resolutionParams,domainRatios,dataPresent,data,dataLimits,simLimits,...
repeatLayers,contrastBackgroundActions,nParams,parallel,resampleParams,...
repeatLayers,contrastBackgroundActions,nParams,parallel,resampleMinAngle,resampleNPoints,...
useImaginary,resample,geometry,roughness,calcSld,calcAllLayers1,calcAllLayers2)

% Get the domain ratio for this contrast
Expand All @@ -188,12 +189,12 @@
[sldProfile1,reflect1,simul1,shiftedData,layerSld1,resampledLayer1,~] = nonPolarisedTF.coreLayersCalculation(calcAllLayers1,roughness,...
geometry,bulkInValue,bulkOutValue,resample,calcSld,scalefactorValue,qzshiftValue,...
dataPresent,data,dataLimits,simLimits,repeatLayers,backgroundParamValue,...
resolutionParamValue,contrastBackgroundActions,nParams,parallel,resampleParams,useImaginary);
resolutionParamValue,contrastBackgroundActions,nParams,parallel,resampleMinAngle,resampleNPoints,useImaginary);

[sldProfile2,reflect2,simul2,~,layerSld2,resampledLayer2,~] = nonPolarisedTF.coreLayersCalculation(calcAllLayers2,roughness,...
geometry,bulkInValue,bulkOutValue,resample,calcSld,scalefactorValue,qzshiftValue,...
dataPresent,data,dataLimits,simLimits,repeatLayers,backgroundParamValue,...
resolutionParamValue,contrastBackgroundActions,nParams,parallel,resampleParams,useImaginary);
resolutionParamValue,contrastBackgroundActions,nParams,parallel,resampleMinAngle,resampleNPoints,useImaginary);

% Calculate the average reflectivities....
[reflectivity,simulation] = domainsTF.averageReflectivity(reflect1,reflect2,simul1,simul2,domainRatio);
Expand Down
Loading

0 comments on commit 79f7aac

Please sign in to comment.