pub struct DiscreteFactor { /* private fields */ }Implementations§
Source§impl DiscreteFactor
impl DiscreteFactor
Sourcepub fn new(scope: Vec<VarSpec>, logp: Vec<f32>) -> Result<Self, String>
pub fn new(scope: Vec<VarSpec>, logp: Vec<f32>) -> Result<Self, String>
Build from explicit scope specs (order is preserved).
Sourcepub fn uniform(scope: Vec<VarSpec>) -> Result<Self, String>
pub fn uniform(scope: Vec<VarSpec>) -> Result<Self, String>
Convenient: all zeros in prob-space => log(1) table (not normalized unless you normalize).
pub fn scope(&self) -> &[VarId]
pub fn dims(&self) -> &[usize]
pub fn logp(&self) -> &[f32]
Sourcepub fn index_of(&self, asg: &[usize]) -> usize
pub fn index_of(&self, asg: &[usize]) -> usize
Flatten an assignment (aligned with this factor’s axis order) to an index.
Sourcepub fn unflatten(&self, idx: usize) -> Vec<usize>
pub fn unflatten(&self, idx: usize) -> Vec<usize>
Unflatten index -> assignment (aligned with axis order).
pub fn log_value_aligned(&self, asg: &[usize]) -> f32
Sourcepub fn restrict(&self, evidence: &[(VarId, usize)]) -> Result<Self, String>
pub fn restrict(&self, evidence: &[(VarId, usize)]) -> Result<Self, String>
Restrict (condition) the factor on evidence. Evidence is a list of (VarId, state) pairs. Returns a new factor with those variables fixed and removed from the scope.
Sourcepub fn reorder(&self, new_scope: &[VarId]) -> Result<Self, String>
pub fn reorder(&self, new_scope: &[VarId]) -> Result<Self, String>
Reorder axes to new_scope (must be a permutation of current scope).
Sourcepub fn normalize_rows(&mut self, child: VarId) -> Result<(), String>
pub fn normalize_rows(&mut self, child: VarId) -> Result<(), String>
CPT-style normalization on the child axis: for every fixed parent assignment,
normalize over child states so that sum prob == 1.
Sourcepub fn marginalize(&self, elim: &[VarId]) -> Result<Self, String>
pub fn marginalize(&self, elim: &[VarId]) -> Result<Self, String>
Sum out the given vars.
Sourcepub fn product(
&self,
rhs: &DiscreteFactor,
cards: &impl Fn(VarId) -> usize,
) -> Result<Self, String>
pub fn product( &self, rhs: &DiscreteFactor, cards: &impl Fn(VarId) -> usize, ) -> Result<Self, String>
Product of two discrete factors: join scope, broadcast, add in log-space.
pub fn axis_of(&self, v: VarId) -> Option<usize>
Trait Implementations§
Source§impl Clone for DiscreteFactor
impl Clone for DiscreteFactor
Source§fn clone(&self) -> DiscreteFactor
fn clone(&self) -> DiscreteFactor
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 DiscreteFactor
impl RefUnwindSafe for DiscreteFactor
impl Send for DiscreteFactor
impl Sync for DiscreteFactor
impl Unpin for DiscreteFactor
impl UnsafeUnpin for DiscreteFactor
impl UnwindSafe for DiscreteFactor
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