-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
51 lines (40 loc) · 1.23 KB
/
main.py
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
from functions import *
if __name__ == '__main__':
draw_matrix = []
I = [
[1, 1],
[1, 2],
[1, 6],
[1, 8],
[1, 9],
[2, 1],
]
# converting Ind vectors into Class instances
classes_nb = len(I)
for i in range(classes_nb):
I[i] = Class(I[i], '{}'.format(i), weight = 1)
# start CAH
while len(I) > 1:
s = calculate_distances_table(I, I)
s.show()
# get smallest distance and its cordinates in table s
r, y, x = s.get_smallest_val()
# removing the classes where the smallest distance was found
if x > y:
a, b = I.pop(x), I.pop(y)
else:
a, b = I.pop(y), I.pop(x)
# save removed classes labels and distance between them for drawing later
draw_matrix += [[int(a.label), int(b.label), r, 0]]
# creating a new class that regroups the old removed classes
new = Class(
vect = [],
label = '{}'.format(classes_nb),
ro = r,
group = [b,a],
)
classes_nb += 1
# updating the I vector with the newly created class
I = [new, *I]
# draw the dendrogram
draw(draw_matrix)