-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventPartitioner.py
47 lines (40 loc) · 1.66 KB
/
EventPartitioner.py
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
import copy
import numpy as np
from collections import Counter, defaultdict
from conf import client_num
class EventPartitioner(object):
'''
for evaluation, partation the events in trace to clients.
'''
def __init__(self, dataset):
activities = dataset.features[0].flatten()
d = dict(Counter(activities[activities > 0]))
d = dict(sorted(d.items(), key=lambda x: x[1], reverse=True))
self.partition_list=[set() for i in range(client_num)]
for i, activity in enumerate(d.keys()):
self.partition_list[int(i%client_num)].add(int(activity))
temp = [list(actIdset) for actIdset in self.partition_list]
max_len=0
for actIdset in self.partition_list:
max_len=max(len(actIdset),max_len)
self.transform_actId = defaultdict(list)
for i in range(max_len):
for j in range(client_num):
if len(temp[j])>i:
self.transform_actId[i+1].append(temp[j][i])
def partition(self, act_seq):
'''Return a list, where each element represents the current event being executed on which client'''
res = []
for act in act_seq:
for id, acts in enumerate(self.partition_list):
if int(act) in acts:
res.append(id)
break
return np.array(res)
def transform_acts(self,acts):
'''Convert the global ID of the activity to the client local activity ID in the client'''
acts = np.array(acts)
acts_res = copy.deepcopy(acts)
for k,v in self.transform_actId.items():
acts_res[np.isin(acts, v)]= k
return acts_res