Drexel dragonThe Math ForumDonate to the Math Forum

Search All of the Math Forum:

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

Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 11
Registered: 1/25/05
Re: the math in classify.m
Posted: Aug 9, 2005 12:06 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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

> With a flat prior, I think the third output POSTERIOR is what you
> are asking for.

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

% 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;

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

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

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2016. All Rights Reserved.