igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Can not plot community structure


From: Tamas Nepusz
Subject: Re: [igraph] Can not plot community structure
Date: Sat, 9 Apr 2016 12:15:15 +0200

It seems like there's a bug in the code of the label propagation
algorithm which assigns some of the vertices to a community with index
= -1 if there are lots of isolated vertices. A quick way to reproduce
this:

>>> Graph(10).community_label_propagation().membership
[-1, 0, 1, 2, 3, 4, 5, 6, 7, 8]

A temporary workaround is:

g = Graph(10)
cl = g.community_label_propagation()
cl = VertexClustering(g, membership=[x+1 for x in cl.membership])

I will fix the underlying bug in the label propagation algorithm soon.

T.


On Sat, Apr 9, 2016 at 1:23 AM, Zhige Xin <address@hidden> wrote:
> Hi I tried to plot the community structure by using label propagation
> algorithm but got some errors. First, the value of modularity is none.
> Second, it produced IndexError: color index must be non-negative.
>
> My idea:
> 1. Read from a csv file with the format of weighted adjacency matrix
> 2. Convert the data into a graph object in igraph
> 3. Applying label propagation algorithm to find communities
> 4. Plot the result
>
> My code is following:
>
> from igraph import *
> from numpy import genfromtxt
> import numpy as np
>
>
> my_data = genfromtxt('CBSNews.csv', delimiter=',')
> conn_indices = np.where(my_data)
> weights = my_data[conn_indices]
> edges = zip(*conn_indices)
> g = Graph(edges=edges, directed=False)
> g.es['weight'] = weights
> result = g.community_label_propagation()
> print result.modularity
> plot(result)
>
> The erros message is:
>
> Traceback (most recent call last):
>   File "plot_community.py", line 25, in <module>
>     plot(result)
>   File "/usr/local/lib/python2.7/site-packages/igraph/drawing/__init__.py",
> line 475, in plot
>     result.show()
>   File "/usr/local/lib/python2.7/site-packages/igraph/drawing/__init__.py",
> line 316, in show
>     self.redraw(ctx)
>   File "/usr/local/lib/python2.7/site-packages/igraph/drawing/__init__.py",
> line 269, in redraw
>     plotter(ctx, bbox, palette, *args, **kwds)
>   File "/usr/local/lib/python2.7/site-packages/igraph/clustering.py", line
> 509, in __plot__
>     return self._graph.__plot__(context, bbox, palette, *args, **kwds)
>   File "/usr/local/lib/python2.7/site-packages/igraph/__init__.py", line
> 3152, in __plot__
>     drawer.draw(self, palette, *args, **kwds)
>   File "/usr/local/lib/python2.7/site-packages/igraph/drawing/graph.py",
> line 259, in draw
>     vertex_builder = vertex_drawer.VisualVertexBuilder(graph.vs, kwds)
>   File "/usr/local/lib/python2.7/site-packages/igraph/drawing/metamagic.py",
> line 222, in __init__
>     values = self._collect_attributes(attr_spec)
>   File "/usr/local/lib/python2.7/site-packages/igraph/drawing/metamagic.py",
> line 340, in _collect_attributes
>     result = [transform(x) for x in result]
>   File "/usr/local/lib/python2.7/site-packages/igraph/drawing/colors.py",
> line 93, in get
>     raise IndexError("color index must be non-negative")
>
> I do appreciate it if anyone can help.
>
>
>
>
> Best,
> Zhige
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/igraph-help
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]