Closed DoganCK closed 1 year ago
This happens because of floating point errors. The PDF is defined as:
PDF(x) = (x * (alpha - 1.0)) ((1.0 - x) ** (beta - 1.0)) / (SpecialFunctions.Beta._beta alpha beta)
The first factor: 0.5599 already returns 0.0. The maximal exponent to get a valid result is 0.5248 resulting in 1.976262583e-323.
Either the variables must be converted from float to decimal to facilitate the calculation with such extreme values, or there is an alternative algorithm to determine the PDF without the need for these extreme values.
https://www.itl.nist.gov/div898/handbook/eda/section3/eda366h.htm
I've transformed the PDF
to its corresponding PDFLn
and updated the density estimation with a switch for high alpha/beta parameters.
The function is tested for alpha/beta <= 2000 but should handle values way above this.
(beta 600. 600.).PDF 0.5 // F#Stats 27.63377432
Describe the bug Beta distribution PDF returns
nan
after a threshold when it should not.To Reproduce Steps to reproduce the behavior:
Expected behavior Similar results with MathNet. They resort to LogPDF when either one of the params is greater than 80.
OS and framework information (please complete the following information):