From 19f7ba742a529fae933b494f317a648205e2a28d Mon Sep 17 00:00:00 2001 From: Jonathan J Lawlor Date: Sun, 19 Oct 2014 21:59:35 -0400 Subject: [PATCH] simplify implementation of cross entropy Changed the implementation to match the simpler flow of Entropy. This will also result in fewer operations. --- stat.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/stat.go b/stat.go index d16d5d4c..f5c12045 100644 --- a/stat.go +++ b/stat.go @@ -176,11 +176,9 @@ func CrossEntropy(p, q []float64) float64 { } var ce float64 for i, v := range p { - w := q[i] - if v == 0 && w == 0 { - continue + if v != 0 { + ce -= v * math.Log(q[i]) } - ce -= v * math.Log(w) } return ce }