#NEWLINE# def after_batch( self , batch ) : #NEWLINE# #INDENT# gradient_norm = math . log ( self . main_loop . log . current_row [ self . log_record ] ) #NEWLINE# self . mean_gradient_norm = ( ( batch . decay_rate * self . mean_gradient_norm ) + ( ( 1 - self . decay_rate ) * gradient_norm ) ) #NEWLINE# self . mean_gradient_norm2 = ( ( self . decay_rate * self . mean_gradient_norm2 ) + ( ( 1 - self . decay_rate ) * ( gradient_norm ** 2 ) ) ) #NEWLINE# self . std_gradient_norm = ( ( self . mean_gradient_norm2 - ( self . mean_gradient_norm ** 2 ) ) ** 0.5 ) #NEWLINE# threshold = math . exp ( ( self . mean_gradient_norm + ( 1 * self . std_gradient_norm ) ) ) #NEWLINE# confidence = ( min ( self . burnin_period , self . main_loop . status [ 'iterations_done' ] ) / float ( self . burnin_period ) ) #NEWLINE# threshold = ( ( confidence * threshold ) + ( ( 1 - confidence ) * self . initial_threshold ) ) #NEWLINE# threshold = min ( threshold , ( 5 * self . initial_threshold ) ) #NEWLINE# self . clipping_rule . threshold . set_value ( threshold )