Computational topology and topological data analysis library providing state-of-the-art algorithms for constructing simplicial complexes and computing persistent homology
—
Specialized tools for analyzing and processing point clouds including distance-to-measure computations, subsampling algorithms, nearest neighbor queries, and time delay embedding for time series data.
Robust distance computation that provides outlier-resistant alternatives to standard distance functions by computing distances to empirical measures.
class DistanceToMeasure:
def __init__(self, k: int, q: float = 2.0):
"""
Initialize Distance to Measure estimator.
Parameters:
- k: Number of neighbors for distance computation
- q: Power parameter for Lq norm
"""
def fit_transform(self, X):
"""
Compute distance to measure for point cloud.
Parameters:
- X: Point cloud as array-like
Returns:
array: DTM values for each point
"""
def compute_distance_to_measure(self, X):
"""
Compute DTM values.
Parameters:
- X: Input point cloud
Returns:
array: Distance to measure values
"""Efficient nearest neighbor queries for point clouds with support for various distance metrics.
class KNearestNeighbors:
def __init__(self, k: int, metric: str = "euclidean"):
"""
Initialize k-nearest neighbors estimator.
Parameters:
- k: Number of neighbors
- metric: Distance metric ("euclidean", "manhattan", etc.)
"""
def fit(self, X):
"""
Fit the estimator to point cloud.
Parameters:
- X: Training point cloud
"""
def transform(self, X):
"""
Find k-nearest neighbors.
Parameters:
- X: Query points
Returns:
tuple: (distances, indices) of k-nearest neighbors
"""Transforms time series data into point clouds using time delay embedding for topological analysis of dynamical systems.
class TimeDelayEmbedding:
def __init__(self, dim: int = 3, delay: int = 1, skip: int = 1):
"""
Initialize time delay embedding.
Parameters:
- dim: Embedding dimension
- delay: Time delay between coordinates
- skip: Subsampling parameter
"""
def fit_transform(self, X):
"""
Transform time series to embedded point cloud.
Parameters:
- X: Time series data
Returns:
array: Embedded point cloud
"""Algorithms for reducing point cloud size while preserving topological and geometric properties.
def choose_n_farthest_points(points, nb_points: int, starting_point: int = None):
"""
Farthest point sampling for point cloud subsampling.
Parameters:
- points: Input point cloud
- nb_points: Number of points to select
- starting_point: Index of starting point (random if None)
Returns:
list: Indices of selected points
"""
def pick_n_random_points(points, nb_points: int):
"""
Random subsampling of point cloud.
Parameters:
- points: Input point cloud
- nb_points: Number of points to select
Returns:
list: Indices of randomly selected points
"""
def sparsify_point_set(points, min_squared_distance: float):
"""
Sparsify point cloud by minimum distance constraint.
Parameters:
- points: Input point cloud
- min_squared_distance: Minimum squared distance between points
Returns:
list: Indices of points in sparsified set
"""import gudhi
import numpy as np
# Generate noisy point cloud
points = np.random.random((100, 2))
# Add some outliers
outliers = np.random.random((10, 2)) * 5
noisy_points = np.vstack([points, outliers])
# Compute distance to measure
dtm = gudhi.point_cloud.DistanceToMeasure(k=10)
dtm_values = dtm.fit_transform(noisy_points)
print(f"DTM values shape: {dtm_values.shape}")import gudhi
import numpy as np
# Generate dense point cloud
points = np.random.random((1000, 3))
# Subsample using farthest point sampling
subsampled_indices = gudhi.choose_n_farthest_points(points, 100)
subsampled_points = points[subsampled_indices]
print(f"Original: {len(points)} points, Subsampled: {len(subsampled_points)} points")import gudhi
import numpy as np
# Generate time series (sine wave with noise)
t = np.linspace(0, 4*np.pi, 1000)
time_series = np.sin(t) + 0.1 * np.random.randn(1000)
# Create time delay embedding
embedding = gudhi.point_cloud.TimeDelayEmbedding(dim=3, delay=10)
embedded_points = embedding.fit_transform(time_series)
print(f"Time series length: {len(time_series)}")
print(f"Embedded point cloud shape: {embedded_points.shape}")
# Analyze topology of embedded attractor
rips = gudhi.RipsComplex(points=embedded_points, max_edge_length=0.5)
st = rips.create_simplex_tree(max_dimension=1)
persistence = st.persistence()import gudhi
import numpy as np
# Generate point cloud
points = np.random.random((200, 2))
# Find k-nearest neighbors
knn = gudhi.point_cloud.KNearestNeighbors(k=5)
knn.fit(points)
# Query neighbors for subset of points
query_points = points[:10]
distances, indices = knn.transform(query_points)
print(f"Distances shape: {distances.shape}")
print(f"Indices shape: {indices.shape}")Install with Tessl CLI
npx tessl i tessl/pypi-gudhi