Commit 9d7a4826 authored by Romain Reuillon's avatar Romain Reuillon
Browse files

[Tool] fix: bug in proba distribution

parent 4a443f64
Pipeline #1251 passed with stages
in 44 minutes and 25 seconds
...@@ -215,18 +215,23 @@ trait Stat { ...@@ -215,18 +215,23 @@ trait Stat {
s / math.log(2) s / math.log(2)
} }
def probabilityDistribution(s: Seq[Double], classes: Int) = { def probabilityDistribution(s: Seq[Double], beans: Int) = {
val ssorted = s.sorted val ssorted = s.sorted
val smin = s.head val smin = ssorted.head
val smax = s.last val smax = ssorted.last
val step = (smax - smin) / classes val step = (smax - smin) / beans
@tailrec def recurse(hb: BigDecimal, ssorted: List[Double], distrib: List[Double]): List[Double] = @tailrec def recurse(lowBound: BigDecimal, ssorted: List[Double], beans: List[Int]): List[Int] = {
if (hb > smax) distrib.reverse val highBound = lowBound + step
else recurse(hb + step, ssorted.dropWhile(_ <= hb), ssorted.takeWhile(_ <= hb).size :: distrib) if (highBound >= smax) (ssorted.size :: beans).reverse
else {
def bean = ssorted.takeWhile(_ <= highBound).size
recurse(highBound, ssorted.dropWhile(_ <= highBound), bean :: beans)
}
}
val size = ssorted.size val size = ssorted.size
recurse(BigDecimal(smin) + step, ssorted.toList, List()).toSeq.map(_.toDouble / size) recurse(BigDecimal(smin), ssorted.toList, List()).map(_.toDouble / size)
} }
} }
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