Fix GMM.condition() ValueError with single conditioning value#61
Merged
AlexanderFabisch merged 1 commit intoJan 12, 2026
Merged
Conversation
The to_norm_factor_and_exponents() method returns exponents as an array
of shape (n_samples,). When conditioning on a single value, this is a
1-element array, not a scalar. Attempting to assign this array to
marginal_prior_exponents[k] (a scalar slot) raised:
ValueError: setting an array element with a sequence
The fix extracts the scalar value with exponents[0] since condition()
is designed to handle a single conditioning value.
Added test to verify various input formats work correctly:
- 1D array: np.array([val])
- list: [val]
- nested list: [[val]]
- 2D array: np.array([[val]])
jkitchin
added a commit
to KitchinHUB/generative-optimization
that referenced
this pull request
Jan 11, 2026
The gmr library GMM.condition() method has a bug that causes ValueError when conditioning on a single value. Added sample_gmm_conditional() helper function that conditions each MVN component separately as a workaround. See upstream fix: AlexanderFabisch/gmr#61 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Owner
|
Thanks for the contribution! |
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
GMM.condition()raisesValueError: setting an array element with a sequencewhen conditioning on a single value. This affects all input formats ([[val]],[val],np.array(...), scalar).Root Cause
The
to_norm_factor_and_exponents()method returnsexponentsas an array of shape(n_samples,). When conditioning on a single value, this is a 1-element array, not a scalar. The original code attempted to assign this array directly tomarginal_prior_exponents[k](a scalar slot), causing the error.Fix
Extract the scalar value with
exponents[0]sincecondition()is designed to handle a single conditioning value:Minimal Reproducer
Testing
test_conditional_distribution_input_formats()to verify various input formats work