def binary_cross_entropy_cost( outputs, targets, derivative=False, epsilon=1e-11 ):
    """
    The output signals should be in the range [0, 1]
    """
    # Prevent overflow
    outputs = np.clip(outputs, epsilon, 1 - epsilon)
    divisor = np.maximum(outputs * (1 - outputs), epsilon)
    
    if derivative:
        return (outputs - targets) / divisor
    else:
        return np.mean(-np.sum(targets * np.log( outputs ) + (1 - targets) * np.log(1 - outputs), axis=1))
def binary_cross_entropy_cost ( outputs , targets , derivative = False , epsilon = 1e-11 ) : outputs = np . clip ( outputs , epsilon , 1 - epsilon ) divisor = np . maximum ( outputs * ( 1 - outputs ) , epsilon ) if derivative : return ( outputs - targets ) / divisor else : return np . mean ( - np . sum ( targets * np . log ( outputs ) + ( 1 - targets ) * np . log ( 1 - outputs ) , axis = 1 ) )
The output signals should be in the range [0, 1]