def average_results(self):
grouped_results = defaultdict(list)<EOL>for res in self.results:<EOL><INDENT>grouped_results[res.name].append(res)<EOL><DEDENT>averaged_results = dict()<EOL>for name, result_list in grouped_results.items():<EOL><INDENT>newres = OptimizeResult()<EOL>newres.name = name<EOL>newres.mean_nfev = np.mean([r.nfev for r in result_list])<EOL>newres.mean_njev = np.mean([r.njev for r in result_list])<EOL>newres.mean_nhev = np.mean([r.nhev for r in result_list])<EOL>newres.mean_time = np.mean([r.time for r in result_list])<EOL>newres.ntrials = len(result_list)<EOL>newres.nfail = len([r for r in result_list if not r.success])<EOL>try:<EOL><INDENT>newres.ndim = len(result_list[<NUM_LIT:0>].x)<EOL><DEDENT>except TypeError:<EOL><INDENT>newres.ndim = <NUM_LIT:1><EOL><DEDENT>averaged_results[name] = newres<EOL><DEDENT>return averaged_results.values()<EOL>
group the results by minimizer and average over the runs