#NEWLINE# def crossEntOneIdx( Y , T , weights = None ) : #NEWLINE# #INDENT# eps = 1e-08 #NEWLINE# Y2 = Y . reshape ( ( Y . size / Y . shape [ ( - 1 ) ] ) , Y . shape [ ( - 1 ) ] ) #NEWLINE# T2 = T . reshape ( T . size ) #NEWLINE# E = 0.0 #NEWLINE# dEdY = np . zeros ( Y2 . shape , float ) #NEWLINE# if ( weights is None ) : #NEWLINE# #INDENT# for n in range ( 0 , Y . shape [ 0 ] ) : #NEWLINE# #INDENT# E += ( ( - np . log ( ( Y2 [ ( n , T2 [ n ] ) ] + eps ) ) ) + np . log ( ( 1 - Y2 [ ( n , ( T2 [ n ] + eps ) ) ] ) ) ) #NEWLINE# E += ( - np . sum ( np . log ( ( ( 1 - Y2 [ n , : ] ) + eps ) ) ) ) #NEWLINE# dEdY [ n , : ] = ( 1 / ( ( 1 - Y2 [ n ] ) + eps ) ) #NEWLINE# dEdY [ ( n , T2 [ n ] ) ] = ( ( - 1 ) / ( Y2 [ ( n , T2 [ n ] ) ] + eps ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# for n in range ( 0 , Y . shape [ 0 ] ) : #NEWLINE# #INDENT# E += ( ( ( - np . log ( ( Y2 [ ( n , T2 [ n ] ) ] + eps ) ) ) + np . log ( ( 1 - Y2 [ ( n , ( T2 [ n ] + eps ) ) ] ) ) ) * weights [ n ] ) #NEWLINE# E += ( ( - np . sum ( np . log ( ( ( 1 - Y2 [ n , : ] ) + eps ) ) ) ) * weights [ n ] ) #NEWLINE# dEdY [ n , : ] = ( ( 1 / ( ( 1 - Y2 [ n ] ) + eps ) ) * weights [ n ] ) #NEWLINE# dEdY [ ( n , T2 [ n ] ) ] = ( ( ( - 1 ) / ( Y2 [ ( n , T2 [ n ] ) ] + eps ) ) * weights [ n ] ) #NEWLINE# #UNINDENT# #UNINDENT# E /= Y2 . shape [ 0 ] #NEWLINE# dEdY /= Y2 . shape [ 0 ] #NEWLINE# dEdY = dEdY . reshape ( Y . shape ) #NEWLINE# return ( E , dEdY )