#NEWLINE# def crossEntOne( Y , T , weights = None ) : #NEWLINE# #INDENT# eps = 1e-08 #NEWLINE# T = T . reshape ( Y . shape ) #NEWLINE# cost = ( ( ( - T ) * np . log ( ( Y + eps ) ) ) - ( ( 1 - T ) * np . log ( ( ( 1 - Y ) + eps ) ) ) ) #NEWLINE# dcost = ( ( ( - T ) / ( Y + eps ) ) + ( ( 1 - T ) / ( ( 1 - Y ) + eps ) ) ) #NEWLINE# if ( weights is not None ) : #NEWLINE# #INDENT# cost *= weights #NEWLINE# dcost *= weights . reshape ( weights . shape [ 0 ] , 1 ) #NEWLINE# #UNINDENT# if ( len ( Y . shape ) == 0 ) : #NEWLINE# #INDENT# E = cost #NEWLINE# dEdY = dcost #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# E = ( np . sum ( cost ) / float ( Y . size ) ) #NEWLINE# dEdY = ( dcost / float ( Y . size ) ) #NEWLINE# #UNINDENT# return ( E , dEdY )