Reputation: 71
I have a difficulty in projecting a toy bipartite network.
from igraph import *
def create_bipartite(n1, n2, directed=False):
g = Graph(n1+n2, directed=True)
g.vs["type"] = 0
g.vs[n2:]["type"] = 1
return g
gb=create_bipartite(4,3)
gb.add_edges([(0,1),(0,2),(3,4),(0,4),(0,5),(3,6)])
> In [358]: gb.is_bipartite()
Out[358]: True
In [359]: gb.bipartite_projection()
---------------------------------------------------------------------------
InternalError Traceback (most recent call last)
<ipython-input-359-a7b9927dc7bb> in <module>()
----> 1 gb.bipartite_projection()
/usr/lib/python2.7/dist-packages/igraph/__init__.pyc in bipartite_projection(self, types, multiplicity, *args, **kwds)
2530 superclass_meth = super(Graph, self).bipartite_projection
2531 if multiplicity:
-> 2532 g1, g2, w1, w2 = superclass_meth(types, True, *args, **kwds)
2533 g1.es["weight"] = w1
2534 g2.es["weight"] = w2
InternalError: Error at structure_generators.c:84: Invalid (negative) vertex id, Invalid vertex id
In [360]:
The error I get is this trying to project to either nodes: What does that mean? negative vertex? Any ideas how to work around this?
Upvotes: 1
Views: 736
Reputation: 48061
Newer versions of igraph give a more informative error message (actually, I'm not sure whether this change went into release already or not - I'm living on the bleeding edge):
InternalError: Error at ../../src/bipartite.c:198: Non-bipartite edge found in
bipartite projection, Invalid value
(You may be surprised at this point why g.is_bipartite()
returned True
- the reason is that g.is_bipartite()
only checks whether the graph has a vertex attribute named type
).
The problem is that your type vector looks like this:
>>> gb.vs["type"]
[0, 0, 0, 1, 1, 1, 1]
Since you have an edge between vertices 3 and 4, both of which are of type 1, this graph is not bipartite. I strongly suspect that the actual bug is in create_bipartite
, where you wanted to write this:
g.vs[n1:]["type"] = 1
instead of this:
g.vs[n2:]["type"] = 1
Upvotes: 1