Skip to content

[MRG] Fix ot.bregman.barycenter with non-uniform weights (default sinkhorn method) - #920

Open
iammanoj807 wants to merge 2 commits into
PythonOT:masterfrom
iammanoj807:fix/barycenter-weighted-init
Open

iammanoj807 wants to merge 2 commits into
PythonOT:masterfrom
iammanoj807:fix/barycenter-weighted-init

Conversation

@iammanoj807

Copy link
Copy Markdown

Types of changes

Bug fix: ot.bregman.barycenter_sinkhorn, the default method of ot.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_sinkhorn leaves prod_k u_k ** w_k unchanged, so this product keeps its initial value for the whole run. Starting from the unweighted geometricMean(UKv) made it equal to geometricMean(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 from geometricBar(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)

  • New test test_barycenter_unequal_weights, for sinkhorn and sinkhorn_log. It uses the setup of plot_barycenter_1D.py with weights [0.8, 0.2], and checks that the barycenter is centered at 28 and that the result matches sinkhorn_log.
    • The sinkhorn case fails on master, where the center is 29.11, and passes with this change.
    • The existing test_barycenter uses alpha = 0.5, so it could not catch this.
  • pytest test/test_bregman.py: 102 passed, 10 skipped. Only the numpy backend is installed locally.
  • On 30 random problems with random weights, the largest difference between sinkhorn and sinkhorn_log goes from 4e-2 to 3e-15. With uniform weights it stays below 6e-15, as before.
  • ruff check and ruff format --check (0.5.2, the pre-commit version) pass on the changed files.

PR checklist

  • I have read the CONTRIBUTING document.
  • The documentation is up-to-date with the changes I made (check build artifacts).
  • All tests passed, and additional code has been covered with new tests.
  • I have added the PR and Issue fix to the RELEASES.md file.

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.
@iammanoj807
iammanoj807 force-pushed the fix/barycenter-weighted-init branch from c1618a9 to e62b856 Compare November 13, 2026 21:59

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ot.bregman.barycenter gives a wrong barycenter with the default method when the weights are not uniform

1 participant