#NEWLINE# def binary_crossentropy( output , target ) : #NEWLINE# #INDENT# '\n    Compute the crossentropy of binary random variables.\n\n    Output and target are each expectations of binary random\n    variables; target may be exactly 0 or 1 but output must\n    lie strictly between 0 and 1.\n\n    Notes\n    -----\n    We could use the x log y op to support output=0 and output=1.\n    The gradient would still be undefined though.\n\n    We do not sum, crossentropy is computed by component.\n    TODO : Rewrite as a scalar, and then broadcast to tensor.\n\n    ' #NEWLINE# return ( - ( ( target * tensor . log ( output ) ) + ( ( 1.0 - target ) * tensor . log ( ( 1.0 - target ) ) ) ) )