[−]Struct bio::stats::probs::LogProb
A newtype for log-scale probabilities.
For performance reasons, we use an approximation of the exp method
implemented in bio::utils::FastExp
. This can lead to slight
errors, but should not matter given that most of the probability differences
are reflected within the integer part of the log probability.
Example
#[macro_use] extern crate approx; use bio::stats::{LogProb, Prob}; // convert from probability let p = LogProb::from(Prob(0.5)); // convert manually let q = LogProb(0.2f64.ln()); // obtain zero probability in log-space let o = LogProb::ln_one(); assert_relative_eq!(*Prob::from(p.ln_add_exp(q) + o), *Prob(0.7), epsilon=0.000001);
Methods
impl LogProb
[src]
pub fn is_valid(&self) -> bool
[src]
pub fn ln_zero() -> LogProb
[src]
Log-space representation of Pr=0
pub fn ln_one() -> LogProb
[src]
Log-space representation of Pr=1
pub fn cap_numerical_overshoot(&self, epsilon: f64) -> LogProb
[src]
sums of LogProbs, e.g. with ln_sum_exp()
can end up
slightly above the maximum of LogProb <= 0
due to
numerical imprecisions -- this function can rescue such
values before panics due to asserts in other functions
handling LogProbs, e.g. ln_1m_exp
pub fn ln_one_minus_exp(&self) -> LogProb
[src]
Numerically stable calculation of 1 - p in log-space.
pub fn ln_sum_exp(probs: &[LogProb]) -> LogProb
[src]
Numerically stable sum of probabilities in log-space.
pub fn ln_add_exp(self, other: LogProb) -> LogProb
[src]
Numerically stable addition of probabilities in log-space.
pub fn ln_sub_exp(self, other: LogProb) -> LogProb
[src]
Numerically stable subtraction of probabilities in log-space.
pub fn ln_cumsum_exp<I: IntoIterator<Item = LogProb>>(probs: I) -> ScanIter<I>
[src]
Calculate the cumulative sum of the given probabilities in a numerically stable way (Durbin 1998).
pub fn ln_trapezoidal_integrate_exp<T, D>(
density: D,
a: T,
b: T,
n: usize
) -> LogProb where
T: Copy + Add<Output = T> + Sub<Output = T> + Div<Output = T> + Mul<Output = T> + Float,
D: FnMut(usize, T) -> LogProb,
f64: From<T>,
[src]
density: D,
a: T,
b: T,
n: usize
) -> LogProb where
T: Copy + Add<Output = T> + Sub<Output = T> + Div<Output = T> + Mul<Output = T> + Float,
D: FnMut(usize, T) -> LogProb,
f64: From<T>,
Integrate numerically stable over given log-space density in the interval [a, b]. Uses the trapezoidal rule with n grid points.
pub fn ln_simpsons_integrate_exp<T, D>(
density: D,
a: T,
b: T,
n: usize
) -> LogProb where
T: Copy + Add<Output = T> + Sub<Output = T> + Div<Output = T> + Mul<Output = T> + Float,
D: FnMut(usize, T) -> LogProb,
f64: From<T>,
[src]
density: D,
a: T,
b: T,
n: usize
) -> LogProb where
T: Copy + Add<Output = T> + Sub<Output = T> + Div<Output = T> + Mul<Output = T> + Float,
D: FnMut(usize, T) -> LogProb,
f64: From<T>,
Integrate numerically stable over given log-space density in the interval [a, b]. Uses Simpson's rule with n (odd) grid points.
Trait Implementations
impl Clone for LogProb
fn clone(&self) -> LogProb
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Copy for LogProb
impl From<f64> for LogProb
impl From<LogProb> for f64
impl From<NotNan<f64>> for LogProb
[src]
impl From<LogProb> for NotNan<f64>
[src]
impl From<LogProb> for Prob
[src]
impl From<Prob> for LogProb
[src]
impl From<PHREDProb> for LogProb
[src]
impl From<LogProb> for PHREDProb
[src]
impl Default for LogProb
[src]
impl PartialEq<LogProb> for LogProb
impl PartialOrd<LogProb> for LogProb
fn partial_cmp(&self, other: &LogProb) -> Option<Ordering>
fn lt(&self, other: &LogProb) -> bool
fn le(&self, other: &LogProb) -> bool
fn gt(&self, other: &LogProb) -> bool
fn ge(&self, other: &LogProb) -> bool
impl Debug for LogProb
impl Add<LogProb> for LogProb
type Output = LogProb
The resulting type after applying the +
operator.
fn add(self, rhs: Self) -> LogProb
impl<'a> Add<&'a LogProb> for &'a LogProb
type Output = LogProb
The resulting type after applying the +
operator.
fn add(self, rhs: Self) -> LogProb
impl<'a> Add<&'a LogProb> for LogProb
type Output = LogProb
The resulting type after applying the +
operator.
fn add(self, rhs: &'a LogProb) -> LogProb
impl<'a> Add<LogProb> for &'a LogProb
type Output = LogProb
The resulting type after applying the +
operator.
fn add(self, rhs: LogProb) -> LogProb
impl Sub<LogProb> for LogProb
type Output = LogProb
The resulting type after applying the -
operator.
fn sub(self, rhs: Self) -> LogProb
impl<'a> Sub<&'a LogProb> for &'a LogProb
type Output = LogProb
The resulting type after applying the -
operator.
fn sub(self, rhs: Self) -> LogProb
impl<'a> Sub<&'a LogProb> for LogProb
type Output = LogProb
The resulting type after applying the -
operator.
fn sub(self, rhs: &'a LogProb) -> LogProb
impl<'a> Sub<LogProb> for &'a LogProb
type Output = LogProb
The resulting type after applying the -
operator.
fn sub(self, rhs: LogProb) -> LogProb
impl AddAssign<LogProb> for LogProb
[src]
fn add_assign(&mut self, other: LogProb)
[src]
impl SubAssign<LogProb> for LogProb
[src]
fn sub_assign(&mut self, other: LogProb)
[src]
impl Deref for LogProb
impl<'a> Sum<&'a LogProb> for LogProb
[src]
impl<'a> Sum<LogProb> for LogProb
[src]
impl Zero for LogProb
[src]
fn zero() -> Self
[src]
fn is_zero(&self) -> bool
[src]
fn set_zero(&mut self)
[src]
Sets self
to the additive identity element of Self
, 0
.
impl Serialize for LogProb
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<'de> Deserialize<'de> for LogProb
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
Auto Trait Implementations
impl Sync for LogProb
impl Unpin for LogProb
impl Send for LogProb
impl UnwindSafe for LogProb
impl RefUnwindSafe for LogProb
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<M> Measure for M where
M: Debug + PartialOrd<M> + Add<M, Output = M> + Default + Clone,
[src]
M: Debug + PartialOrd<M> + Add<M, Output = M> + Default + Clone,
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,