Skip to content

Commit fe158bc

Browse files
committed
Improved docstrings
1 parent fa90e0c commit fe158bc

2 files changed

Lines changed: 73 additions & 3 deletions

File tree

src/tdamapper/cover.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,28 @@
2727

2828

2929
class _Pullback(Generic[S_contra, T_contra]):
30+
"""
31+
Pullback pseudo-metric function.
32+
33+
This class is used to adapt a metric function that operates on a
34+
transformed space to work with the original space. It applies a function
35+
to the input data before computing the distance, effectively pulling back
36+
the metric to the original space.
37+
38+
Given a function :math:`f: X \to Y` and a metric
39+
:math:`d: Y \times Y \to \\mathbb{R}`,
40+
this class defines a new pseudo-metric
41+
:math:`d': X \times X \to \\mathbb{R}` such that:
42+
:math:`d'(x_1, x_2) = d(f(x_1), f(x_2))`.
43+
44+
When :math:`f` is injective, this pseudo-metric :math:`d'` is a true
45+
metric. If :math:`f` is not injective, it is a pseudo-metric, meaning it
46+
may not satisfy the identity of two objects :math:`x_1`, :math:`x_2` with
47+
:math:`d'(x_1, x_2) = 0`.
48+
49+
:param fun: A function that transforms the input data.
50+
:param dist: A metric function that operates on the transformed data.
51+
"""
3052

3153
def __init__(
3254
self, fun: Callable[[S_contra], T_contra], dist: Metric[T_contra]
@@ -35,10 +57,24 @@ def __init__(
3557
self.dist = dist
3658

3759
def __call__(self, x: S_contra, y: S_contra) -> float:
60+
"""
61+
Compute the distance between two points in the original space
62+
using the pullback metric.
63+
64+
This method applies the transformation function to both points and
65+
then computes the distance using the provided metric function.
66+
67+
:param x: A point in the original space.
68+
:param y: Another point in the original space.
69+
:return: The distance between the transformed points in the metric space.
70+
"""
3871
return self.dist(self.fun(x), self.fun(y))
3972

4073

4174
def _snd(x: tuple[T, ...]) -> T:
75+
"""
76+
Extract the second element from a tuple.
77+
"""
4278
return x[1]
4379

4480

@@ -242,6 +278,35 @@ def apply(self, X: ArrayRead[T_contra]) -> Iterator[list[int]]:
242278

243279

244280
class BaseCubicalCover:
281+
"""
282+
Base class for cubical cover algorithms, which cover data with open
283+
hypercubes of uniform size and overlap. This class provides the basic
284+
functionality for cubical covers, including the initialization of parameters
285+
and the methods for computing the center of a hypercube and its overlap.
286+
287+
A hypercube is a multidimensional generalization of a square or a cube.
288+
The size and overlap of the hypercubes are determined by the number of
289+
intervals and the overlap fraction parameters. This class maps each point
290+
to the hypercube with the nearest center.
291+
292+
:param n_intervals: The number of intervals to use for each dimension.
293+
Must be positive and less than or equal to the length of the dataset.
294+
Defaults to 1.
295+
:param overlap_frac: The fraction of overlap between adjacent intervals on
296+
each dimension, must be in the range (0.0, 0.5]. If not specified, the
297+
overlap_frac is computed such that the volume of the overlap within
298+
each hypercube is half the total volume. Defaults to None.
299+
:param kind: Specifies whether to use a flat or a hierarchical vantage
300+
point tree. Acceptable values are 'flat' or 'hierarchical'. Defaults to
301+
'flat'.
302+
:param leaf_capacity: The maximum number of points in a leaf node of the
303+
vantage point tree. Must be a positive value. Defaults to 1.
304+
:param leaf_radius: The radius of the leaf nodes. If not specified, it
305+
defaults to the value of `radius`. Must be a positive value. Defaults
306+
to None.
307+
:param pivoting: The method used for pivoting in the vantage point tree.
308+
Acceptable values are None, 'random', or 'furthest'. Defaults to None.
309+
"""
245310

246311
_overlap_frac: float
247312
_n_intervals: int

src/tdamapper/protocols.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
"""
2-
This module defines various protocols used in the tdamapper library. These
3-
protocols specify the expected behavior of different components such as arrays,
4-
metrics, covers, clustering algorithms, and spatial search algorithms.
2+
Protocols for type hinting in tdamapper.
3+
4+
These protocols define the expected interfaces for various components
5+
used in the tdamapper library, such as array-like structures, metrics,
6+
cover algorithms, clustering algorithms, and spatial search algorithms.
7+
They are used to ensure that the components adhere to the expected
8+
behaviors and can be used interchangeably in the library's functions
9+
and methods.
510
"""
611

712
from __future__ import annotations

0 commit comments

Comments
 (0)