Newer
Older
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
"""
SYNTHETIC :Generate piecewise non-homogeneous poisson point process (NHPPP)
To check the running time vs number of edges
To reproduce the results of the paper:
set NO_SAMPLES = 50 from list_samples = [50,100,150,200] ;
one at a time
"""
import numpy as np
import pandas as pd
import math
from itertools import combinations
import itertools
import time
import experiment
from streamlit import caching
# Initilaize
np.random.seed(113)
# To reproduce the results of the paper:
# set NO_SAMPLES = 50 from list_samples = [50,100,150,200] ;
# one at a time
NO_SAMPLES= 50
num_roles=3
num_vertices=20
num_segments = 3
caching.clear_cache()
group_assignment= np.random.randint(num_roles, size=(num_vertices))
nodes = np.arange(num_vertices)
list_of_groups= [[] for _ in range(num_roles)]
for idx, val in enumerate(group_assignment):
list_of_groups[val].append(nodes[idx])
# print(list_of_groups)
size_all_pairs = {}
for k in range(0, num_roles):
for g in range(k, num_roles):
U=list_of_groups[k]
W=list_of_groups[g]
if k == g:
size_all_pairs[k,g] = math.comb(len(U), 2)
if k != g:
size_all_pairs[k,g] = len(U)*len(W)
lamda_arr = np.ones((num_roles, num_roles,num_segments) , dtype=float)
lamda_arr = 1e-2* np.random.randint(11,99, size=(num_roles, num_roles,num_segments))
change_points_arr = np.zeros((num_roles, num_roles, num_segments+1) , dtype=int)
df_all= None
points= list(range(0, (num_segments+1)*NO_SAMPLES, NO_SAMPLES))
list1 = []
# Generate piecewise non-homogeneous poisson process
for k in range(0, num_roles):
for g in range(k, num_roles):
comb = []
if k == g:
comb = list(combinations(list_of_groups[k], 2))
# print(type(comb))
else:
# comb = []
key_data = [list_of_groups[k],list_of_groups[g],]
comb = list(itertools.product(*key_data))
# print(comb)
if len(comb) != size_all_pairs[k,g]:
print('not equal..')
change_points_arr[k,g,:] = points
lamda_arr[k,g,:] = lamda_arr[g,k,:]
for pair in comb:
for d in range(0,num_segments):
s = np.random.poisson(lamda_arr[k,g,d], NO_SAMPLES)
list1=[i for i, e in enumerate(s) if e != 0]
if len(list1) == 0:
print('zero')
list1 = [x+points[d] for x in list1]
df = pd.DataFrame(data=list1)
df.columns =['timestamp']
N= df.size
list_start_stations =[pair[0]] * N
list_end_stations =[pair[1]] * N
df['source'] = list_start_stations
df['target'] = list_end_stations
df_all=pd.concat([df_all, df], ignore_index=True)
## Other preparations
# Remove self loops
df_all = df_all[((df_all['source'] ) != (df_all['target']))]
#sort
df_all=df_all.sort_values('timestamp')
df_all = df_all[['target', 'timestamp','source']]
# Save as .csv file
# df_all.to_csv('./Data/synthetic_ground_truth_g1.csv')
df=df_all
dest_folder='./Results/synthetic/3'
t_df = df['timestamp']
df = df.sample(frac=1).reset_index(drop=True)
#sort
df=df.sort_values('timestamp')
nodes_arr = np.union1d(df['target'],df['source']).astype(int)
# list of nodes
nodes = nodes_arr.tolist()
num_vertices = len(nodes)
def _swap (row):
if row['source'] > row['target']:
row['source'] , row['target'] =row['target'] , row['source']
return row
# Undirected graph
df=df.apply(lambda row: _swap(row), axis=1)
#scale timestamps for zeroth reference point
refValue = df['timestamp'].min()
df['timestamp'] -= refValue
# Experiments
# User parameters
num_roles=3
num_segments=5
num_levels=3# Optional arg
algo_ver=2
dest_folder='./Results/synthetic/'
# tuning parameters
theta = 1e-20
eta = 1
tuning_params= {'theta':theta,'eta':eta}
start_time = time.time()
exp_obj = experiment.Experiment(df,num_roles,num_segments,algo_ver,dest_folder,tuning_params,num_levels,refValue)
exp_obj.execute()
print("--- %s seconds ---" % (time.time() - start_time))
print("no of edges: %d"%df.shape[0])
# running time can be dependent on the machine you run.
# However, it should have a linear trend w.r.t. edges with algo_ver=3.
# However, it should have a quadratic trend w.r.t. edges with algo_ver=2.