pub struct CDF<T: Ord> { /* private fields */ }
Expand description
Implementation of a cumulative distribution function as a vector of Entry
s.
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 a vector representing a probability mass function (PMF). The PMF may contain duplicate values the probabilities of which are summed during generation of the CDF.
Runtime complexity: O(n log n), where n is the number of entries
.
Arguments
entries
- The PMF as a vector ofEntry
objects (values with an associatedLogProb
).
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.
Runtime complexity: O(n), where n is the number of entries
.
Arguments
entries
- An iterator overEntry<T>
values, where T requires
sourcepub fn reduce(self) -> Self
pub fn reduce(self) -> Self
Reduce CDF by omitting values with zero probability.
Runtime complexity: O(n), where n is the number of value
s with prob
of zero.
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.
Runtime complexity: O(m), where m is the original number of Entry
s in CDF
.
Arguments
n
- Number of entries after downsampling.
sourcepub fn iter_mut(&mut self) -> IterMut<'_, Entry<T>>
pub fn iter_mut(&mut self) -> IterMut<'_, Entry<T>>
Provide a 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>
Provide an iterator over the PMF corresponding to this CDF.
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.
Time complexity: O(log n), where n is the number of Entry
s in CDF
.
Arguments
value
- A value at which you’re interested in the cumulative probability.
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
.
Time complexity: O(log n), where n is the number of Entry
s in CDF
.
sourcepub fn total_prob(&self) -> LogProb
pub fn total_prob(&self) -> LogProb
Return total probability of the CDF
.
Time complexity: O(1).
sourcepub fn map(&self) -> Option<&T>
pub fn map(&self) -> Option<&T>
Return maximum a posteriori probability estimate (MAP).
Time complexity: O(n), where n is the number of Entry
s in CDF
.
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.
Runtime complexity: O(log n), where n is the number of Entry
s in CDF
.
Arguments
width
- wanted width of the credible interval as a fraction of 1.
sourceimpl<T: Clone + Ord> CDF<T> where
f64: From<T>,
impl<T: Clone + Ord> CDF<T> where
f64: From<T>,
sourcepub fn expected_value(&self) -> f64
pub fn expected_value(&self) -> f64
Calculate expected value.
Runtime complexity: O(n), where n is the number of Entry
s in CDF
.
sourcepub fn variance(&self) -> f64
pub fn variance(&self) -> f64
Calculate variance.
Runtime complexity: O(n), where n is the number of Entry
s in CDF
.
sourcepub fn standard_deviation(&self) -> f64
pub fn standard_deviation(&self) -> f64
Calculate standard deviation.
Runtime complexity: O(n), where n is the number of Entry
s in CDF
.
Trait Implementations
sourceimpl<'de, T: Ord> Deserialize<'de> for CDF<T> where
T: Deserialize<'de>,
impl<'de, T: Ord> Deserialize<'de> for CDF<T> where
T: Deserialize<'de>,
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for CDF<T> where
T: RefUnwindSafe,
impl<T> Send for CDF<T> where
T: Send,
impl<T> Sync for CDF<T> where
T: Sync,
impl<T> Unpin for CDF<T> where
T: Unpin,
impl<T> UnwindSafe for CDF<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
pub fn to_subset(&self) -> Option<SS>
pub fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
pub fn is_in_subset(&self) -> bool
pub fn is_in_subset(&self) -> bool
Checks if self
is actually part of its subset T
(and can be converted to it).
pub fn to_subset_unchecked(&self) -> SS
pub fn to_subset_unchecked(&self) -> SS
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
pub fn from_subset(element: &SS) -> SP
pub fn from_subset(element: &SS) -> SP
The inclusion map: converts self
to the equivalent element of its superset.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more