Inspecting the source code of Accord.NET implementation it can be seen that ProbabilityMassFunction
works like this:
//...
return Special.Binomial(numberOfTrials, k) * Math.Pow(probability, k)
* Math.Pow(1 - probability, numberOfTrials - k);
In your case numberOfTrials
is 3779
and k
is 250
. Binomial function of 3779
over 250
is more than 10398, which seems too much for the double
data type (approximate range is up to a bit more than 10308). So you get Infinity
in the first multiplication term, which determines the final result here.
I'm not sure how Extreme.Numerics
implements that, but your results suggest that they do it in a more clever way. Also, sadly it doesn't seem that Accord.NET provides decimal
version of their interface.
This issue seems to have been fixed in the latest Accord.NET implementation. The implementation looks now as follows:
double log = Special.LogBinomial(numberOfTrials, k) + k * Math.Log(probability)
+ (numberOfTrials - k) * Math.Log(1 - probability);
return Math.Exp(log);