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

support cliques as a resolver of coincident points in Graph #647

Merged
merged 16 commits into from
Nov 19, 2023

Conversation

knaaptime
Copy link
Member

i think we were just missing a couple parens

@martinfleis
Copy link
Member

The issue, as far as I remember it, was that _induce_cliques was not working properly. That is why I added NotImplementedError. I'd be happy to allow it again but the PR needs to come with extensive tests to ensure it all works as it is supposed to :).

@ljwolf
Copy link
Member

ljwolf commented Nov 13, 2023

I think there was an issue after a bad rebase.

I can get some attention on it this week to fix.

@ljwolf
Copy link
Member

ljwolf commented Nov 13, 2023

I'm pretty certain that the issue was induced when we switched from focal-indexed adjacency to non-indexed adjacency.. @knaaptime, I've sent a PR to your clique branch with the change.

The dual merge in lines 76-82 was supposed to match up the deduped ids back onto the clique ids, and then explode the cliques into their own links. This only works when the adjtable is indexed on focal.

With this fix, tests still fail, but I think the test answers are incorrect? In the tests, 0 and 4 are coincident, and the current answers are:

exp_heads = np.array(
    [0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5]
)
exp_tails = np.array(
    [1, 2, 4, 0, 2, 3, 4, 5, 0, 1, 3, 1, 2, 5, 0, 1, 5, 1, 3, 4]
)

But, if 0 and 4 are coincident, then every link and backlink containing 0 should also contain 4. So, for example, link (5,0) is missing, as is link (2,4). So, the correct answer, I think, is:

exp_heads = numpy.array([0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5,
       5, 5])
exp_tails = numpy.array([1, 2, 4, 5, 0, 2, 3, 4, 5, 0, 1, 3, 4, 1, 2, 5, 0, 1, 2, 5, 0, 1,
       3, 4])

The _induce_cliques() function with f9bfadbe correctly recovers this.

example_output

@ljwolf
Copy link
Member

ljwolf commented Nov 15, 2023

OK, after some further testing, I think I've confirmed the answers need to change, but I had to make sure to re-set the working values (like, coordinates, ids, geoms, heads, tails, weights) after expanding the cliques.

I will change the tests, but the correct edge table is in the comment above.

@ljwolf
Copy link
Member

ljwolf commented Nov 16, 2023

This now also addresses #573. The fix was as described, but also exposed a few other minor issues in the implementation that have been fixed.

example_output

@ljwolf
Copy link
Member

ljwolf commented Nov 16, 2023

Triangulation is done. I'm now verifying the usage in _knn()/_kernel(), so still WIP.

@ljwolf ljwolf changed the title add cliques back to graph [WIP] add cliques back to graph Nov 16, 2023
@ljwolf
Copy link
Member

ljwolf commented Nov 16, 2023

_knn/_kernel is done. Currently, I'm getting local failures in the round-tripping from sparse? The adjacency tables are the same, but comparing the graphs by equality is not. I'm not sure how/where this would have been introduced by this PR, and it's currently failing on main?

@ljwolf ljwolf changed the title [WIP] add cliques back to graph add cliques back to graph Nov 16, 2023
@ljwolf
Copy link
Member

ljwolf commented Nov 16, 2023

This is ready for review.

@martinfleis
Copy link
Member

Currently, I'm getting local failures in the round-tripping from sparse? The adjacency tables are the same, but comparing the graphs by equality is not. I'm not sure how/where this would have been introduced by this PR, and it's currently failing on main?

Could it be some issue with your local env? It seems to be work as expected on CI.

We have some issue with coincident points in the env with the minimum supported versions of dependencies for some reason...

@ljwolf
Copy link
Member

ljwolf commented Nov 16, 2023

then it must be something in my local environment. I will check out the failures in py3.10. I think that's likely a numba issue.

Copy link

codecov bot commented Nov 16, 2023

Codecov Report

Merging #647 (ab9eef1) into main (44204b5) will increase coverage by 0.6%.
Report is 46 commits behind head on main.
The diff coverage is 98.1%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main    #647     +/-   ##
=======================================
+ Coverage   84.5%   85.0%   +0.6%     
=======================================
  Files        139     139             
  Lines      14972   14868    -104     
=======================================
- Hits       12647   12642      -5     
+ Misses      2325    2226     -99     
Files Coverage Δ
libpysal/graph/_kernel.py 88.8% <100.0%> (+0.7%) ⬆️
libpysal/graph/_utils.py 94.1% <100.0%> (+4.8%) ⬆️
libpysal/graph/tests/test_builders.py 100.0% <100.0%> (ø)
libpysal/graph/tests/test_kernel.py 100.0% <100.0%> (ø)
libpysal/graph/tests/test_triangulation.py 98.8% <100.0%> (+14.5%) ⬆️
libpysal/graph/tests/test_utils.py 98.8% <100.0%> (ø)
libpysal/graph/_triangulation.py 97.9% <94.1%> (+0.7%) ⬆️

... and 51 files with indirect coverage changes

@ljwolf
Copy link
Member

ljwolf commented Nov 16, 2023

Not a numba issue, but rather needed a bit more than 4091467 to fully fix #573.

@ljwolf
Copy link
Member

ljwolf commented Nov 17, 2023

Tests are passing, ready for review!

@ljwolf
Copy link
Member

ljwolf commented Nov 17, 2023

@knaaptime I can't assign you as a reviewer, but you probably should be one of the reviewers anyway, having motivated me to revisit this 😄

Copy link
Member Author

@knaaptime knaaptime left a comment

Choose a reason for hiding this comment

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

you rule. But i also cant approve, apparently, since it's technically "my" pr

so, approved. :P

Copy link
Member

@martinfleis martinfleis left a comment

Choose a reason for hiding this comment

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

I can approve :)

libpysal/graph/_kernel.py Outdated Show resolved Hide resolved
@martinfleis martinfleis changed the title add cliques back to graph support cliques as a resolver of coincident points in Graph Nov 19, 2023
@martinfleis martinfleis merged commit adfa032 into pysal:main Nov 19, 2023
10 checks passed
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.

4 participants