Skip to content

Commit

Permalink
adjusting plotPosteriorScatter to match other function style
Browse files Browse the repository at this point in the history
  • Loading branch information
HeikoSchuett committed Jul 18, 2017
1 parent 0e82d08 commit e170060
Showing 1 changed file with 37 additions and 22 deletions.
59 changes: 37 additions & 22 deletions plotPosterior.m → plotPosteriorScatter.m
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
function plotPosterior(fitResult, dims, minP)
%PLOTPOSTERIOR make 2d or 3d plot of joint posterior.
%
% PLOTPOSTERIOR(fitResult, [dims], [minP]) where 'dims' is a subset of 1:5
function plotPosteriorScatter(result, dims, minP)
% plotPosteriorScatter(result, [dims], [minP])
% where 'dims' is a subset of 1:5 with 2 or three elements
% marginalizes over all other dims and makes either a 2d or 3d scatter plot
% of the resulting marginal posterior grid, ignoring data less than 'minP'.
% of the resulting marginal posterior grid, ignoring data with posterior
% probability less than 'minP'

P = fitResult.Posterior;

P = result.Posterior.*result.weight;

if nargin < 2, dims = [1 2 3]; end
assert((length(dims)>=2 & length(dims<=3)),'plotPosteriorScatter expects to plot 2 or 3 dimensions');

% Default threshold = 100 * uniform for given # grid points after
% marginalization.
if nargin < 3, minP = 0; end


% Marginalize all dimensions of P except 'dims'.
margdims = setdiff(1:5, dims);
for i=length(margdims):-1:1
% Since 'margdims' will be sorted, we are passing over the data
% starting with the last dimension and moving backwards. This allows a
% 'squeeze' at every iteration.
P = squeeze(sum(P, margdims(i)));
P = sum(P, margdims(i));
end
P = squeeze(P);

% Default threshold = 100 * uniform for given # grid points after
% marginalization.
if nargin < 3, minP = 100/numel(P); end

% Get gridpoints and names for each parameter.
gridpts = cell(size(dims));
meshpts = cell(size(dims));
names = cell(size(dims));
for i=1:length(dims)
gridpts{i} = linspace(fitResult.options.borders(dims(i), 1), fitResult.options.borders(dims(i), 2), fitResult.options.stepN(dims(i)));
gridpts{i} = result.X1D{dims(i)};
switch dims(i)
case 1, names{i} = 'Threshold';
case 2, names{i} = 'Width';
Expand All @@ -48,18 +50,31 @@ function plotPosterior(fitResult, dims, minP)
case 2
% 2d scatter
scatter(meshpts{1}(pts), meshpts{2}(pts), 30, P(pts), 'filled', 'Marker', 'o');
xlabel(names{1}); xlim([gridpts{1}(1) gridpts{1}(end)]);
ylabel(names{2}); ylim([gridpts{2}(1) gridpts{2}(end)]);
xlabel(names{1});
ylabel(names{2});
if gridpts{1}(end)> gridpts{1}(1)
xlim([gridpts{1}(1) gridpts{1}(end)]);
end
if gridpts{2}(end)> gridpts{2}(1)
ylim([gridpts{2}(1) gridpts{2}(end)]);
end
case 3
% 3d scatter
scatter3(meshpts{1}(pts), meshpts{2}(pts), meshpts{3}(pts), 30, P(pts), 'filled', 'Marker', 'o');

xlabel(names{1}); xlim([gridpts{1}(1) gridpts{1}(end)]);
ylabel(names{2}); ylim([gridpts{2}(1) gridpts{2}(end)]);
zlabel(names{3}); zlim([gridpts{3}(1) gridpts{3}(end)]);
xlabel(names{1});
ylabel(names{2});
zlabel(names{3});
if gridpts{1}(end)> gridpts{1}(1)
xlim([gridpts{1}(1) gridpts{1}(end)]);
end
if gridpts{2}(end)> gridpts{2}(1)
ylim([gridpts{2}(1) gridpts{2}(end)]);
end
if gridpts{3}(end)> gridpts{3}(1)
zlim([gridpts{3}(1) gridpts{3}(end)]);
end
set(gca, 'YDir', 'reverse');
otherwise
error('plotPosterior expects 2 or 3 dimensions');
end

end
end

0 comments on commit e170060

Please sign in to comment.