pub struct LogMessage {
pub variable: String,
pub log_values: Array1<f64>,
}Expand description
A message stored in log-space for numerical stability.
All arithmetic (product, damping) is performed in log space, then converted back to probability space only when computing beliefs.
Fields§
§variable: StringVariable this message is “about”
log_values: Array1<f64>Log-probabilities (not necessarily normalised)
Implementations§
Source§impl LogMessage
impl LogMessage
Sourcepub fn from_factor_slice(variable: &str, values: &ArrayD<f64>) -> Self
pub fn from_factor_slice(variable: &str, values: &ArrayD<f64>) -> Self
Create from a (probability-space) crate::Factor projected onto a single variable.
Sourcepub fn uniform(variable: &str, card: usize) -> Self
pub fn uniform(variable: &str, card: usize) -> Self
Create a uniform log-message of length card.
Sourcepub fn log_normalise(&mut self)
pub fn log_normalise(&mut self)
Log-sum-exp normalise (subtract max, then subtract log-sum-exp).
Sourcepub fn residual_linf(&self, other: &LogMessage) -> f64
pub fn residual_linf(&self, other: &LogMessage) -> f64
L∞ residual vs another message (in log space).
Sourcepub fn damp(&self, old: &LogMessage, lambda: f64) -> Self
pub fn damp(&self, old: &LogMessage, lambda: f64) -> Self
Apply damping: λ * self + (1-λ) * old (in log space via log-sum-exp).
Trait Implementations§
Source§impl Clone for LogMessage
impl Clone for LogMessage
Source§fn clone(&self) -> LogMessage
fn clone(&self) -> LogMessage
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for LogMessage
impl RefUnwindSafe for LogMessage
impl Send for LogMessage
impl Sync for LogMessage
impl Unpin for LogMessage
impl UnsafeUnpin for LogMessage
impl UnwindSafe for LogMessage
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.