-
Notifications
You must be signed in to change notification settings - Fork 122
/
analysis.py
147 lines (114 loc) · 5.18 KB
/
analysis.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
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
"""Analysis of results from mdevents_optimize.py and others
@author: Janik Zikovsky
"""
#This line has to be first for some reason.
#from enthought.mayavi import mlab
from pylab import *
import os
import sys
import time
import numpy as np
import pickle
import argparse
from scipy import stats
class Params:
def __init__(self):
self.NumberEvents = 0
self.MaxRecursionDepth = 10
self.MakeTime = 0
self.CoarseBinTime = 0
self.MediumBinTime = 0
self.FineBinTime = 0
self.MemoryUsed = 0
results = []
#========================================================================================================
def plot_results_vs_other(results, x_field, y_field, other_field, extra_title=""):
""" Function to plot Y vs X of anything. It accesses the members of "results" to plot them.
other_field is used to separate by another field, and make separate line plots for each"""
others = set()
for par in results:
others.add( eval('par.%s' % other_field) )
others = list(others)
others.sort()
figure()
for other in others:
data = []
for par in results:
this_other = eval('par.%s' % other_field)
if this_other == other:
x = eval('par.%s' % x_field)
y = eval('par.%s' % y_field)
data.append( (x,y) )
data.sort()
xs = [x for (x,y) in data]
ys = [y for (x,y) in data]
p = plot(xs,ys, marker='.', label="%s = %f" % (other_field, other))
if extra_title != "": extra_title = "\n" + extra_title
title("%s vs %s%s" % (y_field, x_field, extra_title) );
xlabel(x_field)
ylabel(y_field)
legend(loc='best')
savefig("%s_vs_%s.png" % (y_field, x_field));
#========================================================================================================
def plot_results_with_slope(results, x_field, y_field, x_scale=1):
""" Function to plot Y vs X of anything. It accesses the members of "results" to plot them.
other_field is used to separate by another field, and make separate line plots for each
@param x_scale :: multiply x by this amount
"""
figure()
data = []
for par in results:
x = eval('par.%s' % x_field)
y = eval('par.%s' % y_field)
data.append( (x,y) )
data.sort()
xs = [x*x_scale for (x,y) in data]
ys = [y for (x,y) in data]
# Now get the slope
gradient, intercept, r_value, p_value, std_err = stats.linregress(xs,ys)
p = plot(xs,ys, marker='.', label="y = %.3gx + %.3g" % (gradient, intercept))
title("%s vs %s" % (y_field, x_field));
xlabel("%s x %s" % (x_field, x_scale) )
ylabel(y_field)
legend(loc='best')
savefig("%s_vs_%s.png" % (y_field, x_field));
#========================================================================================================
def do_analysis(file_list, type):
# Load back the results
results = []
for filename in file_list:
f = open(filename, 'r')
these_results = pickle.load(f)
results += these_results
f.close()
if type == 1:
plot_results_vs_other(results, "SplitInto", "MakeTime", "SplitThresholdBase")
plot_results_vs_other(results, "SplitInto", "MemoryUsed", "SplitThresholdBase")
plot_results_vs_other(results, "SplitInto", "CoarseBinTime", "SplitThresholdBase")
plot_results_vs_other(results, "SplitInto", "MediumBinTime", "SplitThresholdBase")
plot_results_vs_other(results, "SplitInto", "FineBinTime", "SplitThresholdBase")
elif type == 2:
plot_results_with_slope(results, "NumberEvents", "MakeTime", x_scale=1e-9)
plot_results_with_slope(results, "NumberEvents", "MemoryUsed", x_scale=1e-9)
plot_results_with_slope(results, "NumberEvents", "CoarseBinTime", x_scale=1e-9)
plot_results_with_slope(results, "NumberEvents", "MediumBinTime", x_scale=1e-9)
plot_results_with_slope(results, "NumberEvents", "FineBinTime", x_scale=1e-9)
elif type == 3:
extra_title = "Binary Splitting Method"
plot_results_vs_other(results, "SplitThreshold", "MakeTime", "SplitInto", extra_title)
plot_results_vs_other(results, "SplitThreshold", "MemoryUsed", "SplitInto", extra_title)
plot_results_vs_other(results, "SplitThreshold", "CoarseBinTime", "SplitInto", extra_title)
plot_results_vs_other(results, "SplitThreshold", "MediumBinTime", "SplitInto", extra_title)
plot_results_vs_other(results, "SplitThreshold", "FineBinTime", "SplitInto", extra_title)
show()
#========================================================================================================
if __name__=="__main__":
# parser = argparse.ArgumentParser(description='Analyze results from MDEvents optimization')
# parser.add_argument('files', metavar='FILES', type=str,
# help='The .dat results file')
# parser.add_argument('--force', dest='force', action='store_const',
# const=True, default=False,
# help='Force overwriting existing files. Use with caution!')
# args = parser.parse_args()
file_list = ["optimize_results1.dat"]
do_analysis(file_list, 1)