Skip to content

Conversation

@davibarreira
Copy link
Member

This PR creates a version of ot_cost and ot_plan that receives usupport, vsupport and uprobs, uprobs. In case the vector of probabilities is not passed, it assumes that all entries have equal probability.

The PR has one test that is failing that I was not able to figure out where is coming from.

One thing that I tried doing was "NOT" sorting the vector, but returning the transport plan for the order given. I'm guessing this is the thing that is causing some issues, because when the transport plan is provided to the ot_cost function, it has to reorder it for to be properly used, and I'm guessing there might be some compilation issues.

@davibarreira
Copy link
Member Author

The issue is type instability as I thought :(
I've written:

function ot_cost(
    c,
    usupport::AbstractVector{<:Real},
    vsupport::AbstractVector{<:Real},
    ;
    uprobs::AbstractVector{<:Real}=fill(inv(length(usupport)), length(usupport)),
    vprobs::AbstractVector{<:Real}=fill(inv(length(vsupport)), length(vsupport)),
    plan=nothing
    )
    μ = discretemeasure(usupport, uprobs)
    ν = discretemeasure(vsupport, vprobs)
    if plan === nothing
        return _ot_cost(c, μ, ν, plan)
    else
        return _ot_cost(c, μ, ν, plan[sortperm(usupport), sortperm(vsupport)])
    end
end

To try to deal with the case where the plan is the in the sorted order. But I guess this causes problems for the compiler. Any ideas on how to solve this?

@davibarreira
Copy link
Member Author

Ok, so it was actually a typo in the test! This piece of code is actually solid :)

@coveralls
Copy link

coveralls commented Oct 28, 2021

Pull Request Test Coverage Report for Build 1396825672

  • 11 of 11 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 97.076%

Totals Coverage Status
Change from base Build 1396587941: 0.2%
Covered Lines: 166
Relevant Lines: 171

💛 - Coveralls

@codecov-commenter
Copy link

codecov-commenter commented Oct 28, 2021

Codecov Report

Merging #13 (a6569be) into main (e9efd4e) will increase coverage by 0.24%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #13      +/-   ##
==========================================
+ Coverage   96.83%   97.07%   +0.24%     
==========================================
  Files           4        4              
  Lines         158      171      +13     
==========================================
+ Hits          153      166      +13     
  Misses          5        5              
Impacted Files Coverage Δ
src/exact.jl 98.31% <100.00%> (+0.20%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e9efd4e...a6569be. Read the comment docs.

@davibarreira
Copy link
Member Author

@devmotion and @zsteve , are you guys good with such kind of dispatch? This allows users to simple do:

wasserstein(rand(10),rand(10))

I'll be doing a PR for the multivariate case shortly.

Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not happy about this PR. We already support OT with 1D vectors and also ot_cost, ot_plan, and wasserstein with 1D vectors. Maybe it should just be better documented.

I think we should not define ot_cost and ot_plan in this way and in particular we should not make uprobs and vprobs keyword arguments (BTW the signature in the docstring is different from the implementation). We should be consistent with the other ot_cost and ot_plan and only allow the cost and the measures (no vectors) as inputs. Users should just use discretemeasure.

In the same way, a consistent API should require them to write e.g squared2wasserstein(discretemeasure(rand(10)), discretemeasure(rand(10), probs)). This is much clearer and avoids redundant implementations.

@davibarreira
Copy link
Member Author

Ok. So I guess we should export discretemeasure, since it's not currently exported. I'll make another PR here with the modification and I'll submit an update to the docs in OptimalTransport.jl. Sound good?

@coveralls
Copy link

coveralls commented Sep 25, 2024

Pull Request Test Coverage Report for Build 1396802728

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 11 of 11 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 97.076%

Totals Coverage Status
Change from base Build 1396587941: 0.2%
Covered Lines: 166
Relevant Lines: 171

💛 - Coveralls

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants