Hi Shakeel!



 shakeel608:

man_loss_weighted = -(np.log(0.3116)*0.2 + np.log(0.3531)*0.2 + np.log(0.6909)*0.2 + np.log(0.6711)*0.33 + np.log(0.4617)*0.33 + np.log(0.3374)*0.33 + np.log(0.6077)*0.2 + np.log(0.4059)*0.2)/(0.2+0.33)
man_loss_weighted /=8



You have two errors in your computation of man_loss_weighted:
First you need to divide by the sum of the weights used for each
individual sample.*
Second, you have mixed up your class-0 and class-1 weights.
Here is the correct manual computation:
>>> -(np.log(0.3116)*0.333333 + np.log(0.3531)*0.333333 + np.log(0.6909)*0.333333 + np.log(0.6711)*0.2 + np.log(0.4617)*0.2 + np.log(0.3374)*0.2 + np.log(0.6077)*0.333333 + np.log(0.4059)*0.333333)/(0.333333 + 0.333333 + 0.333333 + 0.2 + 0.2 + 0.2 + 0.333333 + 0.333333)
0.784032260475451

*)  You have divided first by cl_wts[0] + cl_wts[1].  But you need
to divide by the actual weights used for each sample in the batch.
Suppose your batch contained only class-0 samples. In such a case
it wouldn’t wouldn’t make sense to use cl_wts[1] in the computation
at all.  Then you divide by 8.  But suppose that all of your weights
were 1.  You would first divide by the sum of those weights, which
would be 8, and then you would divide by 8 again, which would be
wrong.
Best.
K. Frank