Repository navigation
[MRG] Accept 1D sample weights in the empirical Gaussian OT functions - #885
Open
raashish1601 wants to merge 2 commits into
Open
raashish1601 wants to merge 2 commits into
raashish1601 wants to merge 2 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
Motivation and context / Related issue
ot.gaussian.empirical_bures_wasserstein_distancedocumentsws/wtwith shape(ns), andempirical_bures_wasserstein_barycenterdocumentswas a list of(n,)arrays, but the code only works with column vectors of shape(n, 1). With 1D weights:xs * wsfails with a broadcasting error;xs * wsscales the dimensions instead of the samples andws.T @ xsgives a wrong mean, so a wrong value is returned without any error.The other empirical functions in
ot.gaussian(mappings,_hdvariants, Gaussian Gromov-Wasserstein) have the same code. This PR reshapes user-given sample weights to(n, 1)in all of them, so both(n,)and(n, 1)work. Weights that are already(n, 1)are unchanged.How has this been tested (if it applies)
New tests in
test/test_gaussian.py:test_empirical_gaussian_1d_weights: for the distance, mapping, GGW distance and GGW mapping, 1D weights give the same result as(n, 1)weights (all backends);test_empirical_bures_wasserstein_distance_1d_weights: with 3 samples in dimension 3, the result equals the Bures-Wasserstein distance computed from the weighted means and covariances;test_empirical_bures_wasserstein_barycenter_1d_weights: same check for the empirical barycenter.All 11 new cases fail on master.
pytest test/test_gaussian.pypasses (numpy and torch backends locally), and ruff 0.5.2 lint and format are clean.PR checklist