#NEWLINE# def init_train_updates( self ) : #NEWLINE# #INDENT# network_input = self . variables . network_input #NEWLINE# network_output = self . variables . network_output #NEWLINE# inv_hessian = self . variables . inv_hessian #NEWLINE# prev_params = self . variables . prev_params #NEWLINE# prev_full_gradient = self . variables . prev_full_gradient #NEWLINE# params = list ( iter_parameters ( self ) ) #NEWLINE# param_vector = parameters2vector ( self ) #NEWLINE# gradients = T . grad ( self . variables . error_func , wrt = params ) #NEWLINE# full_gradient = T . concatenate ( [ grad . flatten ( ) for grad in gradients ] ) #NEWLINE# new_inv_hessian = ifelse ( T . eq ( self . variables . epoch , 1 ) , inv_hessian , self . update_function ( inv_hessian , ( param_vector - prev_params ) , ( full_gradient - prev_full_gradient ) ) ) #NEWLINE# param_delta = ( - new_inv_hessian . dot ( derphi ) ) #NEWLINE# def prediction( step ) : #NEWLINE# #INDENT# updated_params = ( param_vector + ( step * param_delta ) ) #NEWLINE# layer_input = network_input #NEWLINE# start_pos = 0 #NEWLINE# for layer in self . layers : #NEWLINE# #INDENT# for param in layer . parameters : #NEWLINE# #INDENT# end_pos = ( start_pos + param . size ) #NEWLINE# setattr ( layer , param . name . split ( '_' ) [ 0 ] , T . reshape ( updated_params [ start_pos : end_pos ] , param . shape ) ) #NEWLINE# start_pos = end_pos #NEWLINE# #UNINDENT# layer_input = layer . output ( layer_input ) #NEWLINE# #UNINDENT# return layer_input #NEWLINE# #UNINDENT# def phi( step ) : #NEWLINE# #INDENT# return self . error ( network_output , prediction ( step ) ) #NEWLINE# #UNINDENT# def derphi( step ) : #NEWLINE# #INDENT# error_func = self . error ( network_output , prediction ( step ) ) #NEWLINE# return T . grad ( error_func , wrt = step ) #NEWLINE# #UNINDENT# step = asfloat ( line_search ( phi , derphi ) ) #NEWLINE# updated_params = ( param_vector + ( step * param_delta ) ) #NEWLINE# updates = setup_parameter_updates ( params , updated_params ) #NEWLINE# updates . extend ( [ ( inv_hessian , new_inv_hessian ) , ( prev_params , param_vector ) , ( prev_full_gradient , full_gradient ) ] ) #NEWLINE# return updates