-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSequentialClassifier.m
More file actions
95 lines (91 loc) · 2.86 KB
/
SequentialClassifier.m
File metadata and controls
95 lines (91 loc) · 2.86 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
classdef SequentialClassifier
properties
G
naB
nbA
end
methods
function obj = SequentialClassifier(a, b, j)
a = a';
b= b';
if(nargin == 2)
j = size(a,2) + size(b,2);
end
% G = MEDClassifier;
% naB = [];
% nbA = [];
counter = 1; % j from the lab
% Na = size(a,2);
% Nb = size(b,2);
while ((size(a,2) ~= 0) && (size(b,2) ~=0) && (counter <= j))
A_num = randi([1, size(a,2)]);
B_num = randi([1, size(b,2)]);
AMu = a(:,A_num);
BMu = b(:,B_num);
MED = MEDClassifier(AMu, BMu);
naB_temp = MED.DataClassification(a);
naB_temp = naB_temp(2);
nbA_temp = MED.DataClassification(b);
nbA_temp = nbA_temp(1);
if((nbA_temp == 0) || (naB_temp ==0))
obj.G{counter} = MED;
obj.naB(counter) = naB_temp;
obj.nbA(counter) = nbA_temp;
counter = counter +1;
end
if(naB_temp ==0)
b(:,B_num) = [];
end
if(nbA_temp == 0)
a(:,A_num) = [];
end
end
end
function Y = Sequential_Classify(obj,point)
Y = -1;
counter = 1;
NG = length(obj.G);
done = false;
while((counter <= NG) && (done == false))
temp_class = obj.G{counter}.MED_Classify(point);
if((temp_class == 2)&&(obj.naB(counter) ==0))
Y = temp_class;
done = true;
end
if((temp_class == 1)&&(obj.nbA(counter) == 0))
Y = temp_class;
done = true;
end
counter = counter + 1;
end
end
function Y = Sequential_ClassifyClass(obj, class)
class = class';
nA = 0;
nB = 0;
for i= 1:size(class,2)
x = [class(1,i) class(2,i)]';
temp_class = obj.Sequential_Classify(x);
if(temp_class == 1)
nA = nA +1;
end
if(temp_class == 2)
nB = nB +1;
end
end
Y = [nA nB];
end
function Plot(obj,minX, minY, maxX, maxY)
x1 = minX -5: 1: maxX +5;
x2 = minY -5 :1:maxY+5;
Y = zeros(length(x2),length(x1));
for i = 1:length(x1)
for j = 1:length(x2)
v = [x1(i) x2(j)]';
Y(j,i) = obj.Sequential_Classify(v);
end
end
contour(x1,x2,Y);
end
end
end