Repository navigation
[MRG] Fix ot.bregman.barycenter with non-uniform weights (default sinkhorn method) - #920
iammanoj807 wants to merge 2 commits into
Conversation
c1618a9 to
e62b856
Compare
barycenter_sinkhorn started its scalings from the unweighted geometric mean. Its update keeps prod_k u_k ** w_k constant, so with non-uniform weights this product stayed different from 1 and the iterations converged to a point that is not the barycenter. Start from the weighted geometric mean instead.
e62b856 to
f782051
Compare
|
I've just noticed that #870, opened in September, makes the same change to I checked #870 against Since #870 covers both solvers, I'm happy to close this one in its favour. Or, if you'd rather merge the |
Types of changes
Bug fix:
ot.bregman.barycenter_sinkhorn, the default method ofot.bregman.barycenter, now starts its scalings from the weighted geometric mean instead of the unweighted one.Motivation and context / Related issue
Fixes #919.
The update in
barycenter_sinkhornleavesprod_k u_k ** w_kunchanged, so this product keeps its initial value for the whole run. Starting from the unweightedgeometricMean(UKv)made it equal togeometricMean(UKv) / geometricBar(weights, UKv)instead of 1. With non-uniform weights, the iterations then converge, without a warning, to a point that is not the barycenter. Starting fromgeometricBar(weights, UKv)makes the product 1. With uniform weights both means are the same, so nothing changes there.How has this been tested (if it applies)
test_barycenter_unequal_weights, forsinkhornandsinkhorn_log. It uses the setup ofplot_barycenter_1D.pywith weights[0.8, 0.2], and checks that the barycenter is centered at 28 and that the result matchessinkhorn_log.sinkhorncase fails on master, where the center is 29.11, and passes with this change.test_barycenterusesalpha = 0.5, so it could not catch this.pytest test/test_bregman.py: 102 passed, 10 skipped. Only the numpy backend is installed locally.sinkhornandsinkhorn_loggoes from 4e-2 to 3e-15. With uniform weights it stays below 6e-15, as before.ruff checkandruff format --check(0.5.2, the pre-commit version) pass on the changed files.PR checklist