Repository navigation
BiRank Algorithm Implementation - #7978
Conversation
dschult
left a comment
There was a problem hiding this comment.
Nice contribution! Thanks!
I only ask that you wrap the comments and docstrings to ~80 chars (code is enforced to <88. But we don't have a tool for wrapping docstrings yet). I think the docstring is the only part of review I have left to do.
My other comments are all incredibly picky so only do the ones you feel improve what's here.
dschult
left a comment
There was a problem hiding this comment.
This looks good to me. Just a few very minor tweaks/suggestions. If you prefer not for any of them that's fine. They aren't blockers for sure.
I approve this PR.
| bipartite node set ('bottom') are automatically determined by taking the | ||
| complement of 'top' with respect to the graph `G`. | ||
|
|
||
| alpha : float, optional (default=0.80 if top_personalization not empty, else 1) |
There was a problem hiding this comment.
Does the paper specify why these 0.8 default? Would be good to add that to the docs
There was a problem hiding this comment.
The paper talks a little about choices for alpha and beta. Their summary is:
BiRank needs more iterations to converge with a larger α (and β). [... A] smaller value of α (and β) leads to a larger effect of the static query vectors, helpful in achieving quick convergence.
My summary is: Larger alpha and beta reduce the effect of the personalizations and increase the number of iterations before convergence. Your results may vary by application and sometimes even by dataset. The choice of default value 0.8 is reasonable start, but you should see what works in your setting.
| pytest.importorskip("scipy") | ||
|
|
||
|
|
||
| class TestBipartiteLinkAnalysis: |
There was a problem hiding this comment.
Question regarding testing: is there any family of graphs where you can induce the result without calling the algorithm? For example, the case where all top connect to all bottoms.
If that's the case, can you put up a test that generates a random set of those graphs and validates the result matches the expected value?
|
Hmm... just pushed a few commits implementing some of the suggestions you guys had. Looks like it's failing on extra for ubuntu 3.13 on a completely unrelated test: I'm not really sure what could be happening here, could this be an unrelated issue with networkx testing? |
|
The failed test is almost certainly an update to one of the packages our CI is testing (or just using) in the "extra" suite of tests. It works on my machine locally, so we'll chase down what updated package is causing troubles. You don't need to worry about that for this PR. :) |
rossbar
left a comment
There was a problem hiding this comment.
This is a very nice addition, thanks @LorentzFactor !
Just a couple minor things related to the function signature but otherwise LGTM!
|
Made a few changes, including to the test values that are being used as references to compare the output with. See the reply to @amcandio for the explanation. I'm going to add a few more tests tomorrow to at least be testing both the case
|
|
Okay - a few changes later, and this should be in a mergable position. I've added some more parameterized tests to get better coverage. For large graphs, testing becomes pretty expensive due to converting the graph to a biadjancency matrix, so for now at least I'm limiting the total range of values tested. |
amcandio
left a comment
There was a problem hiding this comment.
Approving with minor comments. This is a great addition!
|
Just two (maybe small -- let me know if not) requests left:
|
Regarding this - I'm for raising when there negative personalization values, although I can see the case for allowing them From a purely algorithmic perspective, there's nothing wrong with providing negative personalizations - convergence will still occur. But I'm not really sure why a user would want to use negatives, or really any personalization system where the minimum score is not represented by 0. What bothers me is that the choice of minimum personalization seems to impact the output birank in a non-trivial way. That is to say, shifting personalizations by a uniform vector It also is pretty clear in the paper that the intent was for values to be non-negative. So ultimately this seems like the way to go, and I've added a commit to implement this. |
rossbar
left a comment
There was a problem hiding this comment.
Thanks @LorentzFactor , this LGTM! I took the liberty of pushing up minor docstring formatting fixes (including a whitespace issue, so the diff looks worse than it is!). This is a really nice addition!
I'll give @dschult a chance for one last once-over, otherwise I'll merge in the near future (certainly before the 3.5 release!)
There was a problem hiding this comment.
There is a lot of variation in the whitespace/indentation for the docs here. The math indent is 3 spaces, bullets are 2, cases-list is 4, G parameter is 3, but other parameters are 2.
Could you take a look at the indentation levels and select them intentionally. I htink the normal approach is 4 spaces for each indentation -- but e.g. references sometimes follow a different rule -- and @rossbar set those as 3. The bullet points on lines 37-47 look pretty good the way they are. But I think other than bullet points and references, the rest should probably be 4 spaces per indentation. What you choose isn't as important as making it consistent (so long as the docs look good -- can check by clicking on "details" of the "documentation artifact" test and then navigating to the page for the function you are changing/adding).
Thanks for this -- we are getting to some nitty details. So that means we are close to merging!
:)
|
Sounds good - I've standardized non-bullet/reference indentation to 4 spaces. Let me know if there's anything else, formatting-wise. |
Co-authored-by: Dan Schult <[email protected]>
Co-authored-by: Dan Schult <[email protected]>
Co-authored-by: Dan Schult <[email protected]>
Co-authored-by: Dan Schult <[email protected]>
Co-authored-by: Dan Schult <[email protected]>
…nly compute u's error once p's check has passed
… diagonal matrix construction
Co-authored-by: Ross Barnowski <[email protected]>
…orrectly detected
Co-authored-by: Dan Schult <[email protected]>
Co-authored-by: Dan Schult <[email protected]>
8650ddd to
c64e6f1
Compare
This pull request adds an implementation of the BiRank algorithm to networkx under
networkx.algorithms.bipartite.link_analysis, as proposed in #7963. It attempts to match the api patterns found in similar algorithms, like those found undernetworkx.algorithms.bipartite.centrality, as closely as possible.Additionally, two unit tests have been added to ensure code coverage.
While the code is document to the standards set out by the contribution guidelines, I am considering adding additional context to the introduction to better explain when/what it should be used for.
If this seems like something worth moving forward with, I would like to make sure the my choices of input validation (ensuring
alphaandbetahave valid values, and ensuring there exists at least one node in the top and bottom sets) and Exception type (nx.NetworkXAlgorithmError) are inline with networkx conventions. I see some algorithms raise a genericNetworkXError- and I'm not sure if this the preference or not.