Source code for tdamapper.utils.vptree

"""
A module for fast knn and range searches, depending only on a given metric
"""

from tdamapper.utils.vptree_flat.vptree import VPTree as FVPT
from tdamapper.utils.vptree_hier.vptree import VPTree as HVPT


[docs] class VPTree: """ A Vantage Point Tree, or vp-tree, for fast range-queries and knn-queries. :param X: A dataset of n points. :type X: array-like of shape (n, m) or list-like of length n :param metric: The metric used to define the distance between points. Accepts any value compatible with `tdamapper.utils.metrics.get_metric`. Defaults to 'euclidean'. :type metric: str or callable :param metric_params: Additional parameters for the metric function, to be passed to `tdamapper.utils.metrics.get_metric`. Defaults to None. :type metric_params: dict, optional :param kind: Specifies whether to use a flat or a hierarchical vantage point tree. Acceptable values are 'flat' or 'hierarchical'. Defaults to 'flat'. :type kind: str :param leaf_capacity: The maximum number of points in a leaf node of the vantage point tree. Must be a positive value. Defaults to 1. :type leaf_capacity: int :param leaf_radius: The radius of the leaf nodes. Must be a positive value. Defaults to 0.0. :type leaf_radius: float :param pivoting: The method used for pivoting in the vantage point tree. Acceptable values are None, 'random', or 'furthest'. Defaults to None. :type pivoting: str or callable, optional """ def __init__( self, X, metric="euclidean", metric_params=None, kind="flat", leaf_capacity=1, leaf_radius=0.0, pivoting=None, ): builder = FVPT if kind == "flat": builder = FVPT elif kind == "hierarchical": builder = HVPT else: raise ValueError(f"Unknown kind of vptree: {kind}") self._vpt = builder( X, metric=metric, metric_params=metric_params, leaf_capacity=leaf_capacity, leaf_radius=leaf_radius, pivoting=pivoting, )