Skip to content

Commit c19b35d

Browse files
authored
Reduces "bayesShadedPlot" to use only the "mean" fit option (#277)
* Removes "fit" option from "bayesShadedPlot" * Tidies up "bayesShadedPlot" * Addresses review comments
1 parent 2d2a212 commit c19b35d

File tree

5 files changed

+76
-146
lines changed

5 files changed

+76
-146
lines changed
-197 Bytes
Binary file not shown.

examples/normalReflectivity/customXY/customXYDSPCScript.m

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
% ..and plot this out....
189189

190190
figure(30); clf;
191-
bayesShadedPlot(problem, results,'fit','average','KeepAxes',true,'interval',65,'q4',false)
191+
bayesShadedPlot(problem, results,'KeepAxes',true,'interval',65,'q4',false)
192192

193193
h3 = figure(40); clf
194194
plotHists(results,h3,'smooth',true)
@@ -271,12 +271,14 @@
271271

272272
% In RAT, there is a useful function called 'shade' that we can use
273273
% here.....
274+
fillType = [1 2;2 1];
275+
fillAlpha = 0.3;
274276
cols = get(gca,'ColorOrder');
275-
shade(z,ciSi(1,:),z,ciSi(2,:),'FillColor',cols(1,:),'FillType',[1 2;2 1],'FillAlpha',0.3);
276-
shade(z,ciOxide(1,:),z,ciOxide(2,:),'FillColor',cols(2,:),'FillType',[1 2;2 1],'FillAlpha',0.3);
277-
shade(z,ciHeadL(1,:),z,ciHeadL(2,:),'FillColor',cols(3,:),'FillType',[1 2;2 1],'FillAlpha',0.3);
278-
shade(z,ciTails(1,:),z,ciTails(2,:),'FillColor',cols(4,:),'FillType',[1 2;2 1],'FillAlpha',0.3);
279-
shade(z,ciHeadR(1,:),z,ciHeadR(2,:),'FillColor',cols(5,:),'FillType',[1 2;2 1],'FillAlpha',0.3);
277+
shade(z,ciSi(1,:),z,ciSi(2,:),'FillColor',cols(1,:),'FillType',fillType,'FillAlpha',fillAlpha);
278+
shade(z,ciOxide(1,:),z,ciOxide(2,:),'FillColor',cols(2,:),'FillType',fillType,'FillAlpha',fillAlpha);
279+
shade(z,ciHeadL(1,:),z,ciHeadL(2,:),'FillColor',cols(3,:),'FillType',fillType,'FillAlpha',fillAlpha);
280+
shade(z,ciTails(1,:),z,ciTails(2,:),'FillColor',cols(4,:),'FillType',fillType,'FillAlpha',fillAlpha);
281+
shade(z,ciHeadR(1,:),z,ciHeadR(2,:),'FillColor',cols(5,:),'FillType',fillType,'FillAlpha',fillAlpha);
280282
title('Volume Fractions');
281283
%%
282284
% .. and we are done.
-6 Bytes
Binary file not shown.

utilities/plotting/bayesShadedPlot.m

Lines changed: 65 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function bayesShadedPlot(problem,result,varargin)
22

33
% Plot the shaded reflectivities from Bayes output
44
% from RAT
5-
sf = result.contrastParams.scalefactors;
5+
66
if isa(problem,'domainsClass')
77
isDomains = true;
88
else
@@ -11,60 +11,55 @@ function bayesShadedPlot(problem,result,varargin)
1111

1212
% Parse the input options
1313
if ~isempty(varargin)
14-
defaultq4 = 0;
15-
defaultFit = 'mean';
14+
15+
defaultq4 = false;
1616
defaultKeep = false;
1717
defaultInterval = 95;
1818

19-
2019
allIntervals = [65 95];
2120

2221
p = inputParser;
2322
addOptional(p, 'q4', defaultq4, @islogical);
24-
addOptional(p, 'fit', defaultFit, @(x) any(strcmpi(x,{'mean','average','all'})));
2523
addOptional(p, 'KeepAxes', defaultKeep, @islogical);
2624
addOptional(p, 'interval', defaultInterval, @(x) ismember(x,allIntervals));
2725

2826
parse(p,varargin{:});
2927
inputBlock = p.Results;
3028

3129
q4 = inputBlock.q4;
32-
fit = inputBlock.fit;
3330
keepAx = inputBlock.KeepAxes;
3431
interval = inputBlock.interval;
3532

3633
else
34+
3735
q4 = false;
38-
fit = 'average';
3936
keepAx = false;
40-
interval = 65;
41-
end
42-
43-
%mean %Average % All
44-
showWhichCurves = [false false false];
37+
interval = 95;
4538

46-
switch fit
47-
case 'mean'
48-
showWhichCurves(1) = 1;
49-
case 'average'
50-
showWhichCurves(2) = 1;
51-
case 'all'
52-
showWhichCurves(1:2) = 1;
5339
end
5440

55-
f = gcf;
5641

57-
if ~ keepAx
42+
if ~keepAx
5843
clf; hold on; box on
5944
end
6045

61-
pLims = result.predictionIntervals;
62-
refPlims = pLims.reflectivity;
63-
sldPlims = pLims.sld;
46+
switch interval
47+
case 95
48+
vals = [1 5];
49+
case 65
50+
vals = [2 4];
51+
end
52+
53+
fillColor = [0.7 0.7 0.7];
54+
fillType = [1 2;2 1];
55+
fillAlpha = 0.3;
56+
57+
% Get the reflectivities and SLDs
58+
bestReflectivity = result.reflectivity;
59+
bestSld = result.sldProfiles;
6460

65-
% Get the reflectivities for mean...
66-
bestRefMean = result.reflectivity;
67-
bestSldMean = result.sldProfiles;
61+
reflectivityLimits = result.predictionIntervals.reflectivity;
62+
sldLimits = result.predictionIntervals.sld;
6863

6964
shiftedData = result.shiftedData;
7065
numberOfContrasts = length(shiftedData);
@@ -76,154 +71,87 @@ function bayesShadedPlot(problem,result,varargin)
7671

7772
for i = 1:numberOfContrasts
7873

79-
%thisRef = reflect{i};
8074
thisData = shiftedData{i};
81-
thisRefMean = bestRefMean{i};
82-
thisSf = sf(i);
75+
reflectivity = bestReflectivity{i};
8376

77+
mult = 2^(4*i);
8478
switch q4
79+
case true
80+
thisQ4 = thisData(:,1).^4;
8581
case false
8682
if i == 1
8783
mult = 1;
88-
else
89-
mult = 2^(4*i);
9084
end
91-
otherwise
92-
mult = 2^(4*i);
93-
thisQ4 = thisData(:,1).^4;
9485
end
9586

9687
% Get the limits and fits
97-
theseLims = refPlims{i};
98-
99-
switch interval
100-
case 95
101-
vals = [1 5];
102-
case 65
103-
vals = [2 4];
104-
end
105-
106-
thisMin = theseLims(vals(1),:)./mult;
107-
thisMax = theseLims(vals(2),:)./mult;
108-
109-
thisRefAvg = theseLims(3,:)./mult;
88+
limits = reflectivityLimits{i};
11089

111-
thisRefMean(:,2) = thisRefMean(:,2)./mult;
112-
%thisRefMax(:,2) = thisRefMax(:,2)./mult;
90+
min = limits(vals(1),:)./mult;
91+
max = limits(vals(2),:)./mult;
92+
93+
reflectivity(:,2) = reflectivity(:,2)./mult;
11394

114-
thisDataX = thisData(:,1);
115-
thisDataY = thisData(:,2)./mult;
116-
thisDataErr = thisData(:,3)./mult;
95+
dataX = thisData(:,1);
96+
dataY = thisData(:,2)./mult;
97+
dataErr = thisData(:,3)./mult;
11798

118-
thisSimX = result.reflectivity{i}(:,1);
119-
thisSimQ4 = thisSimX.^4;
99+
refXValues = result.reflectivity{i}(:,1);
100+
thisSimQ4 = refXValues.^4;
120101

121102
switch q4
122103
case true
123-
thisMin = thisMin .* thisSimQ4;
124-
thisMax = thisMax .* thisSimQ4;
125-
thisRefMean(:,2) = thisRefMean(:,2) .* thisQ4;
126-
thisRefAvg = thisRefAvg .* thisSimQ4;
127-
thisDataY = thisDataY(:) .* thisQ4;
128-
thisDataErr = thisDataErr(:) .* thisQ4;
104+
min = min .* thisSimQ4;
105+
max = max .* thisSimQ4;
106+
reflectivity(:,2) = reflectivity(:,2) .* thisQ4;
107+
dataY = dataY(:) .* thisQ4;
108+
dataErr = dataErr(:) .* thisQ4;
129109
end
130110

131-
errorbar(thisDataX,thisDataY,thisDataErr,'.');
111+
errorbar(dataX,dataY,dataErr,'.');
112+
shade(refXValues,min,refXValues,max,'FillColor',fillColor,'FillType',fillType,'FillAlpha',fillAlpha);
113+
plot(reflectivity(:,1),reflectivity(:,2),'b-');
132114

133-
%plot(thisData(:,1),thisMin,'-','color',[0.7 0.7 0.7]);
134-
%plot(thisData(:,1),thisMax,'-','color',[0.7 0.7 0.7]);
135-
%plot(thisData(:,1),thisRef,'LineWidth',2.0);
136-
%fillyy(thisData(:,1),thisMin,thisMax,[0.8 0.8 0.8]);
137-
shade(thisSimX,thisMin,thisSimX,thisMax,'FillColor',[0.7 0.7 0.7],'FillType',[1 2;2 1],'FillAlpha',0.3);
138-
139-
% Plot the requested fit lines;
140-
if showWhichCurves(1)
141-
% Plot the mean
142-
plot(thisRefMean(:,1),thisRefMean(:,2),'b-');
143-
end
144-
145-
if showWhichCurves(2)
146-
% Plot the average
147-
plot(thisDataX,thisRefAvg,'r-');
148-
end
149-
150115
end
151116

152-
% Now plot the SLD's
117+
% Now plot the SLDs
153118
subplot(1,2,2); hold on; box on
154119

155120
if ~isDomains
156-
for i = 1:numberOfContrasts
157-
158-
thisSldMean = bestSldMean{i};
159-
%thisSldMax = bestSld_max{i};
160121

161-
theseLims = sldPlims{i};
162-
163-
thisSldX = result.sldProfiles{i}(:,1);
164-
165-
switch interval
166-
case 95
167-
vals = [1 5];
168-
case 65
169-
vals = [2 4];
170-
end
122+
for i = 1:numberOfContrasts
171123

172-
thisMin = theseLims(vals(1),:);
173-
thisMax = theseLims(vals(2),:);
124+
sld = bestSld{i};
125+
limits = sldLimits{i};
126+
sldXValues = result.sldProfiles{i}(:,1);
174127

175-
thisSldAvg = theseLims(3,:);
128+
min = limits(vals(1),:);
129+
max = limits(vals(2),:);
176130

177-
if showWhichCurves(1)
178-
% Plot the mean
179-
plot(thisSldMean(:,1),thisSldMean(:,2),'b-');
180-
end
131+
plot(sld(:,1),sld(:,2),'b-');
132+
shade(sldXValues,min,sldXValues,max,'FillColor',fillColor,'FillType',fillType,'FillAlpha',fillAlpha);
181133

182-
if showWhichCurves(2)
183-
% Plot the max
184-
plot(thisSldX,thisSldAvg,'r-');
185-
end
186-
187-
shade(thisSldX,thisMin,thisSldX,thisMax,'FillColor',[0.7 0.7 0.7],'FillType',[1 2;2 1],'FillAlpha',0.3);
188134
end
189-
else
190-
for i = 1:numberOfContrasts
191-
192-
thisSldMean = bestSldMean(i,:);
193-
%thisSldMax = bestSld_max{i};
194-
195-
theseLims = sldPlims(i,:);
196135

197-
thisSldX = result.sldProfiles(i,:);
198-
199-
switch interval
200-
case 95
201-
vals = [1 5];
202-
case 65
203-
vals = [2 4];
204-
end
136+
else
205137

206-
for m = 1:2
207-
thisMin = theseLims{m}(vals(1),:);
208-
thisMax = theseLims{m}(vals(2),:);
138+
for i = 1:numberOfContrasts
209139

210-
thisDomainSldX = thisSldX{m}(:,1);
211-
thisSldAvg = theseLims{m}(3,:);
140+
sld = bestSld(i,:);
141+
limits = sldLimits(i,:);
142+
sldXValues = result.sldProfiles(i,:);
212143

213-
if showWhichCurves(1)
214-
% Plot the mean
215-
plot(thisSldMean{m}(:,1),thisSldMean{m}(:,2),'b-');
216-
end
144+
for j = 1:2
145+
min = limits{j}(vals(1),:);
146+
max = limits{j}(vals(2),:);
217147

218-
if showWhichCurves(2)
219-
% Plot the max
220-
plot(thisDomainSldX,thisSldAvg,'r-');
221-
end
148+
thisDomainSldXValues = sldXValues{j}(:,1);
222149

223-
shade(thisDomainSldX,thisMin,thisDomainSldX,thisMax,'FillColor',[0.7 0.7 0.7],'FillType',[1 2;2 1],'FillAlpha',0.3);
150+
plot(sld{j}(:,1),sld{j}(:,2),'b-');
151+
shade(thisDomainSldXValues,min,thisDomainSldXValues,max,'FillColor',fillColor,'FillType',fillType,'FillAlpha',fillAlpha);
224152
end
225153
end
226154

227155
end
228156

229-
end
157+
end

utilities/plotting/plotBayes.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ function plotBayes(problem, results)
33
figure(10); clf; plotRefSLD(problem,results)
44

55
figure(30); clf;
6-
bayesShadedPlot(problem,results,'fit','mean','KeepAxes',true,'interval',95,'q4',false)
6+
bayesShadedPlot(problem,results,'KeepAxes',true,'interval',95,'q4',false)
77

88
h3 = figure(40); clf
99
plotHists(results,h3,'smooth',true)
1010

11-
% h4 = figure(5); clf
12-
% cornerPlot(results,h4,'smooth',false)
11+
% h4 = figure(5); clf
12+
% cornerPlot(results,h4,'smooth',false)
1313

1414
figure(60); clf
1515
mcmcplot(results.chain,[],results.fitNames,'chainpanel');

0 commit comments

Comments
 (0)