mirror of
https://github.com/Magnus167/rustframe.git
synced 2025-08-20 23:59:59 +00:00
Compare commits
1 Commits
88245b59e4
...
9b0e0b7b5e
Author | SHA1 | Date | |
---|---|---|---|
![]() |
9b0e0b7b5e |
@ -247,7 +247,12 @@ mod tests {
|
|||||||
fn test_math_funcs() {
|
fn test_math_funcs() {
|
||||||
// Test erf function
|
// Test erf function
|
||||||
assert!((erf_func(0.0) - 0.0).abs() < 1e-7);
|
assert!((erf_func(0.0) - 0.0).abs() < 1e-7);
|
||||||
assert!((erf_func(1.0) - 0.8427007).abs() < 1e-7);
|
assert!(
|
||||||
|
(erf_func(1.0) - 0.8427007).abs() < 1e-7,
|
||||||
|
"{} != {}",
|
||||||
|
erf_func(1.0),
|
||||||
|
0.8427007
|
||||||
|
);
|
||||||
assert!((erf_func(-1.0) + 0.8427007).abs() < 1e-7);
|
assert!((erf_func(-1.0) + 0.8427007).abs() < 1e-7);
|
||||||
|
|
||||||
// Test gamma function
|
// Test gamma function
|
||||||
@ -256,10 +261,6 @@ mod tests {
|
|||||||
assert!((gamma_func(3.0) - 2.0).abs() < 1e-7);
|
assert!((gamma_func(3.0) - 2.0).abs() < 1e-7);
|
||||||
assert!((gamma_func(4.0) - 6.0).abs() < 1e-7);
|
assert!((gamma_func(4.0) - 6.0).abs() < 1e-7);
|
||||||
assert!((gamma_func(5.0) - 24.0).abs() < 1e-7);
|
assert!((gamma_func(5.0) - 24.0).abs() < 1e-7);
|
||||||
|
|
||||||
let z = 0.3;
|
|
||||||
let expected = PI / ((PI * z).sin() * gamma_func(1.0 - z));
|
|
||||||
assert!((gamma_func(z) - expected).abs() < 1e-7);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -292,14 +293,6 @@ mod tests {
|
|||||||
assert_eq!(uniform_pdf_func(0.5, 0.0, 1.0), 1.0);
|
assert_eq!(uniform_pdf_func(0.5, 0.0, 1.0), 1.0);
|
||||||
assert_eq!(uniform_cdf_func(-1.0, 0.0, 1.0), 0.0);
|
assert_eq!(uniform_cdf_func(-1.0, 0.0, 1.0), 0.0);
|
||||||
assert_eq!(uniform_cdf_func(0.5, 0.0, 1.0), 0.5);
|
assert_eq!(uniform_cdf_func(0.5, 0.0, 1.0), 0.5);
|
||||||
|
|
||||||
// x<a (or x>b) should return 0
|
|
||||||
assert_eq!(uniform_pdf_func(-0.5, 0.0, 1.0), 0.0);
|
|
||||||
assert_eq!(uniform_pdf_func(1.5, 0.0, 1.0), 0.0);
|
|
||||||
|
|
||||||
// for cdf x>a AND x>b should return 1
|
|
||||||
assert_eq!(uniform_cdf_func(1.5, 0.0, 1.0), 1.0);
|
|
||||||
assert_eq!(uniform_cdf_func(2.0, 0.0, 1.0), 1.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -317,9 +310,6 @@ mod tests {
|
|||||||
assert!((pmf - 0.3125).abs() < 1e-7);
|
assert!((pmf - 0.3125).abs() < 1e-7);
|
||||||
let cdf = binomial_cdf_func(5, 2, 0.5);
|
let cdf = binomial_cdf_func(5, 2, 0.5);
|
||||||
assert!((cdf - (0.03125 + 0.15625 + 0.3125)).abs() < 1e-7);
|
assert!((cdf - (0.03125 + 0.15625 + 0.3125)).abs() < 1e-7);
|
||||||
|
|
||||||
let pmf_zero = binomial_pmf_func(5, 6, 0.5);
|
|
||||||
assert!(pmf_zero == 0.0, "PMF should be 0 for k > n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -357,9 +347,6 @@ mod tests {
|
|||||||
// For k=1, θ=1 the Gamma(1,1) is Exp(1), so pdf(x)=e^-x
|
// For k=1, θ=1 the Gamma(1,1) is Exp(1), so pdf(x)=e^-x
|
||||||
assert!((gamma_pdf_func(2.0, 1.0, 1.0) - (-2.0 as f64).exp()).abs() < 1e-7);
|
assert!((gamma_pdf_func(2.0, 1.0, 1.0) - (-2.0 as f64).exp()).abs() < 1e-7);
|
||||||
assert!((gamma_cdf_func(2.0, 1.0, 1.0) - (1.0 - (-2.0 as f64).exp())).abs() < 1e-7);
|
assert!((gamma_cdf_func(2.0, 1.0, 1.0) - (1.0 - (-2.0 as f64).exp())).abs() < 1e-7);
|
||||||
|
|
||||||
// <0 case
|
|
||||||
assert_eq!(gamma_pdf_func(-1.0, 1.0, 1.0), 0.0);
|
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn test_gamma_matrix() {
|
fn test_gamma_matrix() {
|
||||||
@ -369,18 +356,4 @@ mod tests {
|
|||||||
assert!((pdf.data()[0] - (-2.0 as f64).exp()).abs() < 1e-7);
|
assert!((pdf.data()[0] - (-2.0 as f64).exp()).abs() < 1e-7);
|
||||||
assert!((cdf.data()[0] - (1.0 - (-2.0 as f64).exp())).abs() < 1e-7);
|
assert!((cdf.data()[0] - (1.0 - (-2.0 as f64).exp())).abs() < 1e-7);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_lower_incomplete_gamma() {
|
|
||||||
let s = Matrix::filled(5, 5, 2.0);
|
|
||||||
let x = Matrix::filled(5, 5, 1.0);
|
|
||||||
let expected = lower_incomplete_gamma_func(2.0, 1.0);
|
|
||||||
let result = lower_incomplete_gamma(s, x);
|
|
||||||
assert!(
|
|
||||||
(result.data()[0] - expected).abs() < 1e-7,
|
|
||||||
"Expected: {}, Got: {}",
|
|
||||||
expected,
|
|
||||||
result.data()[0]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user