22 from math_tools.statistics
import statistics
29 'TPN' :
'Target Pose Number',
31 'CIR' :
'Configuration in Range',
32 'NSPT' :
'Number of Starting Point Trials',
33 'NI' :
'Number of Iterations',
34 'NS' :
'Number of Success',
35 'RT' :
'Running Time (ms)',
36 'TRT' :
'Total Running Time (ms)',
37 'ART' :
'Average Running Time (ms)',
38 'TNI' :
'Total Number of Iterations',
39 'ANI' :
'Average Number of Iterations',
40 'PS' :
'Percentage of Success',
41 'IC' :
'Initial Configuration',
42 'FC' :
'Final Configuration',
43 'IP' :
'Initial Pose',
47 'PSIR' :
'Percentage of Success in Range',
48 'NRun' :
'Number of Runs',
49 'NSRun' :
'Number of Successful Runs',
50 'NIR' :
'Number of Runs in Range',
51 'NSIR' :
'Number of Successful Runs in Range',
52 'NI-tot':
'Number of Iterations-Total',
53 'NI-max':
'Number of Iterations-Maximum',
54 'NI-min':
'Number of Iterations-Minimum',
55 'NI-avr':
'Number of Iterations-Average',
56 'NI-med':
'Number of Iterations-Median',
57 'NI-sdv':
'Number of Iterations-Standard Deviation',
58 'NI-mse':
'Number of Iterations-Mean Standard Error',
59 'NT-max':
'Number of Trials-Maximum',
60 'NT-min':
'Number of Trials-Minimum',
61 'NT-avr':
'Number of Trials-Average',
62 'RT-tot':
'Running Time-Total (ms)',
63 'RT-max':
'Running Time-Maximum (ms)',
64 'RT-min':
'Running Time-Minimum (ms)',
65 'RT-avr':
'Running Time-Average (ms)',
66 'RT-med':
'Running Time-Median (ms)',
67 'RT-sdv':
'Running Time-Standard Deviation (ms)',
68 'RT-mse':
'Running Time-Mean Standard Error',
73 'Target Pose Number' :
'TPN',
75 'Number of Starting Point Trials' :
'NSPT',
76 'Number of Iterations' :
'NI',
77 'Number of Success' :
'NS',
78 'Running Time (ms)' :
'RT',
79 'Total Running Time (ms)' :
'TRT',
80 'Average Running Time (ms)' :
'ART',
81 'Total Number of Iterations' :
'TNI',
82 'Average Number of Iterations' :
'ANI',
83 'Percentage of Success' :
'PS',
84 'Initial Configuration' :
'IC',
85 'Final Configuration' :
'FC',
88 'Number of Iterations-Total' :
'NI-tot',
89 'Number of Iterations-Maximum' :
'NI-max',
90 'Number of Iterations-Minimum' :
'NI-min',
91 'Number of Iterations-Average' :
'NI-avr',
92 'Number of Iterations-Standard Deviation' :
'NI-sdv',
93 'Number of Iterations-Mean Standard Error' :
'NI-mse',
94 'Number of Trials-Maximum' :
'NT-max',
95 'Number of Trials-Minimum' :
'NT-min',
96 'Number of Trials-Average' :
'NT-avr',
97 'Running Time-Total (ms)' :
'RT-tot',
98 'Running Time-Maximum (ms)' :
'RT-max',
99 'Running Time-Minimum (ms)' :
'RT-min',
100 'Running Time-Average (ms)' :
'RT-avr',
101 'Running Time-Standard Deviation (ms)' :
'RT-sdv',
102 'Running Time-Mean Standard Error' :
'RT-mse'
105 class Single_Run_Log():
107 Contains data structure for evaluation test results for a single run associated with a target pose in PPS
109 Initial Status (Configuration, Endeffector Pose, Values of error functions)
110 Final Status (Configuration, Endeffector Pose, Values of error functions)
114 def __init__(self, pose_number, success = False, config_in_range = False):
117 self.target_pose_num = pose_number
121 self.num_suc_til_now = 0
123 self.success = success
124 self.config_in_range = config_in_range
129 self.num_iter_til_now = 0
134 self.run_time_til_now = 0.0
136 self.mean_stp_time = 0.0
138 self.start_config_str =
''
139 self.final_config_str =
''
140 self.start_pose_str =
''
141 self.final_pose_str =
''
142 self.str_parameter_set = [
'TPN',
'S',
'CIR',
'NSPT',
'NI',
'RT',
'NS',
'TRT',
'ART',
'TNI',
'ANI',
'PS',
'IC',
'FC',
'IP',
'FP']
143 self.csv_parameter_set = [
'TPN',
'S',
'CIR',
'NSPT',
'NI',
'RT',
'NS',
'TRT',
'ART',
'TNI',
'ANI',
'PS']
145 def parameter_value(self, parameter):
146 if parameter ==
'TPN':
147 return str(self.target_pose_num)
148 elif parameter ==
'S':
149 return str(self.success)
150 elif parameter ==
'CIR':
151 return str(self.config_in_range)
152 elif parameter ==
'NSPT':
153 return str(self.num_trial)
154 elif parameter ==
'NI':
155 return str(self.num_iter)
156 elif parameter ==
'RT':
157 return str(1000*self.run_time)
158 elif parameter ==
'NS':
159 return str(self.num_suc_til_now)
160 elif parameter ==
'TRT':
161 return str(1000*self.run_time_til_now)
162 elif parameter ==
'ART':
163 return str(1000*self.run_time_til_now/(self.target_pose_num + 1))
164 elif parameter ==
'TNI':
165 return str(self.num_iter_til_now)
166 elif parameter ==
'ANI':
167 return str(self.num_iter_til_now/(self.target_pose_num + 1))
168 elif parameter ==
'PS':
169 return str(100.00*self.num_suc_til_now/(self.target_pose_num + 1))
170 elif parameter ==
'IC':
171 return self.start_config_str
172 elif parameter ==
'FC':
173 return self.final_config_str
174 elif parameter ==
'IP':
175 return '\n' +
'------------' +
'\n' + self.start_pose_str
176 elif parameter ==
'FP':
177 return '\n' +
'------------' +
'\n' + self.final_pose_str
179 def __str__(self, parameter_set = None):
180 if parameter_set ==
None:
181 parameter_set = self.str_parameter_set
183 s +=
'Test Result:' +
'\n\n'
184 for p
in parameter_set:
185 value = self.parameter_value(p)
187 s += param +
" "*(32-len(param)) +
': ' + value +
'\n'
189 s +=
'\n' +
'______________________________________________________________________________________________________________________________'
193 def csv(self, header = True, parameter_set = None):
194 if parameter_set ==
None:
195 parameter_set = self.csv_parameter_set
198 s =
'Parameter' +
',' +
'Value' +
'\n'
201 for p
in parameter_set:
202 value = self.parameter_value(p)
203 s += key_dic[p] +
"," + value +
'\n'
206 def csv_horizontal_header(self, parameter_set = None):
207 if parameter_set ==
None:
208 parameter_set = self.csv_parameter_set
210 for p
in parameter_set:
211 s += key_dic[p] +
","
215 def csv_horizontal(self, parameter_set = None):
216 if parameter_set ==
None:
217 parameter_set = self.csv_parameter_set
219 for p
in parameter_set:
220 s += self.parameter_value(p) +
','
225 def write_csv(self, filename):
226 print 'Test_Log_Data_Single_Run(): Writing csv file started ...'
227 CSV_FILE_HANDLE = open(filename,
"w")
228 CSV_FILE_HANDLE.write(self.csv())
229 print 'Test_Log_Data_Single_Run(): Writing csv file ended.'
231 class Test_Statistics():
233 Contains structure for statistical data of evaluation test results for a set of target poses
235 Initial Status (Configuration, Endeffector Pose, Values of error functions)
236 Final Status (Configuration, Endeffector Pose, Values of error functions)
243 self.num_suc_inrange = 0
246 self.sum_num_iter = 0
247 self.max_num_iter = 0
248 self.max_num_iter_pose_number = 0
249 self.min_num_iter = 1000000
250 self.min_num_iter_pose_number = 0
252 self.sum_num_trial = 0
253 self.max_num_trial = 0
254 self.max_num_trial_pose_number = 0
255 self.min_num_trial = 1000000
256 self.min_num_trial_pose_number = 0
258 self.max_run_time = 0.0
259 self.max_run_time_pose_number = 0
260 self.min_run_time = 1000000.00
261 self.min_run_time_pose_number = 0
262 self.sum_run_time = 0.0
264 self.mean_num_iter = 0.0
265 self.mean_num_trial = 0.0
266 self.mean_run_time = 0.0
267 self.mean_stp_time = 0.0
268 self.sd_num_iter = 0.0
269 self.sd_run_time = 0.0
270 self.mse_num_iter = 0.0
271 self.mse_run_time = 0.0
273 self.median_num_iter = 0.0
274 self.median_run_time = 0.0
276 self.str_parameter_set = [
'NRun',
'NSRun',
'NSIR',
'PS',
'NI-tot',
'NI-max',
'NI-min',
'NI-avr',
'NI-sdv',
'NI-mse',
277 'NT-max',
'NT-min',
'NT-avr',
'RT-tot',
'RT-max',
'RT-min',
'RT-avr',
'RT-mse']
278 self.csv_parameter_set = [
'PS',
'NI-avr',
'NI-mse',
'RT-max',
'RT-min',
'RT-avr',
'RT-mse']
280 def parameter_value(self, parameter):
281 if parameter ==
'NRun':
282 return str(self.num_run)
283 elif parameter ==
'NSRun':
284 return str(self.num_success)
285 elif parameter ==
'NSIR':
286 return str(self.num_suc_inrange)
287 elif parameter ==
'NIR':
288 return str(self.num_inrange)
289 elif parameter ==
'PS':
290 return vecmat.value_to_str(100*self.num_success/float(self.num_run))
291 elif parameter ==
'PSIR':
292 return vecmat.value_to_str(100*self.num_suc_inrange/float(self.num_run))
293 elif parameter ==
'NI-tot':
294 return str(self.sum_num_iter)
295 elif parameter ==
'NI-max':
297 return str(self.max_num_iter)
298 elif parameter ==
'NI-min':
300 return str(self.min_num_iter)
301 elif parameter ==
'NI-avr':
302 return vecmat.value_to_str(self.mean_num_iter)
303 elif parameter ==
'NI-med':
304 return vecmat.value_to_str(self.median_num_iter)
305 elif parameter ==
'NI-sdv':
306 return vecmat.value_to_str(self.sd_num_iter)
307 elif parameter ==
'NI-mse':
308 return vecmat.value_to_str(self.mse_num_iter)
309 elif parameter ==
'NT-max':
311 return vecmat.value_to_str(self.max_num_trial)
312 elif parameter ==
'NT-min':
314 return vecmat.value_to_str(self.min_num_trial)
315 elif parameter ==
'NT-avr':
316 return vecmat.value_to_str(self.mean_num_trial)
317 elif parameter ==
'RT-tot':
318 return vecmat.value_to_str(1000*self.sum_run_time)
319 elif parameter ==
'RT-max':
320 return vecmat.value_to_str(1000*self.max_run_time)
321 elif parameter ==
'RT-min':
322 return vecmat.value_to_str(1000*self.min_run_time)
323 elif parameter ==
'RT-avr':
324 return vecmat.value_to_str(1000*self.mean_run_time)
325 elif parameter ==
'RT-med':
326 return vecmat.value_to_str(1000*self.median_run_time)
327 elif parameter ==
'RT-sdv':
328 return vecmat.value_to_str(1000*self.sd_run_time)
329 elif parameter ==
'RT-mse':
330 return vecmat.value_to_str(1000*self.mse_run_time)
332 assert False, genpy.err_str(__name__, __class__.__name__,
'parameter_value', parameter +
' is an invalid value for parameter')
334 def __str__(self, parameter_set = None):
335 if parameter_set ==
None:
336 parameter_set = self.str_parameter_set
338 s +=
'Test Statistics:' +
'\n\n'
339 for p
in parameter_set:
340 value = self.parameter_value(p)
342 s += param +
" "*(40-len(param)) +
': ' + value +
'\n'
344 s +=
'\n' +
'______________________________________________________________________________________________________________________________'
348 def csv(self, header = True, parameter_set = None):
349 if parameter_set ==
None:
350 parameter_set = self.csv_parameter_set
352 s =
'Parameter' +
',' +
'Value' +
'\n'
355 for p
in parameter_set:
356 value = self.parameter_value(p)
357 s += key_dic[p] +
"," + value +
'\n'
360 def csv_horizontal_header(self, parameter_set = None, use_key = False):
361 if parameter_set ==
None:
362 parameter_set = self.csv_parameter_set
364 for p
in parameter_set:
368 s += key_dic[p] +
","
372 def csv_horizontal(self, parameter_set = None):
373 if parameter_set ==
None:
374 parameter_set = self.csv_parameter_set
376 for p
in parameter_set:
377 s += self.parameter_value(p) +
','
381 def write_csv(self, filename):
382 print 'Eval_Log_Data_Statistics(): Writing csv file started ...'
383 CSV_FILE_HANDLE = open(filename,
"w")
384 CSV_FILE_HANDLE.write(self.csv())
385 print 'Eval_Log_Data_Statistics(): Writing csv file ended.'
387 def calculate_statistics(self, body):
392 self.num_run = len(body)
397 for i
in range(0, self.num_run):
398 num_iter_list.append(body[i].num_iter)
399 num_trial_list.append(body[i].num_trial)
400 run_time_list.append(body[i].run_time)
402 self.sum_num_iter += body[i].num_iter
403 self.sum_num_trial += body[i].num_trial
404 self.sum_run_time += body[i].run_time
405 sum_stp_time += body[i].mean_stp_time
407 if body[i].num_iter > self.max_num_iter:
408 self.max_num_iter = body[i].num_iter
409 self.max_num_iter_pose_number = i
410 if body[i].num_iter < self.min_num_iter:
411 self.min_num_iter = body[i].num_iter
412 self.min_num_iter_pose_number = i
414 if body[i].num_trial > self.max_num_trial:
415 self.max_num_trial = body[i].num_trial
416 self.max_num_trial_pose_number = i
417 if body[i].num_trial < self.min_num_trial:
418 self.min_num_trial = body[i].num_trial
419 self.min_num_trial_pose_number = i
421 if body[i].run_time > self.max_run_time:
422 self.max_run_time = body[i].run_time
423 self.max_run_time_pose_number = i
424 if body[i].run_time < self.min_run_time:
425 self.min_run_time = body[i].run_time
426 self.min_run_time_pose_number = i
428 assert self.sum_run_time == body[self.num_run - 1].run_time_til_now
429 assert self.sum_num_iter == body[self.num_run - 1].num_iter_til_now
431 self.mean_num_iter = float(self.sum_num_iter) / self.num_run
432 self.mean_num_trial = float(self.sum_num_trial) / self.num_run
433 self.mean_run_time = self.sum_run_time / self.num_run
434 self.mean_stp_time = sum_stp_time / self.num_run
436 self.median_num_iter = statistics.median(num_iter_list)
437 self.median_run_time = statistics.median(run_time_list)
444 self.num_suc_inrange = 0
445 for i
in range(0, self.num_run):
447 sum_var_num_iter += (float(body[i].num_iter) - self.mean_num_iter) ** 2
448 sum_var_run_time += ( body[i].run_time - self.mean_run_time) ** 2
450 self.num_inrange += body[i].config_in_range
451 self.num_success += body[i].success
452 self.num_suc_inrange += (body[i].config_in_range
and body[i].success)
455 den = self.num_run - 1
459 var_num_iter = sum_var_num_iter / den
460 var_run_time = sum_var_run_time / den
462 self.sd_num_iter = math.sqrt(var_num_iter)
463 self.sd_run_time = math.sqrt(var_run_time)
464 self.mse_num_iter = self.sd_num_iter / math.sqrt(den)
465 self.mse_run_time = self.sd_run_time / math.sqrt(den)
467 assert self.num_success == body[self.num_run - 1].num_suc_til_now
471 Contains data structure for evaluation test results for a set of runs associated with multiple target poses
474 Test Settings (An instance of "Kinematic_Manager_Settings")
476 Log data for each configuration (A list of instances of "Run_Log")
478 Statistic Data (An instance of "Run_Log_Statistics")
481 def __init__(self, km_settings ):
482 self.header = km_settings
484 self.footer = Test_Statistics()
486 def write_log(self, filename):
487 print 'Test_Log(): Writing log file started ...'
488 LOG_FILE_HANDLE = open(filename,
"w")
489 LOG_FILE_HANDLE.write(str(self.header))
490 LOG_FILE_HANDLE.write(
"\n" +
"--------------------------------------------------------------------------------" +
"\n")
491 for body_log
in self.body:
492 LOG_FILE_HANDLE.write(str(body_log))
493 LOG_FILE_HANDLE.write(
"\n" +
"--------------------------------------------------------------------------------" +
"\n")
494 LOG_FILE_HANDLE.write(str(self.footer))
495 print 'Test_Log: Writing log file ended.'
497 def write_self(self, filename):
498 print 'Test_Log: Writing self file started ...'
499 SELF_FILE_HANDLE = open(filename,
"w")
500 pickle.dump(self, SELF_FILE_HANDLE)
501 print 'Test_Log: Writing self file ended.'
503 def write_csv(self, filename):
504 print 'Test_Log: Writing csv file started ...'
505 CSV_FILE_HANDLE = open(filename,
"w")
507 CSV_FILE_HANDLE.write(x.csv_horizontal_header() +
'\n')
509 CSV_FILE_HANDLE.write(x.csv_horizontal() +
'\n')
510 print 'Test_Log: Writing csv file ended.'