Skip to content

Commit

Permalink
Fixing possible log of zero error
Browse files Browse the repository at this point in the history
  • Loading branch information
mnielsen committed May 21, 2014
1 parent 074671c commit affbb03
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions code/network2.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ class CrossEntropyCost:
@staticmethod
def fn(a, y):
"""Return the cost associated with an output ``a`` and desired output
``y``.
``y``. Note that the np.nan_to_num ensures that if the output
from the network is exactly right, then 0.0 will be returned,
rather than nan.
"""
return np.sum(-y*np.log(a)-(1-y)*np.log(1-a))
return np.nan_to_num(np.sum(-y*np.log(a)-(1-y)*np.log(1-a)))

@staticmethod
def delta(z, a, y):
Expand Down

0 comments on commit affbb03

Please sign in to comment.