Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 31 lines (23 sloc) 0.694 kb
848bdc0 kris-samala Sim.py uses trans_prob matrix
authored
1 import sys
2 import fileinput
3 import pickle
4 import csv
5 from locations import LocationGraph
6 import numpy as np
7
8 #python transprob_matrix.py out/gowalla_net trans_prob.csv city_list.p
9
10 network = LocationGraph()
11 network.load(sys.argv[1])
12 city_list = network.nodes()
13 size = len(city_list)
14
15 T = np.zeros(shape=(size,size))
16
17 for i in range(size):
18 city1 = city_list[i]
19 sum_w = network.total_edge_weights(city1)
20 for j in range(size):
21 city2 = city_list[j]
22 w = network.edge_weight(city1,city2)
23 T[i,j] = w / float(sum_w)
24
25 writer = csv.writer(open(sys.argv[2], 'wb'), delimiter=',')
26
27 for row in T:
28 writer.writerow(row)
29
30 pickle.dump(city_list, open(sys.argv[3], 'wb'))
Something went wrong with that request. Please try again.