title: Determining Betweenness Centrality With The Igraph Library
body: <p>I am a very, very mediocre programmer, but I still aim to use the <a href="http://igraph.sourceforge.net/" rel="nofollow">igraph</a> python library to determine the effect of a user's centrality in a given forum to predict his later contributions to that forum.</p>
  
  <p>I got in touch with someone else who used the <a href="http://networkx.lanl.gov/" rel="nofollow">NetworkX</a> library to do something similar, but given the current size of the forum, calculating exact centrality indices is virtually impossible--it just takes too much time.</p>
  
  <p>This was his code though:</p>
  
  <pre><code>import networkx as netx
  import sys, csv
  
  if len(sys.argv) is not 2:
     print 'Please specify an input graph.'
     sys.exit(1)
  
  ingraph = sys.argv[1]
  graph = netx.readwrite.gpickle.read_gpickle(ingraph)
  
  num_nodes = len(graph.nodes())
  print '%s nodes found in input graph.' % num_nodes
  print 'Recording data in centrality.csv'
  
  # Calculate all of the betweenness measures
  betweenness = netx.algorithms.centrality.betweenness_centrality(graph)
  print 'Betweenness computations complete.'
  closeness = netx.algorithms.centrality.closeness_centrality(graph)
  print 'Closeness computations complete.'
  
  outcsv = csv.writer(open('centrality.csv', 'wb'))
  
  for node in graph.nodes():
     outcsv.writerow([node, betweenness[node], closeness[node]])
  
  print 'Complete!'
  </code></pre>
  
  <p>I tried to write something similar with the igraph library (which allows to make quick estimates rather than exact calculations), but I cannot seem to write data to a CSV file.</p>
  
  <p>My code:</p>
  
  <pre><code>import igraph
  import sys, csv
  
  from igraph import *
  
  graph = Graph.Read_Pajek("C:\karate.net")
  
  print igraph.summary(graph)
  
  estimate = graph.betweenness(vertices=None, directed=True, cutoff=2)
  print 'Betweenness computation complete.'
  
  outcsv = csv.writer(open('estimate.csv', 'wb'))
  
  for v in graph.vs():
     outcsv.writerow([v, estimate[vs]])
  
  print 'Complete!'
  </code></pre>
  
  <p>I can't find how to call individual vertices (or nodes, in NetworkX jargon) in the igraph documentation, so that's where I am getting error messages). Perhaps I am forgetting something else as well; I am probably too bad a programmer to notice :P</p>
  
  <p>What am I doing wrong?</p>