#NEWLINE# def train( dataset_x , dataset_y , model , optimiser , criterion , epoch , batch_size , mode = 'train' ) : #NEWLINE# #INDENT# progress = make_progressbar ( 'Training ({}) epoch #{}' . format ( mode , epoch ) , len ( dataset_x ) ) #NEWLINE# progress . start ( ) #NEWLINE# shuffle = np . random . permutation ( len ( dataset_x ) ) #NEWLINE# for j in range ( ( dataset_x . shape [ 0 ] // batch_size ) ) : #NEWLINE# #INDENT# indices = shuffle [ ( j * batch_size ) : ( ( j + 1 ) * batch_size ) ] #NEWLINE# mini_batch_input = dataset_x [ indices ] . astype ( th . config . floatX ) #NEWLINE# mini_batch_targets = dataset_y [ indices ] . astype ( th . config . floatX ) #NEWLINE# if ( mode == 'train' ) : #NEWLINE# #INDENT# model . zero_grad_parameters ( ) #NEWLINE# model . accumulate_gradients ( mini_batch_input , mini_batch_targets , criterion ) #NEWLINE# optimiser . update_parameters ( model ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( mode == 'stats' ) : #NEWLINE# #INDENT# model . accumulate_statistics ( mini_batch_input ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# assert False , "Mode should be either 'train' or 'stats'" #NEWLINE# #UNINDENT# #UNINDENT# progress . update ( ( ( j * batch_size ) + len ( mini_batch_input ) ) ) #NEWLINE# #UNINDENT# progress . finish ( )