0

没有标准库函数可以做到这一点。我怎样才能有效地做到这一点?

4

2 回答 2

3

Scala Breeze,http: //www.scalanlp.org/ 在其 stats.distributions 包中有一个 Poisson 类。

case class Poisson(mean: Double)(implicit rand: RandBasis = Rand)
于 2013-04-22T21:48:23.110 回答
0

我将这个答案翻译成 Scala:

def recursive_poisson_helper(m:Long, r:Long, p:Double, i:Long):Double = {
  if (r == i) {
    p
  } else {
    recursive_poisson_helper(m, r, (p * m) / (i + 1), i + 1)
  }
}

def efficient_poisson(m:Long, r:Long): Double = {
  val p = math.exp(-m)
  recursive_poisson_helper(m, r, p, 0)
}
于 2013-04-22T20:03:25.060 回答