Skip to content

Match GPU NMF denominator handling to sklearn - #8

Merged
OlivierBakker merged 1 commit into
TrynkaLab:mainfrom
JerryIshihara:fix/sklearn-nmf-zero-guard
Jul 28, 2026
Merged

Match GPU NMF denominator handling to sklearn#8
OlivierBakker merged 1 commit into
TrynkaLab:mainfrom
JerryIshihara:fix/sklearn-nmf-zero-guard

Conversation

@JerryIshihara

Copy link
Copy Markdown

The previous implementation added eps to every denominator:

W = W * ((Xg @ Ht) / (W @ (H @ Ht) + eps))

scikit-learn only replaces denominators that are exactly zero. Adding eps to valid, nonzero FP64 denominators slightly changed every update, while the same 1e-9 addition generally rounded away in FP32.

The update now leaves nonzero denominators untouched and replaces only exact zeros:

denominator = W @ (H @ Ht)
denominator = denominator.where(denominator != 0, eps)
W = W * ((Xg @ Ht) / denominator)

The same change is applied to the H update and the fixed-H path, and the default replacement value now matches scikit-learn's FP32 epsilon.

@JerryIshihara
JerryIshihara force-pushed the fix/sklearn-nmf-zero-guard branch from 72a73a3 to e1e3fc4 Compare July 27, 2026 17:32
@OlivierBakker
OlivierBakker merged commit 2c3eba2 into TrynkaLab:main Jul 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants