simplify implementation of cross entropy

Changed the implementation to match the simpler flow of Entropy.  This
will also result in fewer operations.
This commit is contained in:
Jonathan J Lawlor
2014-10-19 21:59:35 -04:00
parent 19ed9ad89b
commit 19f7ba742a

View File

@@ -176,11 +176,9 @@ func CrossEntropy(p, q []float64) float64 {
} }
var ce float64 var ce float64
for i, v := range p { for i, v := range p {
w := q[i] if v != 0 {
if v == 0 && w == 0 { ce -= v * math.Log(q[i])
continue
} }
ce -= v * math.Log(w)
} }
return ce return ce
} }