forked from shirsks14/Lab3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMICDClassifier.m
More file actions
55 lines (46 loc) · 1.3 KB
/
MICDClassifier.m
File metadata and controls
55 lines (46 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
classdef MICDClassifier
properties
Mus;
covs;
% AMu;
% BMu;
% CMu;
% DMu;
% EMu;
% FMu;
% GMu;
% HMu;
% IMu;
% JMu;
end
methods
function obj = MICDClassifier(data)
counter = 0;
for i = 1:10
obj.Mus(:,i) = [sum(data(1,counter+1:counter+16))/16; sum(data(2,counter+1:counter+16))/16];
counter = counter +16;
end
counter = 0;
for i = 1:10
x = [data(1,counter+1:counter+16); data(2,counter+1:counter+16)];
obj.covs{i} = obj.CalCovariance(x,obj.Mus(:,i));
counter = counter + 16;
end
end
function Y = CalCovariance(obj, x, Mu)
Y = zeros(2,2);
for i = 1:length(x)
Y = Y + (x(:,i)' - Mu')'*(x(:,i)' -Mu');
end
Y = Y/length(x);
Y = length(x)/(length(x) - 1) * Y;
end
function Y = Classify(obj, point)
distances = [];
for i = 1: 10
distances(i) = (point-obj.Mus(:,i))'*inv(obj.covs{i})*(point - obj.Mus(:,i));
end
[~, Y] = min(distances);
end
end
end