Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion minimisers/generalUtils/bayesStats/processBayes.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
result = reflectivityCalculation(problemStruct,problemCells,problemLimits,controls);

% 2. Reflectivity and SLD shading
predInts = refPercentileConfidenceIntervals(bayesOutputs,problemStruct,problemCells,problemLimits,controls);
predInts = refPercentileConfidenceIntervals(bayesOutputs,problemStruct,problemCells,problemLimits,controls,result);

% ---------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function allPredInts = refPercentileConfidenceIntervals(bayesOutputs,problemStruct,problemCells,problemLimits,controlsStruct)
function allPredInts = refPercentileConfidenceIntervals(bayesOutputs,problemStruct,problemCells,problemLimits,controlsStruct,results)

% Need to deal slightly differently with SLDs if there are domains
if strcmpi(problemStruct.TF, coderEnums.calculationTypes.Domains)
Expand All @@ -10,29 +10,15 @@
CIFn = @(x,p)prctile(x,abs([0,100]-(100-p)/2));
chain = bayesOutputs.chain;

% Calc the ref and SLD for the first row of the chain. This 'sticks' the x
% values of each that we then interpolate the values from the rest of the
% cain onto....
firstRow = chain(1,:);
problemStruct.fitParams = firstRow;
problemStruct = unpackParams(problemStruct,controlsStruct);

% Calc the reflectivities....
calcResult = reflectivityCalculation(problemStruct,problemCells,problemLimits,controlsStruct);

thisRef = calcResult.reflectivity;
thisSld = calcResult.sldProfiles;

% so each is a {n x 1} cell array, because of n contrasts.
% Prepare some arrays to hold the SLD's and Refs for all the chain, keeping only the Y vales.
% Prepare some arrays to hold the SLD's and Refs for all the chain, keeping only the Y values.
% We'll save x values in a separate array
numberOfContrasts = problemStruct.numberOfContrasts;

vals = zeros(1,3);
rowVals = zeros(1,3);

refXVals = makeCell(numberOfContrasts, 1, rowVals); %cell(numberOfContrasts,1);
refYVals = makeCell(numberOfContrasts, 1, vals); %cell(numberOfContrasts,1);
refXVals = makeCell(numberOfContrasts, 1, rowVals);
refYVals = makeCell(numberOfContrasts, 1, vals);


if ~domains
Expand All @@ -44,16 +30,16 @@
end

% We need to have the yvals interpolated onto the same xvals when we
% calculate the sample. So, take the current reflectivity value from above
% calculate the sample. So, take the input reflectivity and SLD values
% to get the 'base' x for ref and SLD, then all following
% interpelations are onto these x values....
% interpolations are onto these x values....
for i = 1:numberOfContrasts
refXVals{i} = thisRef{i}(:,1)'; % Transpose these into rows for storage
refXVals{i} = results.reflectivity{i}(:,1)'; % Transpose these into rows for storage
if ~domains
sldXVals{i} = thisSld{i}(:,1)';
sldXVals{i} = results.sldProfiles{i}(:,1)';
else
for m = 1:2
sldXVals{i,m} = thisSld{i,m}(:,1)';
sldXVals{i,m} = results.sldProfiles{i,m}(:,1)';
end
end
end
Expand All @@ -70,18 +56,18 @@

% First, we populate the yVals arrays with zero arrays of the correct size...
for i = 1:numberOfContrasts
ref = thisRef{i};
ref = results.reflectivity{i};
nRefPoints = size(ref,1);
emptyRefArray = zeros(nsample,nRefPoints);
refYVals{i} = emptyRefArray;
if ~domains
sld = thisSld{i};
sld = results.sldProfiles{i};
nSldPoints = size(sld,1);
emptySldArray = zeros(nsample,nSldPoints);
sldYVals{i} = emptySldArray;
else
sld1 = thisSld{i,1};
sld2 = thisSld{i,2};
sld1 = results.sldProfiles{i,1};
sld2 = results.sldProfiles{i,2};
nSldPoints1 = size(sld1,1);
nSldPoints2 = size(sld2,1);
emptySldArray1 = zeros(nsample,nSldPoints1);
Expand Down Expand Up @@ -110,7 +96,7 @@

thisXval = refXVals{n};
thisYval = interp1(thisRef{n}(:,1),thisRef{n}(:,2),thisXval,'linear','extrap');
refYVals{n}(i,:) = thisYval; % Automatically comes back as a row from inpterp1
refYVals{n}(i,:) = thisYval; % Automatically comes back as a row from interp1

if ~domains
thisSldXVal = sldXVals{n};
Expand Down Expand Up @@ -202,8 +188,6 @@

allPredInts.reflectivity = refErrors;
allPredInts.sld = sldErrors;
allPredInts.reflectivityXData = refXVals;
allPredInts.sldXData = sldXVals;
allPredInts.sampleChi = sampleChi;

end
25 changes: 1 addition & 24 deletions minimisers/generalUtils/makeEmptyBayesResultsStruct.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,12 @@
sldIntervals{i} = sldIntervalsCell;
end
end

