csci5521/assignments/hwk02/Classify.m

23 lines
742 B
Mathematica
Raw Normal View History

2023-10-12 23:51:06 +00:00
% implements Classify, return the predicted class for each row (we'll call each row x) in data
% by computing the posterior probability that x is in class 1 vs. class 2 then
% these posterior probabilities are compared using the log odds.
function [predictions] = Classify(data, m1, m2, S1, S2, pc1, pc2)
2023-10-13 22:11:18 +00:00
d = 8;
2023-10-12 23:51:06 +00:00
% TODO: calculate P(x|C) * P(C) for both classes
2023-10-13 22:11:18 +00:00
pxC1 = exp(-1/2*(data-m1)./S1*(data-m1)') / (power(2*pi,d/2) * sqrt(det(S1)));
pxC2 = exp(-1/2*(data-m2)*(S2\(data-m2).'));
g1 = pxC1 * pc1;
g2 = pxC2 * pc2;
2023-10-12 23:51:06 +00:00
% TODO: calculate log odds, if > 0 then data(i) belongs to class c1, else, c2
2023-10-13 22:11:18 +00:00
for i = 1:length(data)
data(i)
end
2023-10-12 23:51:06 +00:00
% TODO: get predictions from log odds calculation
end % Function end