[]Struct bio::stats::probs::LogProb

pub struct LogProb(pub f64);

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]

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]

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_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

impl Debug for LogProb

impl Add<LogProb> for LogProb

type Output = LogProb

The resulting type after applying the + operator.

impl<'a> Add<&'a LogProb> for &'a LogProb

type Output = LogProb

The resulting type after applying the + operator.

impl<'a> Add<&'a LogProb> for LogProb

type Output = LogProb

The resulting type after applying the + operator.

impl<'a> Add<LogProb> for &'a LogProb

type Output = LogProb

The resulting type after applying the + operator.

impl Sub<LogProb> for LogProb

type Output = LogProb

The resulting type after applying the - operator.

impl<'a> Sub<&'a LogProb> for &'a LogProb

type Output = LogProb

The resulting type after applying the - operator.

impl<'a> Sub<&'a LogProb> for LogProb

type Output = LogProb

The resulting type after applying the - operator.

impl<'a> Sub<LogProb> for &'a LogProb

type Output = LogProb

The resulting type after applying the - operator.

impl AddAssign<LogProb> for LogProb[src]

impl SubAssign<LogProb> for LogProb[src]

impl Deref for LogProb

type Target = f64

The resulting type after dereferencing.

impl<'a> Sum<&'a LogProb> for LogProb[src]

impl<'a> Sum<LogProb> for LogProb[src]

impl Zero for LogProb[src]

fn set_zero(&mut self)[src]

Sets self to the additive identity element of Self, 0.

impl Serialize for LogProb[src]

impl<'de> Deserialize<'de> for LogProb[src]

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]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<M> Measure for M where
    M: Debug + PartialOrd<M> + Add<M, Output = M> + Default + Clone
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]