topology-data-analysis
安装方式
先用 Prompt 核对来源,也可切换到安装命令或下载可用的安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "topology-data-analysis":https://skillpi.com/zh/skills/deepskill-6d9dd72a5d2db612a13733f96f2df9c697295d2890f05da4aafce82b2d5b7906。安装前核对上游来源和版本:https://github.com/brycewang-stanford/Auto-Empirical-Research-Skills/blob/bfa0a6e5a843babbf45a1ef1663fd5dc4f07c0ba/skills/43-wentorai-research-plugins/skills/domains/math/topology-data-analysis/SKILL.md。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
此命令从 GitHub 来源仓库获取指定技能。运行前请先查看源文件。
npx skills add https://github.com/brycewang-stanford/Auto-Empirical-Research-Skills/tree/bfa0a6e5a843babbf45a1ef1663fd5dc4f07c0ba/skills/43-wentorai-research-plugins/skills/domains/math/topology-data-analysis --skill topology-data-analysis来源与配置
查看 GitHub 源码brycewang-stanford/Auto-Empirical-Research-Skills固定提交 bfa0a6e5a843babbf45a1ef1663fd5dc4f07c0ba
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
本条目面向文献与学术工具场景,提供“topology-data-analysis”技能的目录入口。公开标签:learning、拓扑分析、持续同调、Mapper算法。请通过固定上游版本核对实际功能、依赖与权限;此页为 Skillπ 独立编写的用途介绍和原站链接,不代表运行安全保证。原文与附件依各自许可开放。
文件浏览
---
name: topology-data-analysis
description: "Topological data analysis: persistent homology, Mapper, and TDA tools"
metadata:
openclaw:
emoji: "🖇️"
category: "domains"
subcategory: "math"
keywords: ["topology", "persistent-homology", "tda", "mapper", "betti-numbers", "point-cloud"]
source: "wentor"
---
# Topological Data Analysis
A skill for applying topological data analysis (TDA) methods to research data. Covers persistent homology, Vietoris-Rips complexes, persistence diagrams, the Mapper algorithm, and vectorization methods for integrating topological features into machine learning pipelines.
## Core Concepts
### Simplicial Complexes from Data
TDA extracts topological features (connected components, loops, voids) from data by building simplicial complexes at multiple scales:
| Complex | Construction | Computational Cost |
|---------|-------------|-------------------|
| Vietoris-Rips | Edge if distance < epsilon | O(n^d) for d-simplices |
| Cech | Ball intersection (exact) | Computationally expensive |
| Alpha | Delaunay-based (exact in low dim) | Efficient in R^2, R^3 |
| Cubical | Grid-based (for images) | Linear in pixels |
### Filtration and Persistence
```
Scale epsilon: 0.1 0.3 0.5 0.7 1.0
|------|------|------|------|------|
Components: 10 6 3 2 1
(H0 features born at 0, die at merging scale)
Loops: 0 0 1 2 0
(H1 features born when loop forms, die when filled)
```
A feature that persists across many scales is a genuine topological signal; short-lived features are noise.
## Persistent Homology with Ripser
### Computing Persistence Diagrams
```python
import numpy as np
from ripser import ripser
from persim import plot_diagrams
def compute_persistence(point_cloud: np.ndarray,
max_dim: int = 2,
max_edge: float = 2.0) -> dict:
"""
Compute persistent homology of a point cloud.
point_cloud: (n_points, n_dimensions) array
max_dim: maximum homology dimension to compute
max_edge: maximum edge length in Rips complex
Returns persistence diagrams for each dimension.
"""
result = ripser(
point_cloud,
maxdim=max_dim,
thresh=max_edge,
)
diagrams = result["dgms"]
summary = {}
for dim, dgm in enumerate(diagrams):
# Filter out infinite death times for H0
finite = dgm[dgm[:, 1] < np.inf] if len(dgm) > 0 else dgm
lifetimes = finite[:, 1] - finite[:, 0] if len(finite) > 0 else np.array([])
summary[f"H{dim}"] = {
"n_features": len(finite),
"max_persistence": float(lifetimes.max()) if len(lifetimes) > 0 else 0,
"mean_persistence": float(lifetimes.mean()) if len(lifetimes) > 0 else 0,
"birth_death_pairs": finite.tolist(),
}
return summary
# Example: torus point cloud
def sample_torus(n=1000, R=3.0, r=1.0, noise=0.1):
"""Sample points from a torus in R^3."""
theta = np.random.uniform(0, 2 * np.pi, n)
phi = np.random.uniform(0, 2 * np.pi, n)
x = (R + r * np.cos(phi)) * np.cos(theta) + np.random.normal(0, noise, n)
y = (R + r * np.cos(phi)) * np.sin(theta) + np.random.normal(0, noise, n)
z = r * np.sin(phi) + np.random.normal(0, noise, n)
return np.column_stack([x, y, z])
torus = sample_torus(500)
persistence = compute_persistence(torus, max_dim=2)
# Expected: H0 has 1 long-lived component,
# H1 has 2 prominent loops (the two fundamental cycles),
# H2 has 1 prominent void (the cavity)
```
## Persistence Vectorization
### Converting Persistence to Feature Vectors
To use topological features in machine learning, persistence diagrams must be vectorized:
```python
from sklearn.base import BaseEstimator, TransformerMixin
class PersistenceStatistics(BaseEstimator, TransformerMixin):
"""
Extract statistical features from persistence diagrams.
Produces a fixed-length feature vector from variable-length diagrams.
"""
def __init__(self, max_dim: int = 1):
self.max_dim = max_dim
def fit(self, X, y=None):
return self
def transform(self, diagrams_list: list) -> np.ndarray:
features = []
for diagrams in diagrams_list:
row = []
for dim in range(self.max_dim + 1):
dgm = diagrams[dim]
lifetimes = dgm[:, 1] - dgm[:, 0]
lifetimes = lifetimes[np.isfinite(lifetimes)]
if len(lifetimes) == 0:
row.extend([0, 0, 0, 0, 0, 0])
else:
row.extend([
len(lifetimes), # count
np.sum(lifetimes), # total persistence
np.max(lifetimes), # max persistence
np.mean(lifetimes), # mean persistence
np.std(lifetimes), # std persistence
np.sum(lifetimes ** 2), # persistence entropy proxy
])
features.append(row)
return np.array(features)
```
### Persistence Images
```python
def persistence_image(diagram: np.ndarray, resolution: int = 20,
sigma: float = 0.1,
weight_fn=None) -> np.ndarray:
"""
Compute a persistence image from a persistence diagram.
Transforms birth-death pairs into a stable, fixed-size representation.
"""
if weight_fn is None:
weight_fn = lambda birth, persistence: persistence
# Transform to birth-persistence coordinates
births = diagram[:, 0]
persistences = diagram[:, 1] - diagram[:, 0]
# Create grid
x_range = np.linspace(births.min() - sigma, births.max() + sigma, resolution)
y_range = np.linspace(0, persistences.max() + sigma, resolution)
xx, yy = np.meshgrid(x_range, y_range)
image = np.zeros((resolution, resolution))
for b, p in zip(births, persistences):
if not np.isfinite(p):
continue
w = weight_fn(b, p)
gaussian = w * np.exp(-((xx - b)**2 + (yy - p)**2) / (2 * sigma**2))
image += gaussian
return image
```
## The Mapper Algorithm
### Constructing Mapper Graphs
Mapper provides a compressed topological summary of high-dimensional data:
```python
import kmapper as km
from sklearn.cluster import DBSCAN
def run_mapper(data: np.ndarray, lens_fn=None, n_cubes: int = 10,
overlap: float = 0.3) -> dict:
"""
Run the Mapper algorithm to produce a simplicial complex
summarizing the shape of the data.
data: (n_samples, n_features) array
lens_fn: filter function (default: first two PCA components)
"""
mapper = km.KeplerMapper(verbose=0)
# Compute lens (filter function)
if lens_fn is None:
from sklearn.decomposition import PCA
lens = mapper.fit_transform(data, projection=PCA(n_components=2))
else:
lens = lens_fn(data)
# Build the Mapper graph
graph = mapper.map(
lens, data,
cover=km.Cover(n_cubes=n_cubes, perc_overlap=overlap),
clusterer=DBSCAN(eps=0.5, min_samples=3),
)
# Summary statistics
n_nodes = len(graph["nodes"])
n_edges = sum(len(v) for v in graph["links"].values()) // 2
return {
"n_nodes": n_nodes,
"n_edges": n_edges,
"node_sizes": [len(v) for v in graph["nodes"].values()],
"graph": graph,
}
```
### Mapper Parameters
| Parameter | Effect | Guidance |
|-----------|--------|---------|
| Filter function | Projects data to low dimensions | PCA, eccentricity, density |
| Number of intervals | Controls resolution of cover | 10-30 typical |
| Overlap percentage | Controls connectivity | 20-50%, higher = more edges |
| Clustering algorithm | Groups points within intervals | DBSCAN, single-linkage |
## Stability and Statistical Significance
### Bottleneck and Wasserstein Distances
```python
from persim import bottleneck, wasserstein
def compare_persistence_diagrams(dgm1: np.ndarray,
dgm2: np.ndarray) -> dict:
"""
Compare two persistence diagrams using standard TDA distances.
"""
bn_dist = bottleneck(dgm1, dgm2)
ws_dist = wasserstein(dgm1, dgm2, order=2)
return {
"bottleneck_distance": round(bn_dist, 6),
"wasserstein_2_distance": round(ws_dist, 6),
}
```
### Permutation Test for Topological Features
```python
def permutation_test_persistence(data1: np.ndarray, data2: np.ndarray,
n_permutations: int = 1000,
dim: int = 1) -> dict:
"""
Test whether two point clouds have significantly different
topological features using a permutation test on Wasserstein distance.
"""
from persim import wasserstein
# Observed distance
dgm1 = ripser(data1, maxdim=dim)["dgms"][dim]
dgm2 = ripser(data2, maxdim=dim)["dgms"][dim]
observed = wasserstein(dgm1, dgm2)
# Permutation distribution
combined = np.vstack([data1, data2])
n1 = len(data1)
perm_distances = []
for _ in range(n_permutations):
perm = np.random.permutation(len(combined))
perm_d1 = combined[perm[:n1]]
perm_d2 = combined[perm[n1:]]
perm_dgm1 = ripser(perm_d1, maxdim=dim)["dgms"][dim]
perm_dgm2 = ripser(perm_d2, maxdim=dim)["dgms"][dim]
perm_distances.append(wasserstein(perm_dgm1, perm_dgm2))
p_value = np.mean(np.array(perm_distances) >= observed)
return {
"observed_distance": round(observed, 6),
"p_value": round(p_value, 4),
"significant_at_005": p_value < 0.05,
}
```
## Tools and Libraries
- **Ripser / ripser.py**: Fast Vietoris-Rips persistence computation
- **GUDHI**: Comprehensive TDA library (C++ with Python bindings)
- **persim**: Persistence diagram distances and visualization
- **KeplerMapper**: Python Mapper algorithm implementation
- **giotto-tda**: TDA integrated with scikit-learn API
- **Dionysus 2**: Persistent homology and cohomology
- **scikit-tda**: Meta-package bundling ripser, persim, kepler-mapper, tadasets
版本历史
-
v2026.07
GitHub ↗
原版更新说明
## Highlights - **First tagged release.** Every gate is green: `make check` (validate + 183 unit tests + eval-harness + numeric benchmarks), validate-catalog, quality-evals, and OpenSSF Scorecard on `main`. - **Rigor double loop at 13 method families.** Each family closes taxonomy tag → eval scenario (does the agent avoid the method's known traps?) → deterministic numeric benchmark (does it recover the true effect?). New this cycle: heterogeneous treatment effects (CATE) and quantile treatment effects (QTE). - **Paper-WorkFlow flagship at 29/29 executable rigor gates**, now merged to its `main` with a drift-gated README badge — the credibility artifact is checked by CI, so it can never silently go stale ([RIGOR.md](https://github.com/brycewang-stanford/Paper-WorkFlow/blob/main/RIGOR.md)). - **1,150 vendored skills / 69 collections**, all license-audited, security-scanned, tracked in a machine-readable catalog with CI-enforced freshness, and importable as a single whole-repo router skill. - **Hardened weekly upstream syncs**: synced trees must pass the full gate before merge; this cycle both sync PRs were verified, patched (StatsPAI's SkillOpt execution-gate card restored), and merged. - **First-party plugin marketplace** (Python / R / Stata empirical-analysis plugins + guide) shipped in the previous cycle, now under a tagged version. ## Known Follow-Ups - Ecosystem benchmark comparison (AERS vs econometrics agents on the shared benchmark suite) — [PLAN-2026-07 week 3](https://github.com/brycewang-stanford/Auto-Empirical-Research-Skills/blob/main/docs/PLAN-2026-07.md). - Decomposition (Oaxaca–Blinder) and shift-share (Bartik) method families (weeks 3–4). - GitHub Pages catalog site, README demo screenshots, five-language README consistency script (week 4). ## Catalog - Top-level collections: **69** - `SKILL.md` files: **1150** - Cataloged agent tools: **335** ([`tools/CATALOG.md`](../tools/CATALOG.md)) ## Methodological rigor - Method families in the coverage map: **13** ([`RIGOR_COVERAGE.md`](RIGOR_COVERAGE.md)) - Eval scenarios: **26** (138 rubric items, 122 auto-checkable) ([`../eval-harness/`](../eval-harness/README.md)) - Benchmark tasks: **13** (70 gold checks, 58 required) ([`../benchmark/`](../benchmark/README.md)) ### Method families (skills tagged) - `iv`: 27 - `rdd`: 25 - `panel-fe`: 19 - `staggered-did`: 17 - `bayesian`: 13 - `did`: 10 - `event-study`: 10 - `matching`: 10 - `synthetic-control`: 10 - `cate`: 8 - `dml`: 8 - `survival`: 3 - `quantile`: 2 ### Eval scenarios by category - `causal-identification`: 14 - `citation-hygiene`: 1 - `reproducibility`: 2 - `research-integrity`: 1 - `runtime-safety`: 1 - `statistical-validity`: 2 - `writing-compliance`: 3 - `writing-style`: 2 ## License buckets - AGPL-3.0: 1 - Apache-2.0: 1 - CC-BY-NC-4.0 (non-commercial): 1 - CC-BY-SA-4.0: 1 - CC-BY-SA-4.0 (repository default): 4 - GPL-3.0: 1 - MIT: 35 - MIT Non-Commercial: 1 - Mixed (per-skill; see folder): 2 - UNKNOWN - check upstream: 22 ## Quality gates - `make check` — catalog/provenance/audit/eval freshness, repo hygiene, Paper-WorkFlow gates, stdlib unit tests, eval-harness lint + graded smoke, and the strict numeric benchmark (reference-gold drift fails the build). - External links and OpenSSF Scorecard run on their scheduled workflows.
当前收录版本
0.0.1
质量评测
满分 100。前四项来自 DeepSkill 收录的质量报告。
评分依据
提供完整的拓扑数据分析(TDA)解决方案,涵盖持续同调、Mapper 算法、持久图向量化等核心方法
评分依据
触发词精准覆盖拓扑数据分析核心术语,包括 persistent-homology、tda、mapper 等,边界清晰
评分依据
文档结构清晰,分章节详述核心概念、算法实现与工具链,每部分配有完整代码示例
评分依据
代码示例基于主流 TDA 库(ripser、persim、kmapper),参数合理,函数封装良好
计算方式
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
risk · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。