I searched the forum and found this thread, but it does not cover my question Two ways around -inf
From a Machine Learning class, week 3, I am getting -inf
when using log(0)
, which later turns into an NaN
. The NaN
results in no answer being given in a sum formula, so no scalar for J
(a cost function which is the result of matrix math).
Here is a test of my function
>> sigmoid([-100;0;100])
ans =
3.7201e-44
5.0000e-01
1.0000e+00
This is as expected. but the hypothesis requires ans = 1-sigmoid
>> 1-ans
ans =
1.00000
0.50000
0.00000
and the Log(0) gives -Inf
>> log(ans)
ans =
0.00000
-0.69315
-Inf
-Inf
rows do not add to the cost function, but the -Inf
carries through to NaN
, and I do not get a result. I cannot find any material on -Inf
, but am thinking there is a problem with my sigmoid function.
Can you provide any direction?