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