logo
pub struct LogProb(pub f64);
Expand description

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);

Tuple Fields

0: f64

Implementations

Log-space representation of Pr=0

Log-space representation of Pr=1

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

Numerically stable calculation of 1 - p in log-space.

Numerically stable sum of probabilities in log-space.

Numerically stable addition of probabilities in log-space.

Numerically stable subtraction of probabilities in log-space.

Calculate the cumulative sum of the given probabilities in a numerically stable way (Durbin 1998).

Integrate numerically stable over given log-space density in the interval [a, b]. Uses the trapezoidal rule with n grid points.

Integrate numerically stable over given log-space density in the interval [a, b]. Uses Simpson’s rule with n (odd) grid points.

Integrate numerically stable over given log-space density and grid points. Uses the trapezoidal rule.

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Performs the += operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The resulting type after dereferencing.

Dereferences the value.

Deserialize this value from the given Serde deserializer. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Performs the -= operation. Read more

Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more

Method which takes an iterator and generates Self from the elements by “summing up” the items. Read more

Returns the additive identity element of Self, 0. Read more

Returns true if self is equal to the additive identity.

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

Performance hack: Clone doesn’t get inlined for Copy types in debug mode, so make it inline anyway.

Tests if Self the same as the type T Read more

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more

Checks if self is actually part of its subset T (and can be converted to it).

Use with care! Same as self.to_subset but without any property checks. Always succeeds.

The inclusion map: converts self to the equivalent element of its superset.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.