SkBlaz/py3plex

Community partition error

Closed this issue · 5 comments

I am trying to run this simple code

from py3plex.core import multinet
from py3plex.core import random_generators
from py3plex.algorithms.community_detection import community_louvain as cwl

Initiate an instance of a random graph
ER_multilayer = random_generators.random_multilayer_ER(500,8,0.05,directed=False)

Finding best partition

partition = cwl.best_partition(ER_multilayer)

It gives the following error:

File "<ipython-input-136-79ea27059665>", line 1, in <module>
partition = cwl.best_partition(ER_multilayer)

File "/usr/local/lib/python3.6/dist-packages/py3plex/algorithms/community_detection/community_louvain.py", line 292, in best_partition randomize)

File "/usr/local/lib/python3.6/dist-packages/py3plex/algorithms/community_detection/community_louvain.py", line 358, in generate_dendrogram
if graph.is_directed():

AttributeError: 'multi_layer_network' object has no attribute 'is_directed'

Also, importing the community wrapper also gives the following error

from py3plex.algorithms.community_detection import community_wrapper as cw

Traceback (most recent call last):

File "<ipython-input-137-ffcfd3de8e39>", line 1, in <module>
from py3plex.algorithms.community_detection import community_wrapper as cw

File "/usr/local/lib/python3.6/dist-packages/py3plex/algorithms/community_detection/community_wrapper.py", line 5, in <module> from .NoRC import *

File "/usr/local/lib/python3.6/dist-packages/py3plex/algorithms/community_detection/NoRC.py", line 16, in <module>
import community

ModuleNotFoundError: No module named 'community'

Hello Ashuein. I've added an example demonstrating how to perform Louvain on top of ER graphs. There is a reason for another abstraction layer between the algorithms and the API. Please, re install with the newest commit for this to work:

https://github.com/SkBlaz/Py3plex/blob/master/examples/example_community_detection.py (lines 9-13)

Your new commit works with the random multilayer function, but not with the ../datasets/simple_multiplex.edgelist

I tried with the original data file, then I modified to include all nodes in all layers and then I tried by removing any string identification in the edge list file

The new edgelist looks like this:

1 1 2 1
1 1 3 1
1 1 4 1
2 1 2 1
2 1 3 1
2 1 4 1
3 1 2 1
3 1 3 1
3 1 4 1

The layer file looks like this:

LayerID LayerName
1 hub
2 transport
3 utility

But on running the Louvian community code on all possible files as mentioned above

comNet = multinet.multi_layer_network().load_network('../Py3plex_master/datasets/simple_multiplex.edgelist',directed=False,input_type='multiplex_edges')
comNet.basic_stats()
comNet.load_layer_name_mapping('../Py3plex_master/datasets/simple_multiplex.txt')
mat = comNet.get_supra_adjacency_matrix()

part = cw.louvain_communities(comNet)

I get the following error:

Traceback (most recent call last):

File "", line 1, in
part = cw.louvain_communities(comNet)

File "/usr/local/lib/python3.6/dist-packages/py3plex-0.59-py3.6.egg/py3plex/algorithms/community_detection/community_wrapper.py", line 94, in louvain_communities
partition = best_partition(network)

File "/usr/local/lib/python3.6/dist-packages/py3plex-0.59-py3.6.egg/py3plex/algorithms/community_detection/community_louvain.py", line 292, in best_partition
randomize)

File "/usr/local/lib/python3.6/dist-packages/py3plex-0.59-py3.6.egg/py3plex/algorithms/community_detection/community_louvain.py", line 371, in generate_dendrogram
status.init(current_graph, weight, part_init)

File "/usr/local/lib/python3.6/dist-packages/py3plex-0.59-py3.6.egg/py3plex/algorithms/community_detection/community_louvain.py", line 57, in init
self.total_weight = graph.size(weight=weight)

File "/usr/local/lib/python3.6/dist-packages/networkx/classes/graph.py", line 1785, in size
s = sum(d for v, d in self.degree(weight=weight))

File "/usr/local/lib/python3.6/dist-packages/networkx/classes/graph.py", line 1785, in
s = sum(d for v, d in self.degree(weight=weight))

File "/usr/local/lib/python3.6/dist-packages/networkx/classes/reportviews.py", line 529, in iter
deg = sum(d.get(weight, 1) for key_dict in nbrs.values()

TypeError: unsupported operand type(s) for +: 'int' and 'str'

it works now.

I am closing this issue as I didn't have any problems with this further