Skip to content

Instantly share code, notes, and snippets.

@charlienewey
Created November 5, 2016 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlienewey/2bbec7ac2fe16e410c18f8e5571df0a4 to your computer and use it in GitHub Desktop.
Save charlienewey/2bbec7ac2fe16e410c18f8e5571df0a4 to your computer and use it in GitHub Desktop.
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