pub struct LogProb<T>(/* private fields */);
Expand description
Struct that can only hold float values that correspond to negative log probabilities.
Implementations§
source§impl<T: Float + Ln2> LogProb<T>
impl<T: Float + Ln2> LogProb<T>
sourcepub fn add_log_prob(
&self,
y: LogProb<T>
) -> Result<LogProb<T>, ProbabilitiesSumToGreaterThanOne>
pub fn add_log_prob( &self, y: LogProb<T> ) -> Result<LogProb<T>, ProbabilitiesSumToGreaterThanOne>
Adds [LogProb]
as raw probabilities and return the new log probability.
sourcepub fn add_log_prob_clamped(&self, y: LogProb<T>) -> LogProb<T>
pub fn add_log_prob_clamped(&self, y: LogProb<T>) -> LogProb<T>
Adds log probabilities but clamping at 0.0.
sourcepub fn add_log_prob_float(&self, y: LogProb<T>) -> T
pub fn add_log_prob_float(&self, y: LogProb<T>) -> T
Adds log probabilities and return a float (so can be greater than 0.0).
source§impl<T: Float> LogProb<T>
impl<T: Float> LogProb<T>
sourcepub fn new(val: T) -> Result<Self, FloatIsNanOrPositive>
pub fn new(val: T) -> Result<Self, FloatIsNanOrPositive>
Construct a new LogProb
that is guaranteed to be negative (or +0.0).
sourcepub fn from_raw_prob(val: T) -> Result<Self, FloatIsNanOrPositive>
pub fn from_raw_prob(val: T) -> Result<Self, FloatIsNanOrPositive>
Construct a new LogProb
that is guaranteed to be negative (or +0.0) from a value in [0.0, 1.0].
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Gets out the value.
sourcepub fn raw_prob(&self) -> T
pub fn raw_prob(&self) -> T
Get the equivalent non-log probability
let x = LogProb::from_raw_prob(0.25).unwrap();
assert_eq!(x.raw_prob(), 0.25);
sourcepub fn opposite_prob(&self) -> Self
pub fn opposite_prob(&self) -> Self
Calculates the probability of the complement of this log-probability
let x = LogProb::from_raw_prob(0.25).unwrap();
let y = LogProb::from_raw_prob(0.75).unwrap();
assert_eq!(x.opposite_prob(), y);
Trait Implementations§
source§impl<'a, T: AddAssign<&'a T>> AddAssign<&'a LogProb<T>> for LogProb<T>
impl<'a, T: AddAssign<&'a T>> AddAssign<&'a LogProb<T>> for LogProb<T>
source§fn add_assign(&mut self, other: &'a Self)
fn add_assign(&mut self, other: &'a Self)
Performs the
+=
operation. Read moresource§impl<T: AddAssign> AddAssign for LogProb<T>
impl<T: AddAssign> AddAssign for LogProb<T>
source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Performs the
+=
operation. Read moresource§impl<T: Float> Ord for LogProb<T>
impl<T: Float> Ord for LogProb<T>
source§impl<T: PartialEq> PartialEq for LogProb<T>
impl<T: PartialEq> PartialEq for LogProb<T>
source§impl<T: PartialOrd> PartialOrd for LogProb<T>
impl<T: PartialOrd> PartialOrd for LogProb<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl<T: Copy> Copy for LogProb<T>
impl<T: Float> Eq for LogProb<T>
impl<T> StructuralPartialEq for LogProb<T>
Auto Trait Implementations§
impl<T> RefUnwindSafe for LogProb<T>where
T: RefUnwindSafe,
impl<T> Send for LogProb<T>where
T: Send,
impl<T> Sync for LogProb<T>where
T: Sync,
impl<T> Unpin for LogProb<T>where
T: Unpin,
impl<T> UnwindSafe for LogProb<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more