Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check all S are 0 with tolerance #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

gituser768
Copy link

Addresses #2
Turns out the comparison at the beginning of the loop was being too strict. Floating pt err causes the loop to not terminate when it should.

Thanks for the package by the way!

@gituser768
Copy link
Author

Ah, this actually isn't doing anything different from what the code was originally doing with the TOLERANCE constant. I'll reopen if I have a general fix.

@gituser768 gituser768 closed this Sep 11, 2018
@gituser768
Copy link
Author

My understanding is that the floating point precision issues are causing the graph G to eventually not have a maximal matching that contains all nodes (in my specific case G is not even connected). For my application I break in the loop when the maximum matching is not perfect. I've shared my changes here. From what I've read, it's typical to either terminate once the coefficients sum to close to 1, or after a fixed number of iterations, or using a larger tolerance on determining whether S is the 0 matrix; but this solution seems less ad-hoc to me.

One thing that confused me: why aren't the coefficients returned in non-increasing order? My understanding was that this algorithm determined the corresponding permutations and coefficients sorted by magnitude.

@gituser768 gituser768 reopened this Sep 12, 2018
@jfinkels
Copy link
Owner

From what I've read, [...]

If you have any reference material that you can share, that would be helpful.

it's typical to either terminate once the coefficients sum to close to 1, or after a fixed number of iterations, or using a larger tolerance on determining whether S is the 0 matrix; but this solution seems less ad-hoc to me.

Just so I understand, you are saying that we can terminate the loop when

  • the coefficients sum to 1,
  • a specified number of iterations has been reached,
  • the matrix S is the zero matrix, or
  • the maximum matching is missing entries.

Although you are proposing the last one, it seems rather fragile to me. The maximum matching is an "implementation detail" of the algorithm, something that happens in the middle of each iteration. It would make more sense to me to have a termination condition that can be applied at the beginning (or end) of each iteration of the loop---a condition on the matrix or the coefficients, for example. Perhaps we need to make the tolerance of the "isclose()` check configurable?

One thing that confused me: why aren't the coefficients returned in non-increasing order?

You can sort them in the calling code using sorted().


If you are able, it would be helpful to add a unit test that fails before your proposed change and passes after your proposed change. The matrix in the reference issue may be of use in finding a minimal working example.

@gituser768
Copy link
Author

My issue with the other methods used for stopping is that they all require the user to play around with tolerance values etc--how is the consumer of the API supposed to know now many iterations to run for, or the tolerance they need is? In the case of breaking when no perfect matching is possible, we know that the algorithm has run for the largest number of iterations that it can.

Check out: https://hal.inria.fr/hal-01270331v2/document (Notes on Birkhoff-von Neumann decomposition of doubly stochastic matrices). Specifically Lemma 3 which states that the coefficients are obtained in non-increasing order.

I'll look into creating a unit test.

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.

2 participants