KMeansTree

KMeansTree(points, numberofclusters; ...) builds a BoundingBallTree by recursively partitioning points with k-means.

Construction outline:

  1. A root cluster is fitted and the root center/radius are initialized.
  2. Each node is split with k-means into numberofclusters child clusters while length(values(node)) >= max(minvalues, numberofclusters).
  3. Children store point indices and their local center/radius.
  4. Internal-node point lists are emptied after splitting, and node ordering is adjusted.
  5. Node radii are finalized via updateradii! (default: boundingsphere).
Warning

If you use updateradii=H2Trees.unsafemaxradiusboundingsphere or updateradii=H2Trees.noboundingsphereupdate, the radii are not reliably updated. This can lead to incorrect results when using iterators in H2Trees. Proceed at your own risk.

using CompScienceMeshes
using H2Trees
using PlotlyJS
using ParallelKMeans

m = meshsphere(1.0, 0.1)
tree = KMeansTree(vertices(m), 4; minvalues=60)
using CompScienceMeshes
using H2Trees
using PlotlyJS
using ParallelKMeans

m = meshsphere(1.0, 0.1)
tree = KMeansTree(
    vertices(m),
    4;
    minvalues=60,
    updateradii=H2Trees.noboundingsphereupdate,
)
using CompScienceMeshes
using H2Trees
using PlotlyJS
using ParallelKMeans

m = meshsphere(1.0, 0.1)
tree = KMeansTree(
    vertices(m),
    4;
    minvalues=60,
    updateradii=H2Trees.unsafemaxradiusboundingsphere
)