0

I need to access the eigenvector centrality values for all the vertices in a graph. I am using graph-tool to do that.

I tried to calculate it just like closeness centrality but since in graph tool closeness returns just the Vertex Property map whereas eigenvector returns both the largest eigenvalue of the (weighted) adjacency matrix and the vertex property map, it's not working the same way.

node_closeness = []
for vertex in G.vertices():
    a = closeness(G)[vertex]
    node_closeness.append(a)

This code worked for closeness but same for eigenvector:

node_eigenvector = []
for vertex in G.vertices():
    a = eigenvector(G)[vertex]
    node_eigenvector.append(a)

does not work.

So, it gives me this error:

a = eigenvector(G)[vertex]

TypeError: tuple indices must be integers, not Vertex

But I think it is because eigenvector returns eigenvalue and Vertex property map both. Does anyone know how to fix this?

Monali
  • 43
  • 7

1 Answers1

0

You are right that the eigenvector centrality returns two values, so in order to access the VertexPropertyMap you need to unpack the values first:

import graph_tool.all as gt
g = gt.lattice([3,3], periodic=True)

max_eigenvalue, eigenvector_property_map = gt.eigenvector(g)
eigenvector_property_map[vertex]

The documentation has a fuller example.

wem
  • 11
  • 1