MCPcopy
hub / github.com/shenweichen/GraphEmbedding / get_alias_edge

Method get_alias_edge

ge/walker.py:147–171  ·  view source on GitHub ↗

compute unnormalized transition probability between nodes v and its neighbors give the previous visited node t. :param t: :param v: :return:

(self, t, v)

Source from the content-addressed store, hash-verified

145 return walks
146
147 def get_alias_edge(self, t, v):
148 """
149 compute unnormalized transition probability between nodes v and its neighbors give the previous visited node t.
150 :param t:
151 :param v:
152 :return:
153 """
154 G = self.G
155 p = self.p
156 q = self.q
157
158 unnormalized_probs = []
159 for x in G.neighbors(v):
160 weight = G[v][x].get('weight', 1.0) # w_vx
161 if x == t: # d_tx == 0
162 unnormalized_probs.append(weight / p)
163 elif G.has_edge(x, t): # d_tx == 1
164 unnormalized_probs.append(weight)
165 else: # d_tx > 1
166 unnormalized_probs.append(weight / q)
167 norm_const = sum(unnormalized_probs)
168 normalized_probs = [
169 float(u_prob) / norm_const for u_prob in unnormalized_probs]
170
171 return create_alias_table(normalized_probs)
172
173 def preprocess_transition_probs(self):
174 """

Callers 1

Calls 1

create_alias_tableFunction · 0.85

Tested by

no test coverage detected