语言:中文 最后更新:2026-05-02 English: English
NMF 把非负 dense data 分解为非负 factors W 和 H。Phase 2 支持 Frobenius loss 下的 multiplicative updates,并支持 CPU、CuPy/CUDA 和 Torch CUDA。
from statgpu.unsupervised import NMF拟合 factors 需要求解非凸约束问题:
components_ 存储 H;fit_transform 返回 W。
实现使用 multiplicative updates:
Factors 使用按 X 均值缩放的正随机值初始化。重构误差每 10 次迭代和最后一次迭代检查。transform(X) 会固定已经拟合的 H,为新数据更新新的 W。
n_components:latent dimension;None使用min(n_samples, n_features)。init:仅支持"random"。solver:仅支持"mu"。beta_loss:仅支持"frobenius"。max_iter、tol、random_state。device:"auto"、"cpu"、"cuda"或"torch"。
import numpy as np
from statgpu.unsupervised import NMF
X = np.abs(np.random.default_rng(0).normal(size=(1000, 32)))
nmf = NMF(n_components=8, random_state=0, device="cuda")
W = nmf.fit_transform(X)
X_hat = nmf.inverse_transform(W)NMF 没有 strict inference 模式。目标函数是非凸的,multiplicative updates 收敛到依赖初始化和停止准则的局部解。
components_reconstruction_err_n_iter_n_components_n_features_in_
输入可以有负数吗?
不可以。X 包含负数时 NMF 会报错。
支持 coordinate descent 吗? 不支持。Phase 2 仅支持 Frobenius loss 下的 MU。
- 测试:
dev/tests/test_unsupervised_nmf.py。 - Benchmark:
dev/benchmarks/benchmark_unsupervised_phase2.py。 - Baseline:sklearn
NMF(solver="mu", beta_loss="frobenius")。 - 最新远程矩阵:CPU/CuPy/Torch reconstruction differences 处于浮点噪声量级;sklearn reconstruction error 与 statgpu CPU 同尺度。
- Lee, D. D., & Seung, H. S. (1999). Learning the parts of objects by non-negative matrix factorization. Nature, 401(6755), 788-791. https://doi.org/10.1038/44565
- Lee, D. D., & Seung, H. S. (2001). Algorithms for non-negative matrix factorization. In T. K. Leen, T. G. Dietterich, & V. Tresp (Eds.), Advances in Neural Information Processing Systems 13 (pp. 556-562). MIT Press.