pub struct Factor {
pub id: String,
pub variables: Vec<String>,
pub values: Vec<f64>,
pub shape: Vec<usize>,
}Expand description
A factor (un-normalised joint distribution table) over a set of variables.
values is stored in row-major order: the last variable in variables
varies fastest. shape[i] is the cardinality of variables[i].
Fields§
§id: StringHuman-readable label.
variables: Vec<String>Ordered variable scope.
values: Vec<f64>Flat probability/potential table.
shape: Vec<usize>Shape array — shape[i] is the number of states for variables[i].
Implementations§
Source§impl Factor
impl Factor
Sourcepub fn product(&self, other: &Factor) -> Factor
pub fn product(&self, other: &Factor) -> Factor
Compute the factor product of self and other.
The result has the union of both variable scopes. Values are the point-wise product over all joint assignments.
Sourcepub fn marginalize(
&self,
variable: &str,
_var_map: &HashMap<String, usize>,
) -> Factor
pub fn marginalize( &self, variable: &str, _var_map: &HashMap<String, usize>, ) -> Factor
Marginalize variable out of this factor by summing over all its
states.
var_map maps variable names to their cardinalities and is used for
consistency checking; the actual cardinality is taken from self.shape.
Sourcepub fn reduce(
&self,
variable: &str,
state: usize,
_var_map: &HashMap<String, usize>,
) -> Factor
pub fn reduce( &self, variable: &str, state: usize, _var_map: &HashMap<String, usize>, ) -> Factor
Reduce this factor by fixing variable to state (slice operation).
The resulting factor no longer contains variable in its scope.
Sourcepub fn contains_variable(&self, variable: &str) -> bool
pub fn contains_variable(&self, variable: &str) -> bool
Whether variable appears in this factor’s scope.
Trait Implementations§
impl StructuralPartialEq for Factor
Auto Trait Implementations§
impl Freeze for Factor
impl RefUnwindSafe for Factor
impl Send for Factor
impl Sync for Factor
impl Unpin for Factor
impl UnsafeUnpin for Factor
impl UnwindSafe for Factor
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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 more