From the Keras source code, this is the definition of the BinaryCrossentropy() for the Numpy backend and the plot of the loss function for the values around logit 0 in both directions (appoaching to it from the sides):
import numpy as np
def sigmoid(x):
return 1. / (1. + np.exp(-x))
def binary_crossentropy(target, output, from_logits=False):
if not from_logits:
output = np.clip(output, 1e-7, 1 - 1e-7)
output = np.log(output / (1 - output))
return (target * -np.log(sigmoid(output)) +
(1 - target) * -np.log(1 - sigmoid(output)))
loss = binary_crossentropy(np.array([-1,-.5,-.1,0,.1,.5,1]), np.array([1,.5,.1,0,-.1,-.5,-1]), from_logits=True)
plt.plot(loss)
Could anyone help with understanding why the minimum of the loss function is at point 4 (0.1, -0.1)
instead of 3 (0.0, 0.0)
when both prediction and target values are the same?