pub struct TabularCPD {
pub node_idx: usize,
pub n_values: usize,
pub parent_card: Vec<usize>,
pub parent_indices: Vec<usize>,
pub table: Vec<Vec<f64>>,
/* private fields */
}Expand description
Discrete CPD stored as a conditional probability table (CPT).
The table is indexed by the combined parent configuration.
values[row][val] = P(X = val | parent_config = row).
Row indexing follows column-major (rightmost parent cycles fastest),
matching pgmpy convention:
row = Sum_i (parent_values[i] * stride[i])
where stride[i] = product of cardinalities of parents to the right.
Fields§
§node_idx: usizeIndex of the node this CPD belongs to.
n_values: usizeNumber of values (cardinality) of this node.
parent_card: Vec<usize>Cardinalities of parent nodes.
parent_indices: Vec<usize>Parent node indices.
table: Vec<Vec<f64>>Table: table[row] = probability distribution over n_values states.
Length = product(parent_card), each inner vec has length n_values.
Implementations§
Source§impl TabularCPD
impl TabularCPD
Sourcepub fn new(
node_idx: usize,
n_values: usize,
parent_indices: Vec<usize>,
parent_card: Vec<usize>,
values: Vec<Vec<f64>>,
) -> Result<Self, StatsError>
pub fn new( node_idx: usize, n_values: usize, parent_indices: Vec<usize>, parent_card: Vec<usize>, values: Vec<Vec<f64>>, ) -> Result<Self, StatsError>
Create a new TabularCPD.
§Arguments
node_idx: Index of the node.n_values: Cardinality of this node.parent_indices: Indices of parent nodes.parent_card: Cardinalities of each parent (same order as parent_indices).values: Probability table. Each row is a probability distribution. If there are no parents,valuesshould have exactly one row.
Sourcepub fn row_index(&self, parent_values: &[usize]) -> Result<usize, StatsError>
pub fn row_index(&self, parent_values: &[usize]) -> Result<usize, StatsError>
Compute the row index for a given parent configuration.
Sourcepub fn distribution(
&self,
parent_values: &[usize],
) -> Result<&[f64], StatsError>
pub fn distribution( &self, parent_values: &[usize], ) -> Result<&[f64], StatsError>
Return the full conditional distribution P(X | parent_values).
Trait Implementations§
Source§impl CPD for TabularCPD
impl CPD for TabularCPD
Source§fn cardinality(&self) -> usize
fn cardinality(&self) -> usize
Source§fn parent_indices(&self) -> &[usize]
fn parent_indices(&self) -> &[usize]
Source§fn is_continuous(&self) -> bool
fn is_continuous(&self) -> bool
Source§impl Clone for TabularCPD
impl Clone for TabularCPD
Source§fn clone(&self) -> TabularCPD
fn clone(&self) -> TabularCPD
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for TabularCPD
impl RefUnwindSafe for TabularCPD
impl Send for TabularCPD
impl Sync for TabularCPD
impl Unpin for TabularCPD
impl UnsafeUnpin for TabularCPD
impl UnwindSafe for TabularCPD
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
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
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>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
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
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.