|
|
|
@ -25,6 +25,18 @@ class Knn:
|
|
|
|
|
value[i] = value[i] / ttPart
|
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
def getLabelOfPoint(self, coord,nbNearest):
|
|
|
|
|
points, dists = self.getNNearest(coord, nbNearest)
|
|
|
|
|
label = {}
|
|
|
|
|
for idx in range(len(points)):
|
|
|
|
|
tvalue = points[idx].value[0]
|
|
|
|
|
if tvalue in label:
|
|
|
|
|
label[tvalue] += 1/(dists[idx]+1)
|
|
|
|
|
else:
|
|
|
|
|
label[tvalue] = 1/(dists[idx]+1)
|
|
|
|
|
value = max(label, key=label.get)
|
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
def getNNearest(self, coord, nbNearest):
|
|
|
|
|
dist = np.copy(self.space)
|
|
|
|
|
dist = np.frompyfunc(lambda x: x.getDistFromCoord(coord), 1, 1)(dist)
|
|
|
|
|