#NEWLINE# def run( self ) : #NEWLINE# #INDENT# best_valid_error = float ( sys . maxint ) #NEWLINE# valid_error = float ( sys . maxint ) #NEWLINE# train_cost = float ( sys . maxint ) #NEWLINE# valid_cost = float ( sys . maxint ) #NEWLINE# train_stats_values = [ ] #NEWLINE# valid_stats_values = [ ] #NEWLINE# epoch = 0 #NEWLINE# error_dcr = 0 #NEWLINE# self . best_epoch_last_update = 0 #NEWLINE# self . best_valid_last_update = float ( sys . maxint ) #NEWLINE# train_stats_names = [ ( 'train_' + name ) for name in self . train_stats_names ] #NEWLINE# valid_stats_names = [ ( 'valid_' + name ) for name in self . test_stats_names ] #NEWLINE# job_start = time . time ( ) #NEWLINE# while self . continue_learning ( epoch , error_dcr , best_valid_error ) : #NEWLINE# #INDENT# if ( epoch > 0 ) : #NEWLINE# #INDENT# self . log . info ( ( 'best_epoch_last_update: %d' % self . best_epoch_last_update ) ) #NEWLINE# self . log . info ( ( 'valid_error_decrease: %f' % error_dcr ) ) #NEWLINE# self . log . info ( ( 'best_valid_last_update: %f' % self . best_valid_last_update ) ) #NEWLINE# self . log . info ( '========[ End of Epoch ]========\n\n' ) #NEWLINE# #UNINDENT# epoch += 1 #NEWLINE# start_time = time . time ( ) #NEWLINE# num_train_examples = 0 #NEWLINE# total_train_cost = 0.0 #NEWLINE# train_stats_values = np . zeros ( len ( train_stats_names ) , dtype = floatX ) #NEWLINE# num_valid_examples = 0 #NEWLINE# total_valid_cost = 0.0 #NEWLINE# total_valid_stopping_cost = 0.0 #NEWLINE# valid_stats_values = np . zeros ( len ( valid_stats_names ) , dtype = floatX ) #NEWLINE# blk = 0 #NEWLINE# for block in self . dataset : #NEWLINE# #INDENT# block_time = time . time ( ) #NEWLINE# blk += 1 #NEWLINE# train_set = block . get_train ( ) #NEWLINE# valid_set = block . get_valid ( ) #NEWLINE# if ( train_set . dataset_size > 0 ) : #NEWLINE# #INDENT# self . log . info ( ( ( '..training ' + self . dataset . __class__ . __name__ ) + ( ' block %s/%s' % ( blk , self . dataset . nblocks ) ) ) ) #NEWLINE# progbar = Progbar ( target = train_set . dataset_size ) #NEWLINE# blk_sz = 0 #NEWLINE# for idx in train_set : #NEWLINE# #INDENT# cost = self . training ( * train_set [ idx ] ) #NEWLINE# total_train_cost += ( cost * len ( idx ) ) #NEWLINE# num_train_examples += len ( idx ) #NEWLINE# train_stats_values += ( len ( idx ) * get_shared_values ( self . train_stats_shared ) ) #NEWLINE# blk_sz += len ( idx ) #NEWLINE# progbar . update ( blk_sz ) #NEWLINE# #UNINDENT# print #NEWLINE# #UNINDENT# if ( valid_set . dataset_size > 0 ) : #NEWLINE# #INDENT# self . log . info ( ( ( '..validating ' + self . dataset . __class__ . __name__ ) + ( ' block %s/%s' % ( blk , self . dataset . nblocks ) ) ) ) #NEWLINE# progbar = Progbar ( target = valid_set . dataset_size ) #NEWLINE# blk_sz = 0 #NEWLINE# for idx in valid_set : #NEWLINE# #INDENT# ( stopping_cost , cost ) = self . testing ( * valid_set [ idx ] ) #NEWLINE# total_valid_cost += ( cost * len ( idx ) ) #NEWLINE# total_valid_stopping_cost += ( stopping_cost * len ( idx ) ) #NEWLINE# num_valid_examples += len ( idx ) #NEWLINE# valid_stats_values += ( len ( idx ) * get_shared_values ( self . test_stats_shared ) ) #NEWLINE# blk_sz += len ( idx ) #NEWLINE# progbar . update ( blk_sz ) #NEWLINE# #UNINDENT# print #NEWLINE# #UNINDENT# self . log . info ( ( 'block time: %0.2fs' % ( time . time ( ) - block_time ) ) ) #NEWLINE# self . log . info ( get_mem_usage ( ) ) #NEWLINE# #UNINDENT# if ( num_train_examples > 0 ) : #NEWLINE# #INDENT# train_cost = ( total_train_cost / num_train_examples ) #NEWLINE# train_stats_values /= num_train_examples #NEWLINE# #UNINDENT# if ( num_valid_examples > 0 ) : #NEWLINE# #INDENT# valid_error = ( total_valid_stopping_cost / num_valid_examples ) #NEWLINE# valid_cost = ( total_valid_cost / num_valid_examples ) #NEWLINE# valid_stats_values /= num_valid_examples #NEWLINE# if ( valid_error < best_valid_error ) : #NEWLINE# #INDENT# best_valid_error = valid_error #NEWLINE# self . log . info ( '..best validation error so far' ) #NEWLINE# if self . log . save_model : #NEWLINE# #INDENT# self . log . _save_model ( self . model ) #NEWLINE# self . log . info ( '..model saved' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( valid_error < self . best_valid_last_update ) : #NEWLINE# #INDENT# error_dcr = ( self . best_valid_last_update - valid_error ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# error_dcr = 0 #NEWLINE# #UNINDENT# #UNINDENT# if self . log . save_to_database : #NEWLINE# #INDENT# self . log . _save_to_database ( epoch , train_cost , valid_error , best_valid_error ) #NEWLINE# self . log . info ( ( '..sent to database: %s:%s' % ( self . log . save_to_database [ 'name' ] , self . log . experiment_name ) ) ) #NEWLINE# #UNINDENT# if self . log . save_epoch_error : #NEWLINE# #INDENT# self . log . _save_epoch_error ( epoch , train_cost , valid_cost , valid_error ) #NEWLINE# self . log . info ( '..epoch error saved' ) #NEWLINE# #UNINDENT# end_time = time . time ( ) #NEWLINE# merged_train = merge_lists ( train_stats_names , train_stats_values ) #NEWLINE# merged_valid = merge_lists ( valid_stats_names , valid_stats_values ) #NEWLINE# outputs = [ ( 'epoch' , epoch ) , ( 'runtime(s)' , int ( ( end_time - start_time ) ) ) , ( ( 'train_' + self . train_cost . func_name ) , train_cost ) , ( ( 'valid_' + self . train_cost . func_name ) , valid_cost ) , ( ( 'valid_' + self . valid_cost . func_name ) , valid_error ) , ( ( 'best_valid_' + self . valid_cost . func_name ) , best_valid_error ) ] #NEWLINE# outputs += ( merged_train + merged_valid ) #NEWLINE# self . log . _log_outputs ( outputs ) #NEWLINE# #UNINDENT# job_end = time . time ( ) #NEWLINE# self . log . info ( ( 'Job Completed on %s' % time . strftime ( '%a, %d %b %Y %H:%M:%S' , time . gmtime ( job_end ) ) ) ) #NEWLINE# ttl_time = int ( ( job_end - job_start ) ) #NEWLINE# dt = datetime . timedelta ( seconds = ttl_time ) #NEWLINE# self . log . info ( ( 'Total Time Taken: %s' % str ( dt ) ) ) #NEWLINE# self . log . info ( '========[ End of Job ]========\n\n' )