|
|
|
@ -22,14 +22,18 @@ class Nnnar:
|
|
|
|
|
self.space[*self.getSpaceIdxFromCoord(coord)].append(Point(coord, value))
|
|
|
|
|
|
|
|
|
|
def getValueOfPoint(self, coord,nbNearest):
|
|
|
|
|
points = self.getNNearest(coord, nbNearest)
|
|
|
|
|
value = points[0].value
|
|
|
|
|
points, dists = self.getNNearest(coord, nbNearest)
|
|
|
|
|
ttPart = 1/(dists[0]+1)
|
|
|
|
|
value = []
|
|
|
|
|
for i in points[0].value:
|
|
|
|
|
value.append(i * ttPart)
|
|
|
|
|
for idx in range(1,len(points)):
|
|
|
|
|
ttPart += 1/(dists[idx]+1)
|
|
|
|
|
tvalue = points[idx].value
|
|
|
|
|
for i in range(len(tvalue)):
|
|
|
|
|
value[i] += tvalue[i]
|
|
|
|
|
value[i] += tvalue[i] * (1/(dists[idx]+1))
|
|
|
|
|
for i in range(len(value)):
|
|
|
|
|
value[i] = value[i] / nbNearest
|
|
|
|
|
value[i] = value[i] / ttPart
|
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
def getNNearest(self, coord, nbNearest):
|
|
|
|
@ -59,7 +63,7 @@ class Nnnar:
|
|
|
|
|
dist.append(selected[i].getDistFromCoord(coord))
|
|
|
|
|
maxDistIdx = foundMaxIndex(dist)
|
|
|
|
|
maxDist = max(dist)
|
|
|
|
|
return found
|
|
|
|
|
return found, dist
|
|
|
|
|
|
|
|
|
|
def getSpaceIdxFromCoord(self,coord):
|
|
|
|
|
coord = coord - self.minCoord
|
|
|
|
@ -88,4 +92,4 @@ n = Nnnar(3, 0, 3, 2)
|
|
|
|
|
n.addPoint(np.array([1, 0.8,1.5]), [0.2,0.5])
|
|
|
|
|
n.addPoint(np.array([0.2, 1.8,1.2]), [0.4,0.7])
|
|
|
|
|
|
|
|
|
|
print(n.getValueOfPoint(np.array([1, 1, 1]), 2))
|
|
|
|
|
print(n.getValueOfPoint(np.array([1, 0.8, 1.5]), 1))
|