From 4da2fe71052b75b30c701fa783f64f42e7993b4d Mon Sep 17 00:00:00 2001 From: Olivia Coffey Date: Mon, 20 Jan 2020 15:43:01 -0500 Subject: [PATCH] edits for proper rendering --- README.md | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e53d840..792d913 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ -Ruby k-d tree -============= +# Ruby k-d tree Ruby implementation of "K-Dimensional Tree" and "N-Nearest Neighbors" based on [http://en.wikipedia.org/wiki/Kd-tree](http://en.wikipedia.org/wiki/Kd-tree). -##API -#####Initialize +## API + +### Initialize + Build a new tree on a set of (2 or higher dimensional) coordinates: ```ruby @@ -12,13 +13,17 @@ points = [[2,3], [5,4], [9,6], [4,7], [8,1], [7,2]] kdtree = KDTree.new points ``` -#####Flatten +### Flatten + Get an inorder representation as an array + ```ruby kdtree.to_a => [[2, 3], [5, 4], [4, 7], [7, 2], [8, 1], [9, 6]] ``` -#####Print + +### Print + ```ruby kdtree.print => @@ -29,16 +34,23 @@ kdtree.print [5, 4] [2, 3] ``` -#####Nearest Neighbors + +### Nearest Neighbors + Current implementation uses squared euclidean as distance metric. -That is, for any 2 points a and b in D-dimensional space:
+That is, for any 2 points a and b in D-dimensional space: + ![equation](http://latex.codecogs.com/gif.latex?%5Csum_%7Bd%3D1%7D%5E%7BD%7D%28a_d-b_d%29%5E2) -#####1-NN + +### 1-NN + ```ruby kdtree.nnearest([1,1]) => [[2, 3]] ``` -#####k-NN + +### k-NN + ```ruby kdtree.nnearest([1,1],3) => [[7, 2], [5, 4], [2, 3]]