Skip to content

Instantly share code, notes, and snippets.

@stevekochscience
Created May 29, 2015 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevekochscience/ffe37306f3c879c09c5b to your computer and use it in GitHub Desktop.
Save stevekochscience/ffe37306f3c879c09c5b to your computer and use it in GitHub Desktop.
Files related to trouble I'm having reading edgelist files with NetworKit (2015 - May 29)
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
node normalized betweenness
4 5.555556e-01
5 5.555556e-01
3 5.000000e-01
6 5.000000e-01
2 3.888889e-01
7 3.888889e-01
1 2.222222e-01
8 2.222222e-01
0 0.000000e+00
9 0.000000e+00
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
node normalized betweenness
5 4.444444e-01
4 4.166667e-01
6 4.166667e-01
3 3.333333e-01
7 3.333333e-01
2 1.944444e-01
8 1.944444e-01
0 0.000000e+00
1 0.000000e+00
9 0.000000e+00
# Call this program with parameters: inputfilename, epsilon
from networkit import *
import time
from sys import argv
# Unpack the command line arguments
if len(argv) !=3:
print("Wrong number of command line arguments: ")
print(" input file name; epsilon")
exit()
script, infilename, epsilon = argv
basename = infilename.split('.')[0]
outfilename = basename + '_e' + epsilon + '.txt'
if epsilon == '0':
print("using exact calculation")
else: #convert epsilon and delta from strings to numbers
epsilon = float(epsilon)
print("using approximate calculation")
reader = graphio.EdgeListReader("\t", 1, continuous=True)
G = reader.read(infilename)
#properties.overview(G)
print("starting computation of betweenness")
print("output file will be: %s" %outfilename)
start = time.time()
if epsilon == '0':
bc = centrality.Betweenness(G, True)
else:
bc = centrality.ApproxBetweenness(G, epsilon=epsilon)
bc.run()
end = time.time()
elapsed = str(end - start)
out = bc.ranking()[:10]
print(out)
print("elapsed time for betweenness: ")
print(elapsed)
f = open(outfilename, 'w')
f.write("node\tnormalized betweenness\n")
full = bc.ranking()
for item in full:
node = str(item[0])
val = '%e' % item[1]
out = node + '\t' + val + '\n'
f.write(out)
f.close()
properties.overview(G)
@stevekochscience
Copy link
Author

I am using exact betweenness, by calling the python code like so:
python calcbetween_epsilon.py 0edge.txt 0

@stevekochscience
Copy link
Author

Here is note I sent to NetworKit mailing list:
Hello,

I am getting some inconsistent results (exact betweenness) and am not sure if there's something wrong with the installation I'm using, whether I have a bug in python code, or whether I'm not creating input files with the correct format. Here is the behavior (all input files are '%d\t%d\n' format):

  • If I use edge list starting at 1, with no edges skipped the betweenness calculates correctly, but the output nodes are renumbered to start at 0
  • If I use an edge list starting at 2, it looks like nodes are shifted by 1, but also another node is created
  • If I use an edge list starting at 0, I get different behavior, depending on how many edges there are. The attached "0edge.txt" file produces a segmentation fault.

We have been using edge lists that start at 1 and have been assuming NetworKit just shifts them down by one to begin at zero, but otherwise everything is fine. I am comfortable with this as long as it's what's supposed to happen. But I am worried that I am just getting lucky.

Any thoughts on what I'm doing wrong?

I have attached the code, input files, and output files. Output files have '_e0.txt' endings. I've also put the files at this public gist: https://gist.github.com/stevekochscience/ffe37306f3c879c09c5b

Thank you!

--Steve

PS: I will also note that my code always crashes with a unicode error during properties.overview(G) but it has always done that, maybe I shouldn't have ignored that issue.

@stevekochscience
Copy link
Author

DOH
I realized in line 22, the '1' is telling it what the starting node is. I was not changing this parameter accordingly. Sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment