Add `cdf` for `RNG`
@@ -200,6 +200,12 @@ pub trait RNG {
/// # Type
/// `f64 -> f64`
fn pdf<S: PartialOrd + SampleUniform + Copy + Into<f64>>(&self, x: S) -> f64;
+
+ /// Cumulative Distribution Function
+ ///
+ /// # Type
+ /// `f64` -> `f64`
+ fn cdf<S: PartialOrd + SampleUniform + Copy + Into<f64>>(&self, x: S) -> f64;
}
/// RNG for OPDist
@@ -249,6 +255,24 @@ impl<T: PartialOrd + SampleUniform + Copy + Into<f64>> RNG for OPDist<T> {
}
}
}
+
+ fn cdf<S: PartialOrd + SampleUniform + Copy + Into<f64>>(&self, x: S) -> f64 {
+ match self {
+ Bernoulli(prob) => {
+ let k: f64 = x.into();
+ if k < 0f64 {
+ 0f64
+ } else if k < 1f64 {
+ 1f64 - (*prob).into()
+ } else {
+ 1f64
+ }
+ }
+ StudentT(nu) => {
+ unimplemented!()
+ }
+ }
+ }
}
/// RNG for TPDist
@@ -377,6 +401,10 @@ impl<T: PartialOrd + SampleUniform + Copy + Into<f64>> RNG for TPDist<T> {
}
}
}
+
+ fn cdf<S: PartialOrd + SampleUniform + Copy + Into<f64>>(&self, x: S) -> f64 {
+ unimplemented!()
+ }
}
impl<T: PartialOrd + SampleUniform + Copy + Into<f64>> Statistics for OPDist<T> {
