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

"Membership cannot exceed number of nodes" error with leidenalg 0.8.4 #66

Closed
AvantiShri opened this issue Apr 15, 2021 · 2 comments
Closed

Comments

@AvantiShri
Copy link

Hi, I'm getting an odd error with the latest version of leidenalg that wasn't appearing with 0.8.3. Please see this github gist for a reproduction of the error:

https://colab.research.google.com/gist/AvantiShri/46060b5fe0fac540830a3078758a487b/-membership-cannot-exceed-number-of-nodes-error-with-leidenalg-0-8-4.ipynb

Consider the following test:

import numpy as np
import leidenalg
import igraph as ig

def test():
  g = ig.Graph(directed=None)
  g.add_vertices(2)
  g.add_edges([(0,1)])
  g.es['weight'] = np.array([0.5])
  leidenalg.find_partition(graph=g, partition_type=leidenalg.ModularityVertexPartition,
      weights=g.es['weight'], n_iterations=-1,
      initial_membership=np.array([0,1]), seed=1234)

With leidenalg 0.8.3, test() runs without any error. However, with version 0.8.4, it produces:

/usr/local/lib/python3.7/dist-packages/leidenalg/functions.py in find_partition(graph, partition_type, initial_membership, weights, n_iterations, max_comm_size, seed, **kwargs)
     86   partition = partition_type(graph,
     87                              initial_membership=initial_membership,
---> 88                              **kwargs)
     89   optimiser = Optimiser()
     90 

/usr/local/lib/python3.7/dist-packages/leidenalg/VertexPartition.py in __init__(self, graph, initial_membership, weights, node_sizes)
    467 
    468     self._partition = _c_leiden._new_ModularityVertexPartition(pygraph_t,
--> 469         initial_membership, weights, node_sizes)
    470     self._update_internal_membership()
    471 

TypeError: Membership cannot exceed number of nodes.
@vtraag
Copy link
Owner

vtraag commented Apr 15, 2021

Hi @AvantiShri, thanks for reporting this! I now realise that I changed something in 0.8.4 to correct some warnings, but that was previously used to accommodate for numpy. I will correct this again. As a workaround, please pass in any arguments, including the initial_membership, function as a Python list, not as a numpy array. You can use .tolist() of the numpy array.

@vtraag vtraag closed this as completed in 6b6d86e Apr 15, 2021
@AvantiShri
Copy link
Author

For future people encountering this: @vtraag's suggestion of using .tolist() (rather than simply wrapping the numpy array in a list(...) call) seems to be important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants