Source code for gudhi.point_cloud.dtm
# This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
# See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
# Author(s): Marc Glisse
#
# Copyright (C) 2020 Inria
#
# Modification(s):
# - YYYY/MM Author: Description of the modification
from .knn import KNearestNeighbors
__author__ = "Marc Glisse"
__copyright__ = "Copyright (C) 2020 Inria"
__license__ = "MIT"
[docs]class DistanceToMeasure:
"""
Class to compute the distance to the empirical measure defined by a point set, as introduced in :cite:`dtm`.
"""
[docs] def __init__(self, k, q=2, **kwargs):
"""
Args:
k (int): number of neighbors (possibly including the point itself).
q (float): order used to compute the distance to measure. Defaults to 2.
kwargs: same parameters as :class:`~gudhi.point_cloud.knn.KNearestNeighbors`, except that
metric="neighbors" means that :func:`transform` expects an array with the distances
to the k nearest neighbors.
"""
self.k = k
self.q = q
self.params = kwargs
[docs] def fit(self, X, y=None):
"""
Args:
X (numpy.array): coordinates for mass points.
"""
if self.params.setdefault("metric", "euclidean") != "neighbors":
self.knn = KNearestNeighbors(
self.k, return_index=False, return_distance=True, sort_results=False, **self.params
)
self.knn.fit(X)
return self