pub struct CDF<T: Ord> { /* private fields */ }
Expand description
Implementation of a cumulative distribution function.
Implementations
sourceimpl<T: Ord> CDF<T>
impl<T: Ord> CDF<T>
sourcepub fn from_pmf(entries: Vec<Entry<T>>) -> Self
pub fn from_pmf(entries: Vec<Entry<T>>) -> Self
Create CDF from given probability mass function (PMF). The PMF may contain duplicate values the probabilities of which are summed during generation of the CDF.
Arguments
pmf
- the PMF as a vector ofEntry
objects
sourcepub fn from_cdf<I: Iterator<Item = Entry<T>>>(entries: I) -> Self
pub fn from_cdf<I: Iterator<Item = Entry<T>>>(entries: I) -> Self
Create CDF from iterator. This can be used to replace the values of a CDF.
sourcepub fn sample(self, n: usize) -> Self
pub fn sample(self, n: usize) -> Self
Downsample CDF to n entries. Panics if n <= 1 and returns identity if n is greater than the number of entries.
sourcepub fn iter_mut(&mut self) -> IterMut<'_, Entry<T>>
pub fn iter_mut(&mut self) -> IterMut<'_, Entry<T>>
Mutable iterator over entries. This does not check for consistency. In other words, you should not change the order of the entries, nor the probabilities!
sourcepub fn iter_pmf(&self) -> CDFPMFIter<'_, T>
pub fn iter_pmf(&self) -> CDFPMFIter<'_, T>
Iterator over corresponding PMF.
sourcepub fn get(&self, value: &T) -> Option<LogProb>
pub fn get(&self, value: &T) -> Option<LogProb>
Get cumulative probability for a given value. If the value is not present, return the probability of the previous value. Complexity O(log n).
sourcepub fn get_pmf(&self, value: &T) -> Option<LogProb>
pub fn get_pmf(&self, value: &T) -> Option<LogProb>
Get probability (i.e. probability mass) for a given value. Complexity O(log n).
sourcepub fn total_prob(&self) -> LogProb
pub fn total_prob(&self) -> LogProb
Return total probability.
sourcepub fn credible_interval(&self, width: f64) -> Option<Range<&T>>
pub fn credible_interval(&self, width: f64) -> Option<Range<&T>>
Return w%-credible interval. The width w is a float between 0 and 1. Panics otherwise.
E.g. provide width=0.95
for the 95% credible interval.