Commit 4a443f64 authored by Romain Reuillon's avatar Romain Reuillon
Browse files

[Tools] enh: add probabilityDistribution function

parent 96ad78b2
Pipeline #1249 passed with stages
in 78 minutes and 45 seconds
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package org.openmole.tool.statistics package org.openmole.tool.statistics
import scala.annotation.tailrec
import scala.math._ import scala.math._
trait Stat { trait Stat {
...@@ -214,4 +215,18 @@ trait Stat { ...@@ -214,4 +215,18 @@ trait Stat {
s / math.log(2) s / math.log(2)
} }
def probabilityDistribution(s: Seq[Double], classes: Int) = {
val ssorted = s.sorted
val smin = s.head
val smax = s.last
val step = (smax - smin) / classes
@tailrec def recurse(hb: BigDecimal, ssorted: List[Double], distrib: List[Double]): List[Double] =
if (hb > smax) distrib.reverse
else recurse(hb + step, ssorted.dropWhile(_ <= hb), ssorted.takeWhile(_ <= hb).size :: distrib)
val size = ssorted.size
recurse(BigDecimal(smin) + step, ssorted.toList, List()).toSeq.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