vtraag / leidenalg

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

Error with find_partition_multiplex #179

Closed elisabettabiondi closed 4 months ago

elisabettabiondi commented 4 months ago

Hi @vtraag,

I am dealing with a signed network and I would like to partition it into two clusters. I followed the example in the documentation:

import igraph as ig
import leidenalg as la
import numpy as np

g0 = ig.Graph.GRG(100, 0.2)
w = 10 * np.random.rand(len(g0.es)) * np.random.choice([-1,1],p=[0.1,0.9],size=len(g0.es))
g0.es['weight'] = w
g_pos = g0.subgraph_edges(g0.es.select(weight_gt=0), delete_vertices=False)
g_neg = g0.subgraph_edges(g0.es.select(weight_lt=0), delete_vertices=False)
g_neg.es['weight'] = [-w for w in g_neg.es['weight']]

part_pos = la.ModularityVertexPartition(g_pos, weights='weight')
part_neg = la.ModularityVertexPartition(g_neg, weights='weight')

partition = la.find_partition_multiplex([part_pos, part_neg], layer_weights=[1, -1],
                                        partition_type=la.ModularityVertexPartition)

This provided me with an error:

AttributeError: 'ModularityVertexPartition' object has no attribute 'vcount'

What error am I doing?

Thank you

vtraag commented 4 months ago

Hi @elisabettabiondi, you are calling find_partition_multiplex which is expecting to be passed igraph.Graphs, not leidenalg.VertexPartitions. If you look at the example in the documentation at https://leidenalg.readthedocs.io/en/stable/multiplex.html#negative-links, you can see that it uses optimise_partition_multiplex, not find_partition_multiplex.

This should solve your problem. If it doesn't, feel free to re-open the issue!