-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexp_visual.py
More file actions
170 lines (137 loc) · 7.43 KB
/
exp_visual.py
File metadata and controls
170 lines (137 loc) · 7.43 KB
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
import json
import numpy as np
import matplotlib.pyplot as plt
from pprint import pprint
def predicate_parser(whole_data, predicate_type):
general_predicates = {}
for key in whole_data.keys():
if key.startswith(predicate_type):
new_keys = key.split(':')[1].strip()
new_keys = new_keys.split(',')
for new_key in new_keys:
new_key = new_key[1:-1]
if new_key.startswith('(('):
new_key = new_key[1:]
if new_key in general_predicates.keys():
general_predicates[new_key]['total_count'] += whole_data[key]['count']
general_predicates[new_key]['total_score'] += whole_data[key]['score']
else:
general_predicates[new_key] = {}
general_predicates[new_key]['total_count'] = whole_data[key]['count']
general_predicates[new_key]['total_score'] = whole_data[key]['score']
counts = list(map(lambda x: x['total_count'], list(general_predicates.values())))
scores = list(map(lambda x: x['total_score'] / x['total_count'], list(general_predicates.values())))
plt.bar(list(general_predicates.keys()), counts)
plt.title(f'Distribution of "{predicate_type}" LTL predicate types after 10 experiments (200 generated formula)')
plt.xticks(rotation=90)
plt.subplots_adjust(bottom=0.5)
plt.show()
plt.bar(list(general_predicates.keys()), scores)
plt.title(f'Average scores of "{predicate_type}" LTL predicate types after 10 experiments (200 generated formula)')
plt.xticks(rotation=90)
plt.subplots_adjust(bottom=0.5)
plt.show()
def predicate_parser_with_implication(whole_data, predicate_type):
general_predicates = {}
for key in whole_data.keys():
if key.startswith(predicate_type):
new_keys = key.split(':')[1].strip()
if len(new_keys.split(',')) == 2:
antecedent, consequent = new_keys.split(',')
antecedent = antecedent.strip()[1:]
consequent = consequent.strip()[:-1]
new_key = f'{antecedent}=>\n{consequent}'
if new_key in general_predicates.keys():
general_predicates[new_key]['total_count'] += whole_data[key]['count']
general_predicates[new_key]['total_score'] += whole_data[key]['score']
else:
general_predicates[new_key] = {}
general_predicates[new_key]['total_count'] = whole_data[key]['count']
general_predicates[new_key]['total_score'] = whole_data[key]['score']
else:
pairs = new_keys.split(')), ((')
for i, pair in enumerate(pairs):
antecedent, consequent = pair.split(',')
if i == 0:
antecedent = antecedent.strip()[1:]
consequent = consequent.strip() + ')'
elif i == len(pairs) - 1:
antecedent = '(' + antecedent.strip()
consequent = consequent.strip()[:-1]
else:
antecedent = '(' + antecedent.strip()
consequent = consequent.strip() + ')'
new_key = f'{antecedent}=>\n{consequent}'
if new_key in general_predicates.keys():
general_predicates[new_key]['total_count'] += whole_data[key]['count']
general_predicates[new_key]['total_score'] += whole_data[key]['score']
else:
general_predicates[new_key] = {}
general_predicates[new_key]['total_count'] = whole_data[key]['count']
general_predicates[new_key]['total_score'] = whole_data[key]['score']
counts = list(map(lambda x: x['total_count'], list(general_predicates.values())))
scores = list(map(lambda x: x['total_score'] / x['total_count'], list(general_predicates.values())))
plt.bar(list(general_predicates.keys()), counts)
plt.title(f'Distribution of "{predicate_type}" LTL predicate types after 10 experiments (200 generated formula)')
plt.xticks(rotation=90)
plt.subplots_adjust(bottom=0.5)
plt.show()
plt.bar(list(general_predicates.keys()), scores)
plt.title(f'Average scores of "{predicate_type}" LTL predicate types after 10 experiments (200 generated formula)')
plt.xticks(rotation=90)
plt.subplots_adjust(bottom=0.5)
plt.show()
def feature_importance_analyzer():
file_names = ['features_effect_Kevin_De Bruyne_Manchester City_Leicester.json',
'features_effect_Kyle_Walker_Manchester City_Chelsea.json',
'features_effect_Manuel_Akanji_Manchester City_Chelsea.json']
for file_name in file_names:
with open(f'results/{file_name}', 'r') as handle:
data = json.load(handle)
print(f'\n\n ############### {file_name} ###############')
for key in data.keys():
info = {'sometime_before': 0, 'response': 0, 'stability': 0, 'global': 0, 'eventual': 0}
print(f'********** {key} **********')
parse1 = data[key]
max_score = parse1[0][-1]
for item in parse1:
if 'sometime_before' in item[0]:
info['sometime_before'] += 1
elif 'response' in item[0]:
info['response'] += 1
elif 'stability' in item[0]:
info['stability'] += 1
elif 'global' in item[0]:
info['global'] += 1
elif 'eventual' in item[0]:
info['eventual'] += 1
pprint(info)
print(max_score)
print(info['response'] + info['sometime_before'])
print('****************************************')
print(f'\n\n ###########################################')
if __name__ == '__main__':
feature_importance_analyzer()
exit()
with open('results/formula_distribution_Kevin_De Bruyne_Manchester City_Leicester.json', 'r') as handle:
data = json.load(handle)
unique_predicate_types = {}
for key in data.keys():
predecessor = key.split(':')[0].strip()
if predecessor in unique_predicate_types.keys():
unique_predicate_types[predecessor] += data[key]['count']
else:
unique_predicate_types[predecessor] = data[key]['count']
plt.bar(list(unique_predicate_types.keys()), list(unique_predicate_types.values()))
plt.title('Distribution of LTL predicate types after 10 experiments (200 generated formula)')
plt.show()
# distribution of global predicates
predicate_parser(data, 'global')
# distribution of eventual predicates
predicate_parser(data, 'eventual')
# distribution of stability predicates
predicate_parser(data, 'stability')
# distribution of response predicates
predicate_parser_with_implication(data, 'response')
# distribution of sometime_before predicates
predicate_parser_with_implication(data, 'sometime_before')