Revert back.

This commit is contained in:
2018-10-24 07:11:38 +02:00
parent 9cf91fbdf8
commit b39c446b37
5 changed files with 112 additions and 137 deletions

View File

@@ -1,30 +1,20 @@
use std::f64;
fn erfc(x: f64) -> f64 {
let z = x.abs();
let t = 1.0 / (1.0 + z / 2.0);
let r = t
* (-z * z - 1.26551223
+ t * (1.00002368
+ t * (0.37409196
+ t * (0.09678418
+ t * (-0.18628806
+ t * (0.27886807
+ t * (-1.13520398
+ t * (1.48851587 + t * (-0.82215223 + t * 0.17087277)))))))))
.exp();
if x < 0.0 {
2.0 - r
} else {
r
}
}
use statrs::distribution::{Normal, Univariate, Continuous};
pub fn cdf(x: f64) -> f64 {
0.5 * erfc(-x / 2.0f64.sqrt())
Normal::new(0.0, 1.0).unwrap().cdf(x)
}
pub fn pdf(x: f64) -> f64 {
1.0 / (2.0 * f64::consts::PI).sqrt() * (-((x / 1.0).powi(2) / 2.0)).exp()
Normal::new(0.0, 1.0).unwrap().pdf(x)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_cdf() {
assert_eq!(cdf(0.5), 0.6914624612740131);
}
}