-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmake_stochastic_graph.py
More file actions
35 lines (20 loc) · 898 Bytes
/
make_stochastic_graph.py
File metadata and controls
35 lines (20 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# coding: utf-8
import sys
import numpy as np
from graph_helpers import load_graph_by_name
from preprocess_graph import reverse_edge_weights
graph_name = sys.argv[1]
g = load_graph_by_name(graph_name, weighted=True)
w = g.new_edge_property('float')
in_deg = g.degree_property_map('in', weight=None)
for u in g.vertices():
for v in g.vertex(u).in_neighbours(): # v -> u
w[g.edge(v, u)] = 1 / in_deg[u]
in_deg_weighted = g.degree_property_map('in', weight=w)
assert np.all(np.isclose(in_deg_weighted.a, 1)), 'maybe self-loops are not removed'
g.edge_properties['weights'] = w
g.save('data/{}/graph_weighted_sto.gt'.format(graph_name))
rev_g = reverse_edge_weights(g)
out_deg_weighted = g.degree_property_map('out', weight=rev_g.edge_properties['weights'])
assert np.all(np.isclose(out_deg_weighted.a, 1))
rev_g.save('data/{}/graph_weighted_sto_rev.gt'.format(graph_name))