Bundle Core machine learning types: the seedable Random generator, Matrix2D linear algebra and activations, matrix reference holders, the NeuralNetwork and CSV-backed MatrixReader. Compile with -lib ml.
KDTree
K-d tree for fast exact nearest-neighbor queries over numeric rows. Built by median splits cycling through the dimensions; queries prune subtrees whose splitting plane lies farther than the current k-th best distance. Equivalent results to a brute-force scan (Euclidean).
Example
tree := KDTree->New(matrix);
nearest := tree->Nearest(3, [57.0, 170.0]); # row indexes, closest firstOperations
Nearest #
Finds the k nearest rows to the query point.
method : public : Nearest(k:Int, query:Float[]) ~ Int[]Parameters
| Name | Type | Description |
|---|---|---|
| k | Int | number of neighbors |
| query | Float | query point (length = features) |
Return
| Type | Description |
|---|---|
| Int | row indexes sorted closest-first (fewer than k when the tree is smaller), or Nil on invalid input |