Skip to content

Commit

Permalink
feat: default implementation of surival function with generics
Browse files Browse the repository at this point in the history
  • Loading branch information
henryjac authored and YeungOnion committed Apr 17, 2024
1 parent f25de9a commit 018bb70
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/distribution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ pub trait ContinuousCDF<K: Float, T: Float>: Min<K> + Max<K> {
/// let n = Uniform::new(0.0, 1.0).unwrap();
/// assert_eq!(0.5, n.sf(0.5));
/// ```
fn sf(&self, x: K) -> T;
fn sf(&self, x: K) -> T {
T::one() - self.cdf(x)
}

/// Due to issues with rounding and floating-point accuracy the default
/// implementation may be ill-behaved.
Expand Down Expand Up @@ -167,7 +169,9 @@ pub trait DiscreteCDF<K: Bounded + Clone + Num, T: Float>: Min<K> + Max<K> {
/// let n = DiscreteUniform::new(1, 10).unwrap();
/// assert_eq!(0.4, n.sf(6));
/// ```
fn sf(&self, x: K) -> T;
fn sf(&self, x: K) -> T {
T::one() - self.cdf(x)
}

/// Due to issues with rounding and floating-point accuracy the default implementation may be ill-behaved
/// Specialized inverse cdfs should be used whenever possible.
Expand Down

0 comments on commit 018bb70

Please sign in to comment.