Repository navigation
fix(svd): projection deflation for constrained factors (no repeated factors) - #84
Merged
Merged
Conversation
…actors) With nonneg/L1/upper_bound constraints, deflation subtracted each fitted rank-1 term (Hotelling deflation). Constrained factors are not singular vectors, so the residual kept energy along earlier factors and later factors converged to near-copies of them. On pbmc3k (all 13,714 genes, k = 16, nonneg loadings) the 16 returned factors spanned only 8 distinct directions (max |cos| between factors 0.99). When either side is constrained, use generalized (projection) deflation, as in nsprcomp: R_k = P_u A P_v, with P = I - QQ' over an orthonormal basis of the earlier constrained factors. Both deflated products go through one helper; post-factor Gram-Schmidt is skipped in this mode. Unconstrained SVD/PCA keeps the Hotelling path unchanged. pbmc3k, k = 16: 16 distinct directions (max |cos| 0.43), 0 negative loadings, best-fit relative residual 0.9478 vs 0.9480 for nsprcomp. New test fails on the previous code (max |cos| 1.000) and passes here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014zFkHdSUAE1RSwGtTqz9Fi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(svd): projection deflation for constrained factors (no repeated factors)
Problem
Follow-up to #83. With
nonneg/L1/upper_bound, the deflation solver still used Hotelling deflation (subtracting each fitted rank-1 term). Constrained factors are not singular vectors, so the residual keeps energy along earlier factors and later factors converge to near-copies of them. #83 removed the Gram-Schmidt step that had been masking this (by breaking non-negativity), which exposed it at larger k.pbmc3k (all 13,714 genes × 2,638 cells, log-normalized,
k = 16,nonneg = c(TRUE, FALSE)): the 16 returned loading vectors spanned only 8 distinct directions (factors 5–16 pairwise |cos| ≥ 0.99).Change
When either side has projection constraints, use generalized (projection) deflation, as in
nsprcomp:R_k = P_u A P_v,P = I − QQ'over an orthonormal basis of earlier constrained factors (two-pass projection). Both deflated products (R v,R' u) go through one helper used at all nine formerspmv+deflation_correctcall sites; post-factor Gram-Schmidt is skipped in this mode. Unconstrained SVD/PCA keeps the Hotelling path unchanged.Verification
pbmc3k, k = 16, 2 threads, vs CRAN
nsprcomp0.5.1.2 on the same data:(unconstrained rank-16 PCA floor: 0.9435)
base::svd).k = 10, distinct factors): fails on current main (max |cos| 1.000), passes here (0.233).Not covered
deflation_gpu.cuh) still uses Hotelling deflation for constrained factors (no CUDA device to test); same change needed there.SeuratDatain Suggests withoutRemotes:), unrelated to this PR — see fix(svd): keep nonneg/L1 constraints on deflation factors after the first #83.Generated by Claude Code