gudhi.point_cloud.knn.KNearestNeighbors Class Reference

Public Member Functions

def __init__ (self, k, return_index=True, return_distance=False, metric="euclidean", **kwargs)
 
def fit (self, X, y=None)
 
def transform (self, X)
 

Detailed Description

Class wrapping several implementations for computing the k nearest neighbors in a point set.

:Requires: `PyKeOps <installation.html#pykeops>`_, `SciPy <installation.html#scipy>`_,
    `Scikit-learn <installation.html#scikit-learn>`_, and/or `Hnswlib <installation.html#hnswlib>`_
    in function of the selected `implementation`.

Constructor & Destructor Documentation

◆ __init__()

def gudhi.point_cloud.knn.KNearestNeighbors.__init__ (   self,
  k,
  return_index = True,
  return_distance = False,
  metric = "euclidean",
**  kwargs 
)
Args:
    k (int): number of neighbors (possibly including the point itself).
    return_index (bool): if True, return the index of each neighbor.
    return_distance (bool): if True, return the distance to each neighbor.
    implementation (str): choice of the library that does the real work.

* 'keops' for a brute-force, CUDA implementation through pykeops. Useful when the dimension becomes large (10+) but the number of points remains low (less than a million). Only "minkowski" and its aliases are supported.
* 'ckdtree' for scipy's cKDTree. Only "minkowski" and its aliases are supported.
* 'sklearn' for scikit-learn's NearestNeighbors. Note that this provides in particular an option algorithm="brute".
* 'hnsw' for hnswlib.Index. It can be very fast but does not provide guarantees. Only supports "euclidean" for now.
* None will try to select a sensible one (scipy if possible, scikit-learn otherwise).
    metric (str): see `sklearn.neighbors.NearestNeighbors`.
    eps (float): relative error when computing nearest neighbors with the cKDTree.
    p (float): norm L^p on input points (including numpy.inf) if metric is "minkowski". Defaults to 2.
    n_jobs (int): number of jobs to schedule for parallel processing of nearest neighbors on the CPU.
If -1 is given all processors are used. Default: 1.
    sort_results (bool): if True, then distances and indices of each point are
sorted on return, so that the first column contains the closest points.
Otherwise, neighbors are returned in an arbitrary order. Defaults to True.
    enable_autodiff (bool): if the input is a torch.tensor or tensorflow.Tensor, this
instructs the function to compute distances in a way that works with automatic differentiation.
This is experimental, not supported for all metrics, and requires the package EagerPy.
Defaults to False.
    kwargs: additional parameters are forwarded to the backends.

Member Function Documentation

◆ fit()

def gudhi.point_cloud.knn.KNearestNeighbors.fit (   self,
  X,
  y = None 
)
Args:
    X (numpy.array): coordinates for reference points.

◆ transform()

def gudhi.point_cloud.knn.KNearestNeighbors.transform (   self,
  X 
)
Args:
    X (numpy.array): coordinates for query points, or distance matrix if metric is "precomputed".

Returns:
    numpy.array: if return_index, an array of shape (len(X), k) with the indices (in the argument
    of :func:`fit`) of the k nearest neighbors to the points of X. If return_distance, an array of the
    same shape with the distances to those neighbors. If both, a tuple with the two arrays, in this order.

The documentation for this class was generated from the following file:
GUDHI  Version 3.3.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : MIT Generated on Tue Aug 11 2020 11:58:59 for GUDHI by Doxygen 1.8.18