class BCELoss:
def forward(self, y, pred):
J = -(y*np.log(pred)+(1-y)*np.log(1-pred))
return J
preds = np.arange(start = 0.1, stop = 1, step = 0.1)
print("case1) y= 1")
loss1 = BCELoss()
print(loss1.forward(1, preds))
print("case2) y = 0")
loss2 = BCELoss()
print(loss2.forward(0, preds))
========================================================
case1) y= 1
[2.30258509 1.60943791 1.2039728 0.91629073 0.69314718 0.51082562
0.35667494 0.22314355 0.10536052]
case2) y = 0
[0.10536052 0.22314355 0.35667494 0.51082562 0.69314718 0.91629073
1.2039728 1.60943791 2.30258509]