以下给出NaN,但应该给1.0,为什么?
breeze.stats.distributions.Binomial(10, 1.0).probabilityOf(10)
类似于Binomial(1, 0.0).probabilityOf(0)
答案 0 :(得分:1)
来自微风源。
case class Binomial(n: Int, p: Double)(implicit rand: RandBasis=Rand) extends DiscreteDistr[Int] with Moments[Double, Double] {
require(n > 0, "n must be positive!");
require(p >= 0.0, "p must be non-negative!");
def probabilityOf(k: Int) = exp(logProbabilityOf(k));
override def toString() = "Binomial(" + n + ", " + p + ")";
override def logProbabilityOf(k: Int) = {
require(n >= k);
require(k >= 0);
lgamma(n+1) - lgamma(k+1) - lgamma(n-k+1) + k * log(p) + (n-k) * log(1-p)
}
0的日志未定义。在第一个示例中,您的p为1,因此最终为log(1-p) = log(0) = undefined
,在第二个示例中为log(p) = log(0) = undefined
由于这些概率都应为1,我认为这是微风源代码中的错误