-
Notifications
You must be signed in to change notification settings - Fork 8
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 for bipartite graphs #5
Comments
This package calls the python version via Have you tried running it on a bipartite graph? Would you be able to produce a minimal reproducible example? If I'm able to reproduce the graph you're having issues with, I can look into it. |
Awesome! I don't know exactly how the passing to python works so I came up with a small example:
Perhaps it would make sense to include an example like this in the documentation? |
Have you tested this example? Please note that dependencies on non-CRAN packages are not permitted to be submitted to CRAN. When submitting to CRAN, it will need to automatically run tests, examples, and generate vignettes. Data is passed to Python via internal functions. There should be no need to interact with it directly (as long as the |
My apologies, I should have been more clear what I intended with this example. Running the code technically works but the results show that some of the events and persons are in the same community which should not be the case (if I'm not completely mistaken) since they are in different modes.
What I meant with including an example like this for the documentation is a working example that shows how to use the package in a way that takes the bipartite graph structure into account. It looks like it's not enough to just have a bipartite igraph object to achieve this but it is not clear to me how to pass this information using the package. |
I've looked into it. The "bipartite" graphs are supported in the latest version (0.7.0) of leidenalg in section 4.1.2, see the python module documentation for details. These are separate functions now currently supported by the R package. Bipartite methods were added in version 0.6.1 and are not supported by the R version currently.
This does not account for bipartite structures which do not account for this:
Correcting this will require changes to internal functions to call |
It should be possible to implement an R version of the Bipartite methods providing it can be done in Python. I notice you submitted an issue to the leidenalg repository. Was it possible to run in Python. If so it should be possible to run it here: |
The development version of
This will still require testing before it can be added to documentation but here's a minimal example:
Note here that the "resolution" parameter is important for testing the results.
This is different from the bipartite "types":
If you wish to reproduce this, the plotting function I wrote is available on CRAN. |
This is awesome, thank you so much! I will test this function on my data sets and will report back. Let me know if you would like to keep this discussion in the repository or if you would prefer to move it to email. |
You're welcome. Please let me know if you have any problems with it. I'm not so confident with Python so I'm going by the docs on this one. It doesn't accept as many parameters as This toy example (maybe because the datasets is so small) doesn't seem to work unless you fine-tune the resolution. It would be good to know if it works on real data (I know they can't always be shared before publication) and how it compares to the Python leidenalg (and Louvain if it supports Bipartite graphs). I'm okay to keep communications on GitHub where possible (my email is listed as maintainer in the DESCRIPTION if you prefer direct contact). Then other users can see what changes are in development and find these examples. I find the GitHub interface useful to code snippets and figures. It's also helpful to me to track issues in progress that take so long they'd probably get buried in my inbox. Between my current projects and having a young family, I don't have as much time for open-source projects as I'd like. Please bear in mind it may take time to update tests, examples, and get it on CRAN. |
I tried it on the first data set (8k nodes and 27k edges, one connected component) and get the following error:
I get the same error messages with different resolution parameters. I checked the graph My session info
|
This requires additional functions from |
Looks like it works now! My procedure: I reinstalled the development library loaded leiden and igraph seperately It runs but I get the following error message:
In subsequent runs I do not get this error (even for the same line of code) so I wonder what this is. By the way, I tried installing the
I can open a separate issue on the other repository if you think it's worth it. |
I'm not sure what is causing the issue you've run into calling leiden. Don't worry about the |
After some tests with different networks, I could not find any bugs or problems - it works great! But you are right, it is extremely sensitive to the resolution parameter and I had to do quite a bit of testing. |
@PCK1992 Thanks for following up. That's great to hear. In that case, I'll go ahead with merging this into the next release once I have documentation and testing set up for it. For now, I'll leave this issue open for others to see that Bipartite graphs will be supported in the development version. |
After some thorough testing, I discovered a behavior that is quite interesting but I'm not sure if this is related to the R version or the implementation of Leiden in Python. Bottom line is: It looks like the bipartite version only accepts values between 0 and 1, unlike the unipartite version that works fine with values over 1. What I discovered is that if you use a resolution parameter of
Unfortunately, I can't share my data but I could reproduce this behavior with different networks. Is this a package issue on the R side? I assume this is intended behavior on the Python side. |
This is quite different to the behaviour of the regular (non-Bipartite) version of the Leiden algorithm. Thanks for pointing it out. I was really only changing the resolution parameter because the results didn't make much sense (and I thought it was only for this toy example data). I believe the development version of |
This is expected behaviour. Note that you are not using modularity, but another quality function, namely the Constant Potts Model. Indeed, for this quality function, the singleton partition is optimal for a resolution parameter larger than or equal to 1. Personally, I am typically working with this quality function, which I find much more intuitive than modularity (which sometimes behaves quite strangely). In this quality function, clusters have an internal density higher than the resolution parameter, while the density between communities is lower than the resolution parameter. The "relevant" resolution values are typically in the order of the density of the network. It is possible to use the bipartite version of modularity using a particular trick. This is explained in the Bipartite documentation. |
Sorry I may have misunderstood the docs for the Python version? It is possible to use the Bipartite method for other quality functions (e.g., ModularityVertexPartition) not just CPMVertexPartition? I was confused because it is a subheading here: In that case, it should be possible to do this for other methods: |
No, it is not. The support for bipartite clustering is only implemented for |
Thanks, that explains the trouble I had calling it on other quality functions. I've added that argument to the R version and managed to pass the "mimicking" Modularity parameters in the R version.
As mentioned, the
If support for Bipartite graphs is added to other functions, it shouldn't be too much trouble to add them to the R version. |
I've prepared unit tests and a brief vignette on bipartite graphs in R. I will upload this as a minor release (0.3.4) provided checks on Travis CI pass. I will do this before migrating the development version to call |
The leiden R package version 0.3.4 passes all checks and is submitted to CRAN. There is a dedicate vignette for Bipartite graphs here. |
Is it possible to use bipartite graphs? It is supported in the python version of the package so I wonder how one could implement it in the R version.
The text was updated successfully, but these errors were encountered: