-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate_metrics.py
executable file
·67 lines (58 loc) · 1.74 KB
/
calculate_metrics.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
import sys
import pprint
from math import sqrt
# import matplotlib.pyplot as plt
plan_metrics = {
'Grounding Time': [],
'|F|': [],
'|X|': [],
'|A|': [],
'|P|': [],
'|E|': [],
'Metric (Search)': [],
'Planning Time (msec)': [],
'Heuristic Time (msec)': [],
'Search Time (msec)': [],
'Expanded Nodes': [],
'States Evaluated': [],
'Number of Dead-Ends detected': [],
'Number of Duplicates detected': []
}
mean_dict = {}
mean_squared_error_dict = {}
filename = sys.argv[1]
plan_file = open(filename, 'r')
observations = 0
for line in plan_file:
for metric in plan_metrics.keys():
if line.startswith(metric):
val = float(line.split(':')[1])
plan_metrics[metric].append(float(line.split(':')[1]))
if "-------------------" in line:
observations += 1
for metric in plan_metrics.keys():
# calculate the mean of every metric key
mean_dict[metric] = sum(plan_metrics[metric]) / len(plan_metrics[metric])
# Mean squared error
mean_squared_error_dict[metric] = 0
for data in plan_metrics[metric]:
mean_squared_error_dict[metric] += (data - mean_dict[metric]) ** 2
mean_squared_error_dict[metric] = sqrt(mean_squared_error_dict[metric] / len(plan_metrics[metric]))
# Print the results
print("\n")
print("Number of observations: ", observations)
print("")
print('Mean values: ')
pprint.pprint(mean_dict)
print("\n")
print("Standard Deviation values: ")
pprint.pprint(mean_squared_error_dict)
# xm, ym = zip(*sorted(mean_dict.items()))
# plt.plot(xm, ym)
# plt.xticks(rotation='vertical')
# plt.show()
# xsq, ysq = zip(*sorted(mean_squared_error_dict.items()))
# plt.plot(xsq, ysq)
# plt.xticks(rotation='vertical')
# plt.show()