reflectivityXData = cell(nContrasts,1);
xDataCell = ones(1,3);
coder.varsize('xDataCell',[1 1e4],[0 1]);
for i = 1:nContrasts
reflectivityXData{i} = xDataCell;
end

sldXDataCell = ones(1,3);
coder.varsize('sldXDataCell',[1 1e4],[0 1]);
if isDomains
sldXData = cell(nContrasts,2);
for i = 1:nContrasts
sldXData{i,1} = sldXDataCell;
sldXData{i,2} = sldXDataCell;
end
else
sldXData = cell(nContrasts,1);
for i = 1:nContrasts
sldXData{i} = sldXDataCell;
end
end

sampleChi = zeros(1,1);
coder.varsize('sampleChi',[1e7 1],[1 0]);

predictionIntervals = struct('reflectivity',{reflectivityIntervals}, ...
'sld',{sldIntervals},'reflectivityXData',{reflectivityXData}, ...
'sldXData',{sldXData},'sampleChi',sampleChi);
'sld',{sldIntervals},'sampleChi',sampleChi);

% ------------------------------------------------------------------
% (2) bayesResults.confidenceIntervals
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/domainsTFReflectivityCalculation/domainsCustomXYInputs.mat
Binary file not shown.
Binary file modified tests/domainsTFReflectivityCalculation/domainsCustomXYOutputs.mat
Binary file not shown.
Binary file modified tests/domainsTFReflectivityCalculation/domainsCustomXYTFParams.mat
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/nonPolarisedTFReflectivityCalculation/customLayersInputs.mat
Binary file not shown.
Binary file modified tests/nonPolarisedTFReflectivityCalculation/customLayersOutputs.mat
Binary file not shown.
Binary file not shown.
Binary file modified tests/nonPolarisedTFReflectivityCalculation/customXYInputs.mat
Binary file not shown.
Binary file modified tests/nonPolarisedTFReflectivityCalculation/customXYOutputs.mat
Binary file not shown.
Binary file modified tests/nonPolarisedTFReflectivityCalculation/customXYTFParams.mat
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/testProjectConversion/DSPCBilayerProjectClass.mat
Binary file not shown.
Binary file modified tests/testProjectConversion/monolayerVolumeModelProjectClass.mat
Binary file not shown.
15 changes: 6 additions & 9 deletions utilities/plotting/bayesShadedPlot.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ function bayesShadedPlot(problem,result,varargin)
pLims = result.predictionIntervals;
refPlims = pLims.reflectivity;
sldPlims = pLims.sld;
refXdata = pLims.reflectivityXData;
sldXdata = pLims.sldXData;

% Get the reflectivities for mean...
bestRefMean = result.reflectivity;
Expand Down Expand Up @@ -117,7 +115,7 @@ function bayesShadedPlot(problem,result,varargin)
thisDataY = thisData(:,2)./mult;
thisDataErr = thisData(:,3)./mult;

thisSimX = refXdata{i};
thisSimX = result.reflectivity{i}(:,1);
thisSimQ4 = thisSimX.^4;

switch q4
Expand Down Expand Up @@ -162,7 +160,7 @@ function bayesShadedPlot(problem,result,varargin)

theseLims = sldPlims{i};

thisSldX = sldXdata{i};
thisSldX = result.sldProfiles{i}(:,1);

switch interval
case 95
Expand All @@ -186,7 +184,6 @@ function bayesShadedPlot(problem,result,varargin)
plot(thisSldX,thisSldAvg,'r-');
end

thisSldX = sldXdata{i};
shade(thisSldX,thisMin,thisSldX,thisMax,'FillColor',[0.7 0.7 0.7],'FillType',[1 2;2 1],'FillAlpha',0.3);
end
else
Expand All @@ -197,7 +194,7 @@ function bayesShadedPlot(problem,result,varargin)

theseLims = sldPlims(i,:);

thisSldX = sldXdata(i,:);
thisSldX = result.sldProfiles(i,:);

switch interval
case 95
Expand All @@ -210,6 +207,7 @@ function bayesShadedPlot(problem,result,varargin)
thisMin = theseLims{m}(vals(1),:);
thisMax = theseLims{m}(vals(2),:);

thisDomainSldX = thisSldX{m}(:,1);
thisSldAvg = theseLims{m}(3,:);

if showWhichCurves(1)
Expand All @@ -219,11 +217,10 @@ function bayesShadedPlot(problem,result,varargin)

if showWhichCurves(2)
% Plot the max
plot(thisSldX{m},thisSldAvg,'r-');
plot(thisDomainSldX,thisSldAvg,'r-');
end

%thisSldX = sldXdata{i}{m};
shade(thisSldX{m},thisMin,thisSldX{m},thisMax,'FillColor',[0.7 0.7 0.7],'FillType',[1 2;2 1],'FillAlpha',0.3);
shade(thisDomainSldX,thisMin,thisDomainSldX,thisMax,'FillColor',[0.7 0.7 0.7],'FillType',[1 2;2 1],'FillAlpha',0.3);
end
end

Expand Down