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

Function create_alias_table

ge/alias.py:4–38  ·  view source on GitHub ↗

:param area_ratio: sum(area_ratio)=1 :return: accept,alias

(area_ratio)

Source from the content-addressed store, hash-verified

2
3
4def create_alias_table(area_ratio):
5 """
6
7 :param area_ratio: sum(area_ratio)=1
8 :return: accept,alias
9 """
10 l = len(area_ratio)
11 accept, alias = [0] * l, [0] * l
12 small, large = [], []
13 area_ratio_ = np.array(area_ratio) * l
14 for i, prob in enumerate(area_ratio_):
15 if prob < 1.0:
16 small.append(i)
17 else:
18 large.append(i)
19
20 while small and large:
21 small_idx, large_idx = small.pop(), large.pop()
22 accept[small_idx] = area_ratio_[small_idx]
23 alias[small_idx] = large_idx
24 area_ratio_[large_idx] = area_ratio_[large_idx] - \
25 (1 - area_ratio_[small_idx])
26 if area_ratio_[large_idx] < 1.0:
27 small.append(large_idx)
28 else:
29 large.append(large_idx)
30
31 while large:
32 large_idx = large.pop()
33 accept[large_idx] = 1
34 while small:
35 small_idx = small.pop()
36 accept[small_idx] = 1
37
38 return accept, alias
39
40
41def alias_sample(accept, alias):

Callers 5

simulateFunction · 0.90
get_alias_edgeMethod · 0.85
_get_transition_probsMethod · 0.85
_gen_sampling_tableMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected