We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent affbb03 commit 8df450eCopy full SHA for 8df450e
code/network2.py
@@ -43,9 +43,11 @@ class CrossEntropyCost:
43
@staticmethod
44
def fn(a, y):
45
"""Return the cost associated with an output ``a`` and desired output
46
- ``y``. Note that the np.nan_to_num ensures that if the output
47
- from the network is exactly right, then 0.0 will be returned,
48
- rather than nan.
+ ``y``. Note that np.nan_to_num is used to ensure numerical
+ stability. In particular, if both ``a`` and ``y`` have a 1.0
+ in the same slot, then the expression (1-y)*np.log(1-a)
49
+ returns nan. The np.nan_to_num ensures that that is converted
50
+ to the correct value (0.0).
51
52
"""
53
return np.nan_to_num(np.sum(-y*np.log(a)-(1-y)*np.log(1-a)))
0 commit comments