Struct bio::stats::probs::LogProb [−][src]
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);
Implementations
impl LogProb
[src]
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.
pub fn ln_trapezoidal_integrate_grid_exp<T, D>(
density: D,
grid: &[T]
) -> 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,
grid: &[T]
) -> 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 and grid points. Uses the trapezoidal rule.
Methods from Deref<Target = f64>
pub const RADIX: u32
1.43.0[src]
pub const MANTISSA_DIGITS: u32
1.43.0[src]
pub const DIGITS: u32
1.43.0[src]
pub const EPSILON: f64
1.43.0[src]
pub const MIN: f64
1.43.0[src]
pub const MIN_POSITIVE: f64
1.43.0[src]
pub const MAX: f64
1.43.0[src]
pub const MIN_EXP: i32
1.43.0[src]
pub const MAX_EXP: i32
1.43.0[src]
pub const MIN_10_EXP: i32
1.43.0[src]
pub const MAX_10_EXP: i32
1.43.0[src]
pub const NAN: f64
1.43.0[src]
pub const INFINITY: f64
1.43.0[src]
pub const NEG_INFINITY: f64
1.43.0[src]
pub fn as_ne_bytes(&self) -> &[u8; 8]
[src]
num_as_ne_bytes
)Return the memory representation of this floating point number as a byte array in native byte order.
to_ne_bytes
should be preferred over this whenever possible.
Examples
#![feature(num_as_ne_bytes)] let num = 12.5f64; let bytes = num.as_ne_bytes(); assert_eq!( bytes, if cfg!(target_endian = "big") { &[0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] } else { &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40] } );
pub fn total_cmp(&self, other: &f64) -> Ordering
[src]
total_cmp
)Returns an ordering between self and other values. Unlike the standard partial comparison between floating point numbers, this comparison always produces an ordering in accordance to the totalOrder predicate as defined in IEEE 754 (2008 revision) floating point standard. The values are ordered in following order:
- Negative quiet NaN
- Negative signaling NaN
- Negative infinity
- Negative numbers
- Negative subnormal numbers
- Negative zero
- Positive zero
- Positive subnormal numbers
- Positive numbers
- Positive infinity
- Positive signaling NaN
- Positive quiet NaN
Note that this function does not always agree with the PartialOrd
and PartialEq
implementations of f64
. In particular, they regard
negative and positive zero as equal, while total_cmp
doesn’t.
Example
#![feature(total_cmp)] struct GoodBoy { name: String, weight: f64, } let mut bois = vec![ GoodBoy { name: "Pucci".to_owned(), weight: 0.1 }, GoodBoy { name: "Woofer".to_owned(), weight: 99.0 }, GoodBoy { name: "Yapper".to_owned(), weight: 10.0 }, GoodBoy { name: "Chonk".to_owned(), weight: f64::INFINITY }, GoodBoy { name: "Abs. Unit".to_owned(), weight: f64::NAN }, GoodBoy { name: "Floaty".to_owned(), weight: -5.0 }, ]; bois.sort_by(|a, b| a.weight.total_cmp(&b.weight));
Trait Implementations
impl<'de> Deserialize<'de> for LogProb
[src]
impl<'de> Deserialize<'de> for LogProb
[src]fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl PartialOrd<LogProb> for LogProb
[src]
impl PartialOrd<LogProb> for LogProb
[src]impl StructuralPartialEq for LogProb
[src]
impl StructuralPartialEq for LogProb
[src]Auto Trait Implementations
impl RefUnwindSafe for LogProb
impl RefUnwindSafe for LogProb
impl UnwindSafe for LogProb
impl UnwindSafe for LogProb
Blanket Implementations
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
Should always be Self
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 is_in_subset(&self) -> bool
pub unsafe fn to_subset_unchecked(&self) -> SS
pub fn from_subset(element: &SS) -> SP
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,