Example #1
0
def _nearest_neighbor(new, points):
	classe = None
	# Compute the nearest neighbor
	c = (points[0], dist(new[0], points[0][0], new[1], points[0][1]))
	for p in points:
		distance = dist(new[0], p[0], new[1], p[1])
		if(distance < c[1]):
			c = (p, distance)
	points.remove(c[0])

	# If the NN and the new point are the same, their class is the same
	if(new[0] == c[0][0] and new[1] == c[0][1]):
		classe = c[0][2]

	return c, points, classe
Example #2
0
def _couples_creation(c, points):
	# dist(a, b)
	couples = []
	for ida, a in enumerate(points):
		for idb in range(ida):
			couples.append([a, points[idb], dist(a[0], points[idb][0], a[1], points[idb][1])])

	# dist(a, b) ~= dist(c, d)
	for couple in couples:
		couple[-1] = abs(couple[-1] - c[1]) # couples[-1] is the distance
	couples.sort(key=lambda c: c[2])
	couples.reverse()

	return couples