From c33643d57e919c1baf6eae4ac50a94b6b2310f47 Mon Sep 17 00:00:00 2001 From: gospodnetic <petra.gospodnetic@gmail.com> Date: Fri, 5 Jun 2020 12:44:32 +0200 Subject: [PATCH] Add average discarded per approach computation --- Benchmark.py | 36 ++++++++++++++++++++++++++++++++++++ Log.py | 4 ++++ LogContainer.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ vob.py | 2 ++ 4 files changed, 87 insertions(+) diff --git a/Benchmark.py b/Benchmark.py index 41edbe9..4f90bc8 100644 --- a/Benchmark.py +++ b/Benchmark.py @@ -1,5 +1,8 @@ import utilities as util +from LogContainer import LogContainer + +import numpy as np class Benchmark: def __init__(self): @@ -73,3 +76,36 @@ class Benchmark: tex_file.write("\n\\end{tabular}") tex_file.write("\n\\end{table*}\n") tex_file.close() + + # Average ray tracing duration. + def get_average_RT_duration_per_model(self): + avgs = {} + for model in self.log_container_per_model: + avgs.update( + { + model: self.log_container_per_model[model].get_avg_RT_duration() + }) + return avgs + + def get_average_discarded_per_approach(self): + discarded_per_approach_list = {} + for approach in self.methods_per_approach: + for model in self.log_container_per_model: + log_container = LogContainer(self.log_container_per_model[model].get_methods_per_approach()) + log_container.add_logs(self.log_container_per_model[model].get_logs_by_approach(approach)) + if log_container.size() == 0: + continue + + container_avg = log_container.get_avg_discarded() + if approach in discarded_per_approach_list: + discarded_per_approach_list[approach].append(container_avg) + else: + discarded_per_approach_list[approach] = [container_avg] + + discarded_per_approach = {} + for approach in discarded_per_approach_list: + discarded_per_approach[approach] = np.sum(discarded_per_approach_list[approach]) / len(discarded_per_approach_list[approach]) + + print("discarded_per_approach: {}".format(discarded_per_approach)) + return discarded_per_approach + diff --git a/Log.py b/Log.py index 362709d..bfabda4 100644 --- a/Log.py +++ b/Log.py @@ -240,6 +240,10 @@ class Log: def get_cumulative_triangle_per_vp(self): return self.convert_cumulative(self.optimization["triangle_per_vp"]) + def get_discarded_quotient(self): + total_VPC = self.VPC["count"] + self.VPC["discarded_count"] + return self.VPC["discarded_count"] / total_VPC + # Utilities def convert_cumulative(self, value_array): cumulative_array = [] diff --git a/LogContainer.py b/LogContainer.py index 9db4a20..b9e835f 100644 --- a/LogContainer.py +++ b/LogContainer.py @@ -14,6 +14,9 @@ class LogContainer: self.__parse_methods_per_approach() + def size(self): + return len(self.logs) + def add_log(self, log): method = log.VPC["method"] if method in self.approaches_per_method: @@ -21,11 +24,28 @@ class LogContainer: else: raise Exception("Error: method '{}' has not been specified and is not known which approach does it belong to.".format(method)) + self.logs.append(log) + if approach in self.logs_per_approach: self.logs_per_approach[approach].append(log) else: self.logs_per_approach[approach] = [log] + def add_logs(self, input_logs): + for log in input_logs: + method = log.VPC["method"] + if method in self.approaches_per_method: + approach = self.approaches_per_method[method] + else: + raise Exception("Error: method '{}' has not been specified and is not known which approach does it belong to.".format(method)) + + self.logs.append(log) + + if approach in self.logs_per_approach: + self.logs_per_approach[approach].append(log) + else: + self.logs_per_approach[approach] = [log] + def print_status(self): for approach in self.logs_per_approach: print("Approach '{}' has {} logs".format(approach, len(self.logs_per_approach[approach]))) @@ -35,6 +55,9 @@ class LogContainer: print("Methods per approach:") pp.pprint (self.methods_per_approach) + def get_methods_per_approach(self): + return self.methods_per_approach + def get_logs_by_method(self, method): approach = self.approaches_per_method[method] if approach not in self.logs_per_approach: @@ -47,6 +70,11 @@ class LogContainer: return method_logs + def get_logs_by_approach(self, approach): + if approach in self.logs_per_approach: + return self.logs_per_approach[approach] + return [] + # Log which obtains coverage over 99% with minimal number of viewpoint candidates # If no log obrains coverage over 99%, the log with the greatest coverage is considered. def get_best_log(self, method): @@ -62,6 +90,23 @@ class LogContainer: else: return self.max_coverage_log(method_logs) + def get_avg_RT_duration(self): + if len(self.logs) == 0: + return 0 + + summed_per_vp_duration = 0 + for log in self.logs: + if log.VPC["count"] == 0: + continue + summed_per_vp_duration += log.timing["visibility_matrix_sec"] / log.VPC["count"] + return summed_per_vp_duration / len(self.logs) + + def get_avg_discarded(self): + discarded_sum = 0 + for log in self.logs: + discarded_sum += log.get_discarded_quotient() + return discarded_sum / len(self.logs) + def max_coverage_log(self, input_logs=None): if not input_logs: input_logs = self.logs diff --git a/vob.py b/vob.py index e139410..775cbcf 100644 --- a/vob.py +++ b/vob.py @@ -59,6 +59,8 @@ def main(): benchmark = Benchmark() benchmark.set_log_containers(log_container_per_model) benchmark.generate_tex_table() + benchmark.get_average_RT_duration_per_model() + benchmark.get_average_discarded_per_approach() if __name__ == "__main__": -- GitLab