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

Fix outlier handling in qap when len(seeds)==n #754

Merged
merged 6 commits into from Apr 10, 2021

Conversation

kellymarchisio
Copy link
Contributor

@kellymarchisio kellymarchisio commented Apr 8, 2021

  • Does this PR add any new dependencies? No
  • Does this PR modify any existing APIs? No
    • Is the change to the API backwards compatible? Yes
  • Have you built the documentation (reference and/or tutorial) and verified the generated documentation is appropriate? N/A

Reference Issues/PRs

What does this implement/fix? Briefly explain your changes.

QAP incorrectly assumes the partial_match is sorted when partial_match.shape[0] == A.shape[0]. Fix this.

Any other comments?

@netlify
Copy link

netlify bot commented Apr 8, 2021

Deploy preview for graspologic ready!

Built with commit 3c3e5f0

https://deploy-preview-754--graspologic.netlify.app

@bdpedigo
Copy link
Collaborator

bdpedigo commented Apr 8, 2021

thanks for the PR @kellymarchisio, I'll let @asaadeldin11 chime in

@bdpedigo
Copy link
Collaborator

bdpedigo commented Apr 8, 2021

although when partial_match.shape[0] == A.shape[0], then QAP shouldn't run at all... is it just that the score calculation would be wrong in that case @kellymarchisio ?

@bdpedigo bdpedigo added the bug Something isn't working label Apr 8, 2021
@asaadeldin11
Copy link
Contributor

@kellymarchisio Thanks for the PR! I think I understand the issue; the score returned is correct, but the perm_inds returned isn't necessarily correct, depending on the order of the first column of partial_match?

@@ -400,6 +400,8 @@ def _quadratic_assignment_faq(

# check outlier cases
if n == 0 or partial_match.shape[0] == n:
# Cannot assume partial_match is sorted.
partial_match = np.row_stack(sorted(partial_match, key=lambda x: x[0]))
Copy link
Contributor

Choose a reason for hiding this comment

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

does sorted require partial_match to be a list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope - it can be any iterable.

Copy link
Contributor

Choose a reason for hiding this comment

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

great. can you add a test to the function test_barycenter_SGM in test_match.py that gives (a possibly shuffled) full partial_match and returns the correct score_ and perm_inds? (Should be very similar to the test in lines 138-142)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure - done :)

@kellymarchisio
Copy link
Contributor Author

kellymarchisio commented Apr 8, 2021

although when partial_match.shape[0] == A.shape[0], then QAP shouldn't run at all... is it just that the score calculation would be wrong in that case @kellymarchisio ?

The score calculation is wrong, and then the return value of fit is wrong:

sgm = gmp.GraphMatch(init=init_method).fit(A1, A2, A1_seeds, A2_seeds)
perm_inds = sgm.perm_inds_

^^ perm_inds are not sorted, as they would be if QAP had run.

So looks like both the score and perm_inds are incorrect. You can reproduce this by sending in sorted vs. unsorted seeds of list length n.

@ghost
Copy link

ghost commented Apr 8, 2021

CLA assistant check
All CLA requirements met.

tests/test_match.py Outdated Show resolved Hide resolved
chr12c = self.barycenter.fit(A, B, W1, W2)
score = chr12c.score_
assert 11156 == score

Copy link
Contributor

Choose a reason for hiding this comment

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

can you check the perm_inds_ here as well

@asaadeldin11
Copy link
Contributor

@bdpedigo this looks good to me

@bdpedigo bdpedigo added this to Needs Triage in PRs via automation Apr 10, 2021
@bdpedigo bdpedigo moved this from Needs Triage to Ready For Merge in PRs Apr 10, 2021
@bdpedigo bdpedigo merged commit faad997 into graspologic-org:dev Apr 10, 2021
PRs automation moved this from Ready For Merge to Done Apr 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
PRs
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants