Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: the math in classify.m
Replies: 7   Last Post: Dec 3, 2012 7:34 PM

 Messages: [ Previous | Next ]
 marquito Posts: 11 Registered: 1/25/05
Re: the math in classify.m
Posted: Aug 9, 2005 12:06 PM

Thanks for the quick answer! I fully understand the code now.

> With a flat prior, I think the third output POSTERIOR is what you

Yes, I need the posterior p(class|x). Unfortunately my version of
classify.m (Matlab 6.5) doesn't have the option nor the code to
return it.
To fully calculate p(k|x) = p(x|k)*p(k)/p(x) I replaced the for-loop
with:

=====================================================
% MVN relative log posterior density, by group, for
each sample
Sigma = R'*R;
Sigma_det = det(2*pi*Sigma);
help1 = 1/sqrt( Sigma_det );
norm = 0;
for k = 1:ngroups,
A = (sample - repmat(gmeans(k,:), mm, 1)) / R;
help2 = exp(-.5*sum(A.*A, 2));
pdf = help1 * help2; % p(x|k)
norm = norm + prior(k)*pdf; % p(x)
D(:,k) = prior(k) .* pdf;
end

D = D ./ (repmat(norm, 1, ngroups)); % p(k|x)
====================================================

If I haven't overlooked something important, this should be fine,
right?

Date Subject Author
8/9/05 marquito
8/9/05 Peter Perkins
8/9/05 marquito
8/9/05 Peter Perkins
8/9/05 Greg Heath
8/10/05 marquito
12/3/12 Aniket
12/3/12 Greg Heath