Additional modification to softmax

This commit is contained in:
AntreasAntoniou 2017-11-14 18:48:54 +00:00
parent 5769d7c1f0
commit d48cb9214c

View File

@ -155,7 +155,7 @@ class CrossEntropySoftmaxError(object):
Scalar error function value.
"""
normOutputs = outputs - outputs.max(-1)[:, None]
logProb = normOutputs - np.log(np.sum(np.exp(normOutputs)))
logProb = normOutputs - np.log(np.sum(np.exp(normOutputs), axis=-1)[:, None])
return -np.mean(np.sum(targets * logProb, axis=1))
def grad(self, outputs, targets):