#NEWLINE# def check_forward( self , x_data , t_data , use_cudnn = True ) : #NEWLINE# #INDENT# x_val = chainer . Variable ( x_data ) #NEWLINE# t_val = chainer . Variable ( t_data ) #NEWLINE# loss = functions . sigmoid_cross_entropy ( x_val , t_val , use_cudnn , self . normalize ) #NEWLINE# self . assertEqual ( loss . data . shape , ( ) ) #NEWLINE# self . assertEqual ( loss . data . dtype , numpy . float32 ) #NEWLINE# loss_value = float ( cuda . to_cpu ( loss . data ) ) #NEWLINE# loss_expect = 0 #NEWLINE# if ( not getattr ( self , 'ignore_all' , False ) ) : #NEWLINE# #INDENT# non_ignore_count = 0 #NEWLINE# for i in six . moves . range ( self . x . shape [ 0 ] ) : #NEWLINE# #INDENT# for j in six . moves . range ( self . x . shape [ 1 ] ) : #NEWLINE# #INDENT# ( xd , td ) = ( self . x [ ( i , j ) ] , self . t [ ( i , j ) ] ) #NEWLINE# if ( td == ( - 1 ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# loss_expect -= ( ( xd * ( td - ( xd >= 0 ) ) ) - math . log ( ( 1 + math . exp ( ( - numpy . abs ( xd ) ) ) ) ) ) #NEWLINE# non_ignore_count += 1 #NEWLINE# #UNINDENT# #UNINDENT# if self . normalize : #NEWLINE# #INDENT# loss_expect /= non_ignore_count #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# loss_expect /= self . t . shape [ 0 ] #NEWLINE# #UNINDENT# #UNINDENT# self . assertAlmostEqual ( loss_expect , loss_value , places = 5 )