diff --git a/benchmarks/kd_tree.exs b/benchmarks/kd_tree.exs deleted file mode 100644 index 2dca6bea..00000000 --- a/benchmarks/kd_tree.exs +++ /dev/null @@ -1,14 +0,0 @@ -# mix run benchmarks/kd_tree.exs -Nx.global_default_backend(EXLA.Backend) -Nx.Defn.global_default_options(compiler: EXLA) - -key = Nx.Random.key(System.os_time()) -{uniform, _new_key} = Nx.Random.uniform(key, shape: {1000, 3}) - -Benchee.run( - %{ - "bounded" => fn -> Scholar.Neighbors.KDTree.fit(uniform) end - }, - time: 10, - memory_time: 2 -) diff --git a/lib/scholar/neighbors/k_nearest_neighbors.ex b/lib/scholar/neighbors/k_nearest_neighbors.ex index a41ee5c8..5ccb62f2 100644 --- a/lib/scholar/neighbors/k_nearest_neighbors.ex +++ b/lib/scholar/neighbors/k_nearest_neighbors.ex @@ -3,7 +3,9 @@ defmodule Scholar.Neighbors.KNearestNeighbors do The K-Nearest Neighbors. It implements both classification and regression. This implements the linear - version of kNN and therefore it has time complexity $O(N^2)$ for $N$ samples. + (brute) version of kNN and therefore it has time complexity $O(N^2)$ for $N$ + samples. See `Scholar.Neighbors.KDTree` for an alternative implementation which + is also exact. """ import Nx.Defn import Scholar.Shared diff --git a/lib/scholar/neighbors/kd_tree.ex b/lib/scholar/neighbors/kd_tree.ex index 1377d60e..4d33c7e3 100644 --- a/lib/scholar/neighbors/kd_tree.ex +++ b/lib/scholar/neighbors/kd_tree.ex @@ -3,6 +3,8 @@ defmodule Scholar.Neighbors.KDTree do Implements a kd-tree, a space-partitioning data structure for organizing points in a k-dimensional space. + It can be used to predict the K-Nearest Neighbors of a given input. + This is implemented as one-dimensional tensor with indices pointed to highest dimension of the given tensor. Traversal starts by calling `root/0` and then accessing the `left_child/1` and `right_child/1`. The tree is left-balanced. diff --git a/lib/scholar/neighbors/radius_nearest_neighbors.ex b/lib/scholar/neighbors/radius_nearest_neighbors.ex index b1eca0e3..65181fc1 100644 --- a/lib/scholar/neighbors/radius_nearest_neighbors.ex +++ b/lib/scholar/neighbors/radius_nearest_neighbors.ex @@ -163,7 +163,7 @@ defmodule Scholar.Neighbors.RadiusNearestNeighbors do ## Return Values - It returns a tensor with predicted class labels + It returns a tensor with predicted class labels. ## Examples @@ -258,7 +258,7 @@ defmodule Scholar.Neighbors.RadiusNearestNeighbors do ## Return Values - Returns indices of the selected neighbor points as a mask (1 if a point is a neighbor, 0 otherwise) and their respective distances. + Returns indices of the selected neighbor points as a mask (1 if a point is a neighbor, 0 otherwise) and their respective distances. ## Examples