2 Process timing results from timeShonanAveraging 7 import matplotlib.pyplot
as plt
8 from matplotlib.ticker
import FuncFormatter
10 from collections
import Counter
13 """ Make a plot that combines timing and SO(3) cost. 15 name: string of the plot title 16 p_values: list of p-values (int) 17 times: list of timings (seconds) 18 costs: list of costs (double) 19 Will calculate the range of the costs, default minimum range = 10.0 22 cost_range =
max(
max(costs)-min_cost,min_cost_range)
24 ax1 = fig.add_subplot(111)
25 ax1.plot(p_values, times, label=
"time")
26 ax1.set_ylabel(
'Time used to optimize \ seconds')
27 ax1.set_xlabel(
'p_value')
29 ax2.plot(p_values, costs,
'r', label="cost") 30 ax2.set_ylabel('Cost at SO(3) form')
31 ax2.set_xlabel(
'p_value')
32 ax2.set_xticks(p_values)
33 ax2.set_ylim(min_cost, min_cost + cost_range)
34 plt.title(name, fontsize=12)
35 ax1.legend(loc=
"upper left")
36 ax2.legend(loc=
"upper right")
37 plt.interactive(
False)
41 """ Make a bar that show the success rate for each p_value according to whether the SO(3) cost converges 43 name: string of the plot title 44 p_values: list of p-values (int) 45 times: list of timings (seconds) 46 costs: list of costs (double) 47 iter: int of iteration number for each p_value 50 max_cost = np.mean(np.array(heapq.nlargest(iter, costs)))
55 p_mean_cost = [np.mean(np.array(costs[i*iter:(i+1)*iter]))
for i
in range(
len(p_values))]
56 p_max = p_values[p_mean_cost.index(
max(p_mean_cost))]
64 costs_tmp = costs[p_values.index(p)*iter:(p_values.index(p)+1)*iter]
65 mean_cost =
sum(costs_tmp)/
len(costs_tmp)
66 mean_costs.append(mean_cost)
67 times_tmp = times[p_values.index(p)*iter:(p_values.index(p)+1)*iter]
68 mean_time =
sum(times_tmp)/
len(times_tmp)
69 mean_times.append(mean_time)
74 if p_mean_cost[0] >= 0.95*np.mean(np.array(costs))
and p_mean_cost[0] <= 1.05*np.mean(np.array(costs)):
75 p_success_rates = [ 1.0
for p
in p_values]
79 p_costs = costs[p_values.index(p)*iter:(p_values.index(p)+1)*iter]
81 converged = [
int(p_cost < 0.3*max_cost)
for p_cost
in p_costs]
82 success_rate =
sum(converged)/
len(converged)
83 p_success_rates.append(success_rate)
85 p_success_rates.append(0)
87 plt.bar(p_values, p_success_rates, align=
'center', alpha=0.5)
89 plt.yticks(np.arange(0, 1.2, 0.2), [
'0%',
'20%',
'40%',
'60%',
'80%',
'100%'])
91 plt.ylabel(
"success rate")
92 plt.title(name, fontsize=12)
96 """ Make a plot that combines time for optimizing, time for optimizing and compute min_eigen, 97 min_eigen, subound (subound = (f_R - f_SDP) / f_SDP). 99 name: string of the plot title 100 p_values: list of p-values (int) 101 times1: list of timings (seconds) 104 times2: list of timings (seconds) 105 min_eigens: list of min_eigen (double) 106 subounds: list of subound (double) 109 if dict(Counter(p_values))[5] != 1:
112 p_mean_times1 = [np.mean(np.array(times1[i*iter:(i+1)*iter]))
for i
in range(
len(p_values))]
113 p_mean_times2 = [np.mean(np.array(times2[i*iter:(i+1)*iter]))
for i
in range(
len(p_values))]
114 print(
"p_values \n", p_values)
115 print(
"p_mean_times_opti \n", p_mean_times1)
116 print(
"p_mean_times_eig \n", p_mean_times2)
118 p_mean_costPs = [np.mean(np.array(costPs[i*iter:(i+1)*iter]))
for i
in range(
len(p_values))]
119 p_mean_cost3s = [np.mean(np.array(cost3s[i*iter:(i+1)*iter]))
for i
in range(
len(p_values))]
120 p_mean_lambdas = [np.mean(np.array(min_eigens[i*iter:(i+1)*iter]))
for i
in range(
len(p_values))]
122 print(
"p_mean_costPs \n", p_mean_costPs)
123 print(
"p_mean_cost3s \n", p_mean_cost3s)
124 print(
"p_mean_lambdas \n", p_mean_lambdas)
125 print(
"*******************************************************************************************************************")
130 plt.ylabel(
'Time used (seconds)')
131 plt.xlabel(
'p_value')
132 plt.plot(p_values, times1,
'r', label="time for optimizing") 133 plt.plot(p_values, times2, 'blue', label=
"time for optimizing and check")
134 plt.title(name, fontsize=12)
135 plt.legend(loc=
"best")
136 plt.interactive(
False)
140 plt.ylabel(
'Min eigen_value')
141 plt.xlabel(
'p_value')
142 plt.plot(p_values, min_eigens,
'r', label="min_eigen values") 143 plt.title(name, fontsize=12) 144 plt.legend(loc="best")
145 plt.interactive(
False)
149 plt.ylabel(
'sub_bounds')
150 plt.xlabel(
'p_value')
151 plt.plot(p_values, subounds,
'blue', label=
"sub_bounds")
152 plt.title(name, fontsize=12)
153 plt.legend(loc=
"best")
161 parser = argparse.ArgumentParser()
162 parser.add_argument(
"path")
163 args = parser.parse_args()
167 domain = os.path.abspath(args.path)
168 for info
in os.listdir(args.path):
169 file_path.append(os.path.join(domain, info))
176 names[0] =
'tinyGrid3D vertex = 9, edge = 11' 177 names[1] =
'smallGrid3D vertex = 125, edge = 297' 178 names[2] =
'parking-garage vertex = 1661, edge = 6275' 179 names[3] =
'sphere2500 vertex = 2500, edge = 4949' 181 names[5] =
'torus3D vertex = 5000, edge = 9048' 182 names[6] =
'cubicle vertex = 5750, edge = 16869' 183 names[7] =
'rim vertex = 10195, edge = 29743' 186 for key, name
in names.items():
191 for path
in file_path:
192 if name[0:3]
in path:
194 if name_file ==
None:
195 print(
"The file %s is not in the path" % name)
198 p_values, times1, costPs, cost3s, times2, min_eigens, subounds = [],[],[],[],[],[],[]
199 with open(name_file)
as csvfile:
200 reader = csv.reader(csvfile, delimiter=
'\t')
203 p_values.append(
int(row[0]))
204 times1.append(
float(row[1]))
205 costPs.append(
float(row[2]))
206 cost3s.append(
float(row[3]))
208 times2.append(
float(row[4]))
209 min_eigens.append(
float(row[5]))
210 subounds.append(
float(row[6]))
void print(const Matrix &A, const string &s, ostream &stream)
def make_convergence_plot(name, p_values, times, costs, iter=10)
def make_eigen_and_bound_plot(name, p_values, times1, costPs, cost3s, times2, min_eigens, subounds)
const mpreal sum(const mpreal tab[], const unsigned long int n, int &status, mp_rnd_t mode=mpreal::get_default_rnd())
def make_combined_plot(name, p_values, times, costs, min_cost_range=10)