concept core point in category algorithms

appears as: core point, core points, core point, core points
Algorithms and Data Structures in Action

This is an excerpt from Manning's book Algorithms and Data Structures in Action.

Notice that since we would like to find out the index of the centroid closer to each point, we assume that the KdTree object can keep track of the indices of its points in the initialization array, and that we have a query method that returns the index of the closest point, rather than the point itself. It’s not hard to find a workaround if this is not the case: we can keep a hash table associating centroids to their indices, and add an extra step to retrieve the index of the centroid returned by the KdTree.

Listing 12.5 classifyPoints using k-d trees
function classifyPoints(points, centroids)                    #1
  clusters ← []                                #2
  kdTree ← new KdTree(centroids)                        #3
  for i in {0, .., |points|-1} do                        #4
    clusters[i] ← kdTree.nearestNeighborIndex(point)            #5
  return clusters                                #6

#3 Create a KdTree instance, initializing it with the list of centroids.

#4 Cycle through the list of points in the dataset (their indices).

#5 Get the index of the nearest centroid for this point by querying the KdTree.

As we have seen, however, if the theoretical margin is small, sometimes a more complex implementation only beats asymptotically worse solutions for large, or at times very large, inputs. To double check if in practice it is worth to go through the trouble of creating and searching a k-d tree at each iteration, we ran some profiling, that you can check out on the book’s repo.

Figure 12.7 Running time comparison between classifyPoints implementations using brute-force search and k-d tree’s nearest neighbor. The running times are shown as functions of n, the number of points, for fixed values of k, the number of centroids.
(top left) k==5, the method using k-d tree is always slower, and its running time grows faster.
(top right) k == 50, the method using a k-d tree is still slower, but its growth is similar to the brute-force one.
(bottom left) k==75, the method using brute-force is initially taking a similar time, but as n grows, the curves for the two running times diverge and k-d tree implementation grows more slowly.
(bottom right) k==200, the k-d tree implementation takes half the time of the brute-force approach even for small values of n, and it grows much more slowly.

Once again, we used a Python implementation to do the comparison: by now it should go without saying, but these results are obviously only significant for this language and this particular implementation. Nevertheless, they do prove something.