BUG: Detect non-positive-definite covariance in GaussianMembershipFunction#6037
Merged
hjmjohnson merged 1 commit intoInsightSoftwareConsortium:mainfrom Apr 14, 2026
Merged
Conversation
Member
Author
|
@greptileai review this draft before I make it official |
This comment was marked as resolved.
This comment was marked as resolved.
…ction GaussianMembershipFunction::SetCovariance() previously checked inv_cov.determinant_magnitude() < 0, which is unreachable because determinant_magnitude() returns the product of singular values and is always non-negative. As a result a singular or negative-definite covariance matrix would silently slip through and propagate NaNs into the multivariate Gaussian normalization constant downstream. Replace with vnl_determinant() on the original (non-inverted) covariance and reject det <= 0, catching both singular and non-positive-definite cases. Extend itkGaussianMembershipFunctionTest with three regression cases (singular, negative-definite, positive-definite happy path). Closes InsightSoftwareConsortium#3589
5ac2f5b to
d11739f
Compare
thewtex
approved these changes
Apr 14, 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.
Summary
Fixes #3589.
GaussianMembershipFunction::SetCovariance()previously checkedvnl_matrix_inverse::determinant_magnitude()returns the product of singular values, which is always non-negative, so thedet < 0.check is unreachable dead code. A singular or negative-definite covariance matrix would silently slip through and propagate NaNs into the multivariate Gaussian normalization constant downstream (m_PreFactor = 1.0 / (std::sqrt(det) * ...)).This PR replaces the check with
vnl_determinant()on the original (non-inverted) covariance and rejectsdet <= 0, which catches both singular (det == 0) and non-positive-definite (det < 0) cases. The cost isO(n^3)butnis the measurement-vector dimension (typically 1..16), negligible compared to the SVD already computed for the inverse on the next line.Diff
Tests
Three new regression cases added to
itkGaussianMembershipFunctionTest.cxx:[[1,1],[1,1]](det = 0) — must throw.[[1,2],[2,1]](det = −3) — must throw.[[2,0.5],[0.5,2]](det = 3.75, symmetric positive-definite) — must succeed.AI Assistance
Generated by Claude Code as part of the 2026-04-10 open-issue triage cleanup.
Test plan
ITKStatisticsTestDriver) compiles cleanlyitkGaussianMembershipFunctionTestpasses locally with the new singular / negative-definite / positive-definite assertionspre-commit runclean (clang-format, kw-pre-commit)