-
Notifications
You must be signed in to change notification settings - Fork 103
Description
Hello,
First of all thanks a lot for the work on statrs, it is very nice to have such a library in rust !
I know computing some of the statistics are hard computational problems (as in dealing with floating point precision and writing the proper algorithms matching theoretical maths formulas).
I would like to report the following case which fails :
use statrs::distribution::{ChiSquared, ContinuousCDF};
pub fn main() {
let alpha = 0.01;
let df = 129757f64;
let chi2 = ChiSquared::new(df).unwrap();
let chi2_lower = chi2.inverse_cdf(alpha / 2.0);
let chi2_upper = chi2.inverse_cdf(1.0 - alpha / 2.0);
if !(chi2_lower.is_finite() && chi2_upper.is_finite()) {
dbg!(chi2_lower);
dbg!(chi2_upper);
panic!("{df}");
}
}I am aware these values are extreme, chi2_upper produces a NaN.
I prefer reporting it because the function docstring does not indicate the possibility to encounter NaNs and other software like scipy will give a finite answer.
It's now possible to use scipy's special functions in rust using the wrapper around their xsf library :
- xsf library from scipy (c++) : https://github.com/scipy/xsf/
- wrapper : https://github.com/jorenham/xsf-rust
It may be of interest to you for testing purposes.
I still think having rust code able to compute special math functions has value (to avoid dependency on a C++ compiler or tooling), I have no idea what the best course of action for statrs is.
I know there are other combinations of parameters which will make the inverse CDF fail for the ChiSquared distribution.
Cheers