mirror of
https://github.com/storytold/gridcraft.git
synced 2026-10-31 06:06:48 -06:00
Avoid overflow in t density normalization
This commit is contained in:
@@ -26,7 +26,7 @@ fn t_pdf(t: f64, v: f64) -> f64 {
|
||||
} else {
|
||||
ln_gamma(z + 0.5) - ln_gamma(z)
|
||||
};
|
||||
(log_gamma_ratio - 0.5 * (v * std::f64::consts::PI).ln() - (v + 1.0) / 2.0 * (t * t / v).ln_1p()).exp()
|
||||
(log_gamma_ratio - 0.5 * (v.ln() + std::f64::consts::PI.ln()) - (v + 1.0) / 2.0 * (t * t / v).ln_1p()).exp()
|
||||
}
|
||||
|
||||
/// t ≥ 0 with P(T > t) = q, q in (0, 0.5].
|
||||
|
||||
@@ -360,6 +360,7 @@ fn normal() {
|
||||
|
||||
#[test]
|
||||
fn t_chi_f() {
|
||||
close_tol(ev("T.DIST", vec![n(0.0), n(6e307), b(false)]), 0.3989422804, 1e-10);
|
||||
close_tol(ev("T.DIST", vec![n(60.0), n(1.0), b(true)]), 0.99469533, D7);
|
||||
close_tol(ev("T.DIST", vec![n(8.0), n(3.0), b(false)]), 0.00073691, 1e-5);
|
||||
close_tol(ev("T.DIST.2T", vec![n(1.959999998), n(60.0)]), 0.054644930, D7);
|
||||
|
||||
Reference in New Issue
Block a user