语言:中文 最后更新:2026-07-23 路径:
statgpu.unsupervised.UMAP
UMAP 在输入空间构造 fuzzy neighbor graph,并优化低维 embedding。它支持 dense exact Euclidean 邻居,以及内部 NNDescent 邻居搜索选项。
距离计算、邻居搜索、membership 权重、embedding 优化和负采样均在所选 NumPy、CuPy 或 Torch 后端执行。当前 fuzzy-union graph assembly 是明确披露的主机边界:O(n*k) 的 edge indices 和 weights 会复制到主机内存,通过 SciPy sparse COO/CSR 完成组装,再复制回所选后端。这不是 optimization 的静默 CPU fallback,但尚不是 device-native sparse graph path。exact neighbor 还需要 O(n^2) dense distance 内存;当可接受 approximate-neighbor 取舍时,可使用 nn_method='nndescent' 避免该 distance matrix。
从 statgpu.unsupervised 导入:
from statgpu.unsupervised import UMAPUMAP 优化高维图权重 w_ij 与低维 affinity q_ij 之间的 fuzzy-set cross-entropy:
$$ \sum_{i,j} w_{ij}\log\frac{w_{ij}}{q_{ij}}
- (1-w_{ij})\log\frac{1-w_{ij}}{1-q_{ij}}. $$
默认通过 dense exact search 选择 n_neighbors 个邻居(nn_method='auto' 会解析为 exact);也可显式请求内部 NNDescent。随后构造对称 fuzzy membership graph,并对 embedding 做梯度更新。
n_neighbors、n_components、metric、min_dist、spread、n_epochs、learning_rate、init、negative_sample_rate、repulsion_strength、random_state、device。
from statgpu.unsupervised import UMAP
embedding = UMAP(n_neighbors=15, device="cpu").fit_transform(X)
embedding_gpu = UMAP(n_neighbors=15, device="cuda").fit_transform(X_gpu)nn_method='exact' 对 dense Euclidean neighbor search 是 exact。nn_method='nndescent' 是 approximate 且 backend-aware。两种模式均使用上述 SciPy host-side fuzzy-union boundary;完整 device-native sparse graph pipeline 尚未实现。
embedding_、graph_、n_epochs_、n_features_in_。
不支持 sparse、非 Euclidean metric 和新样本 transform。通过 nn_method='nndescent' 支持 approximate neighbor;graph assembly 仍需要 SciPy 与 host memory。
测试:dev/tests/test_unsupervised_umap.py。
Benchmark:dev/benchmarks/benchmark_unsupervised_phase3.py。
Baseline:umap-learn,以及远程可用时的 cuML UMAP。
- McInnes, L., Healy, J., & Melville, J. (2018). UMAP: Uniform Manifold Approximation and Projection for Dimension Reduction. arXiv:1802.03426.