Add --NumSVDPCs and log variance explained per principal component#78
Merged
Conversation
WriteSVD() hardcoded writing exactly 10 principal components to the .UD and .V output files. With fewer than 10 individuals (or fewer than 10 components from the SVD), this read past the end of the vectors — undefined behavior that could crash or produce garbage. Add --NumSVDPCs (default: 10, matching prior behavior; set to 0 for all available components). WriteSVD now respects this parameter and caps at the actual number of components available. After SVD computation, log the singular value, proportion of variance explained, and cumulative variance for the first 20 components. This helps users choose an appropriate --NumPC for estimation and verify that their reference panel has meaningful population structure.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes SVD output more configurable by allowing users to control how many principal components are written to .UD/.V, and adds post-SVD logging of variance explained per component to help pick an appropriate --NumPC for downstream estimation.
Changes:
- Add
--NumSVDPCs(default 10; 0 = all) and pass it through to SVD generation. - Update
WriteSVD()to writemin(--NumSVDPCs, available_components)PCs instead of a hardcoded 10. - Log singular values and (cumulative) variance explained for the first 20 PCs after SVD.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
SVDcalculator.h |
Extends ProcessRefVCF / WriteSVD signatures to accept a PC-count parameter. |
SVDcalculator.cpp |
Implements PC-count capping in WriteSVD and logs variance explained after SVD. |
main.cpp |
Adds CLI flag --NumSVDPCs and wires it into ProcessRefVCF. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Griffan
approved these changes
Apr 11, 2026
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.
WriteSVD() hardcoded writing exactly 10 principal components to the .UD and .V output files. But sometimes it is useful to be able to explore > 10 PCs generated by the SVD process.
Add --NumSVDPCs (default: 10, matching prior behavior; set to 0 for all available components). WriteSVD now respects this parameter and caps at the actual number of components available.
After SVD computation, log the singular value, proportion of variance explained, and cumulative variance for the first 20 components. This helps users choose an appropriate --NumPC for estimation and verify that their reference panel has meaningful population structure.