Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Plotting a multivariate Bayesian prior probability
% Q11: Compute and plot a 3-d graph of the posterior probability of one cls
figure;
xs = -5:0.2:5;
[X1, X2] = meshgrid(xs, xs);
% My method
%numerator = ((1/2) * mvnpdf([X1(:), X2(:)], m2', C));
%denominator = ((1/2) * mvnpdf([X1(:), X2(:)], m1', C)) + ((1/2) * mvnpdf([X1(:), X2(:)], m2', C));
%p_wj = numerator ./ denominator;
%p_wj = reshape(p_wj, length(xs), length(xs));
%surf(p_wj);
% Niranjan's simpler method
w = 2 * (A * (m2' - m1')');
b = (m1' * A * m1) - (m2' * A * m2);
posterior = 1 ./ (1 + exp(-(w' * [X1(:), X2(:)]' + b)));
posterior = reshape(posterior, length(xs), length(xs));
surf(posterior);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.