Commit 3830eaf5 authored by Romain Reuillon's avatar Romain Reuillon
Browse files

[Tool] fix: kl divergence

parent 15a731ca
Pipeline #1241 passed with stages
in 52 minutes and 34 seconds
...@@ -208,7 +208,7 @@ trait Stat { ...@@ -208,7 +208,7 @@ trait Stat {
def klDivergence(p1: Array[Double], p2: Array[Double]) = { def klDivergence(p1: Array[Double], p2: Array[Double]) = {
val s = (p1 zip p2). val s = (p1 zip p2).
filter { case (p1, p2) p1 == 0.0 || p2 == 0.0 }. filter { case (p1, p2) p1 != 0.0 && p2 != 0.0 }.
map { case (p1, p2) p1 * math.log(p1 / p2) }.sum map { case (p1, p2) p1 * math.log(p1 / p2) }.sum
s / math.log(2) s / math.log(2)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment