Exemple #1
0
def get_pagerank(filename='data/fs_pagerank.pck'):
    if os.path.isfile(filename):
        return cPickle.load(open(filename, 'rb'))
    else:
        network = get_spatial_friendship_network()
        pagerank = nx.pagerank(convert_network(network))
        cPickle.dump(pagerank, open(filename, 'wb'))
    return pagerank
Exemple #2
0
def dump_network():
    network = get_spatial_friendship_network()
    locations = get_users_locations()
    G = convert_network(network)

    network_file = open('foursquare_network_private.txt', 'w')
    for u, t in G.edges_iter():
        network_file.write('%s %s\n' % (u, t))

    location_file = open('foursquare_locations_private.txt', 'w')
    for u, cord in locations.items():
        lat, lng = cord
        if u in G: location_file.write('%s %lf %lf\n' % (u, lat, lng))
    for i in xrange(len(communities)):
        val = [pagerank[node] for node in communities[i]]
        results[i] = average(val)
    return results


network_code = 1
community_code = 2

network, locations, pagerank, states = routing_simulation_loader.load_network(
    network_code)
communities, com_table, cgraph, stationary = routing_simulation_loader.load_community(
    network_code, community_code)

com_table = convert_com_table(communities)
com_pagerank = get_community_pagerank(communities)
G = convert_network(network)

for node, com in com_table.items():
    for ci, cj in combinations(com, 2):
        val = com_pagerank[ci] - com_pagerank[cj]
        print ci, cj, val, abs(val)

for u, v in G.edges_iter():
    com_u = com_table[u]
    com_v = com_table[v]
    for ci, cj in product(com_u, com_v):
        if ci == cj: continue
        val = com_pagerank[ci] - com_pagerank[cj]
        #print ci, cj, val, abs(val)
Exemple #4
0
def load_network():
	network = foursquare.get_spatial_friendship_network()
	#network = gowalla.get_spatial_friendship_network()
	G = gowalla.convert_network(network)
	return network, G
Exemple #5
0
def transitivity():
    network = get_spatial_friendship_network()
    G = convert_network(network)
    print "Foursquare Transitivity %lf" % nx.transitivity(G)
Exemple #6
0
def calc_pagerank(network, output_file):
    G = convert_network(network)
    pr = nx.pagerank(G, alpha=0.9)
    cPickle.dump(network, open(output_file, 'wb'))
Exemple #7
0
def network_size():
    network = get_spatial_friendship_network()
    G = convert_network(network)
    print "Number of nodes: %d" % len(G.nodes())
    print "Number of edges: %d" % len(G.edges())
        if r1 != r2 and tup1 not in pairs and tup2 not in pairs:
            pairs.add(tup1)
    return list(pairs)


def calc_paths(pairs):
    results = []
    for starter, target in pairs:
        sp = networkx.shortest_path(G, starter, target)
        results.append((starter, target, len(sp)))
    return results


# Step 1: Load the network into memory.
network = foursquare.get_spatial_friendship_network()
G = gowalla.convert_network(network)
users = network.keys()

# Step 2: Pick k randomly select pairs
num_pairs = 10000  # 10^4 pairs
pairs = select_pairs(num_pairs)

# Step 3: Map & Reduce the pair-wise computations
num_processors = 10
work_input = split_work(pairs, num_processors)
results = multiprocessing.Pool(num_processors).map(calc_paths, work_input)

# Step 4: Output the results
for sub_results in results:
    for starter, target, hop in sub_results:
        print starter, target, hop