vtraag / leidenalg

Implementation of the Leiden algorithm for various quality functions to be used with igraph in Python.
GNU General Public License v3.0
596 stars 78 forks source link

problems with find_partition_multiplex #41

Closed twesleyb closed 4 years ago

twesleyb commented 4 years ago

Hi Vincent,

I used the Leiden algorithm in a paper that myself and my colleagues recently submitted to eLife (biorxiv preprint). Thank you for making the leidenalg python package!

I'm having some trouble when I try to cluster multiplex graphs, maybe you can help (not relevant to that publication).

I'm stuck because calls to leidenalg.find_partition_multiplex generates an error:

terminate called after throwing an instance of 'Exception' what(): Node size vector not the same size as the number of nodes.

I've tried find_multiplex_partition with some dummy graphs:

import sys
import igraph
import leidenalg

## Example 1. Simple generated graphs.

# Create two graphs.
g0 = igraph.Graph.GRG(100, 0.2)
g1 = igraph.Graph.GRG(100, 0.1)

# Multiplex partition.
partition = leidenalg.find_partition_multiplex([g0,g1],
        leidenalg.ModularityVertexPartition)

As well as some real graphs with actual data (source).

# Download pickled examples.
wget https://github.com/twesleyb/StackOverflow/blob/master/leidenalg-multiplex/example/g0.pickle
wget https://github.com/twesleyb/StackOverflow/blob/master/leidenalg-multiplex/example/g0.pickle
## Example 2. Some real graphs.

# Load the graphs.
g0 = igraph.Graph.Read_Pickle("g0.pickle")
g1 = igraph.Graph.Read_Pickle("g1.pickle")

# Enforce same vertex set.
subg0 = g0.induced_subgraph(g1.vs['name'])
subg1 = g1.induced_subgraph(subg0.vs['name'])

# Multiplex partition.
optimiser = leidenalg.Optimiser()
partition = leidenalg.find_partition_multiplex([subg0,subg1],
        leidenalg.ModularityVertexPartition)

Both generate the same error:

terminate called after throwing an instance of 'Exception' what(): Node size vector not the same size as the number of nodes.

The leidenalg Multiplex documentation uses G_telephone and G_email, but without these graphs, I am unable to reproduce the example.

Do you recognize this error message? The error message is unhelpful here because g0 and g1 should contain the same number of nodes in each example.

ragibson commented 4 years ago

Hi, this appears to be a bug with the new fixed node feature.

In the meantime, you can install leidenalg==0.7.0 and your example will work

>>> import igraph as ig
>>> import leidenalg as la
>>> 
>>> print(la.__version__)
0.7.0
>>> 
>>> g0 = ig.Graph.GRG(100, 0.2)
>>> g1 = ig.Graph.GRG(100, 0.1)
>>> membership, improv = la.find_partition_multiplex([g0, g1], la.ModularityVertexPartition)
>>> print(membership)
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 2, 0, 4, 4, 4, 0, 4, 0, 0, 0, 0, 4, 2, 4, 4, 2, 2, 4, 4, 2, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]
twesleyb commented 4 years ago

Thanks Ryan, that fixed the issue.