[MRG] Fix GMM rand map overflow - #872
Open
jonathan-legrand wants to merge 6 commits into
Open
jonathan-legrand wants to merge 6 commits into
jonathan-legrand wants to merge 6 commits into
Conversation
This branch has not been deployed
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.
Types of changes
I simplified the computation of the$T_{rand}$ map and used the
logsumexptrick to avoid overflows. I also added a test case that triggers overflow errors with the current main branch implementation and passes with the changes introduced in this request.Motivation and context / Related issue
I ran into overflow errors when transporting gaussian mixtures with the$T_{rand}$ map. They occur when a point of the source domain $x$ is far away from one of the target components.
The current implementation computes:
log_diff = log_g[:, None] - log_g[None, :]which is effectively:and then exponentiates this quantity :
weighted_exp = w_s[:, None] * nx.exp(log_diff)When the ratio$g_i(x)/g_j(x)$ is very large, the
expoverflows.I rewrote this computation using the$T_{rand}$ attribution probability, so I implemented one which is backend agnostic.
logsumexptrick. I saw that alogsumexpfunction is available throughnxbut it does not accept weights, which are required for computing theHow has this been tested (if it applies)
The
logsumexphas been tested for high (710) and low (0) logits and it behaves as expected. The tests pass for numpy and torch backends. I had to skip jax tests because the functions of thegmmmodule use a lot of array assignments.PR checklist