pub struct DynamicBayesianNetwork {
pub state_vars: Vec<(String, usize)>,
pub observation_vars: Vec<(String, usize)>,
pub initial_dists: HashMap<String, ArrayD<f64>>,
pub transition_dists: HashMap<String, ArrayD<f64>>,
pub emission_dists: HashMap<String, ArrayD<f64>>,
}Expand description
Dynamic Bayesian Network.
Represents a temporal probabilistic model with variables that evolve over time.
§Example
use tensorlogic_quantrs_hooks::DynamicBayesianNetwork;
use scirs2_core::ndarray::{Array, ArrayD, IxDyn};
// Create a simple DBN with one state variable
let dbn = DynamicBayesianNetwork::new(
vec![("state".to_string(), 2)], // state variables with cardinality
vec![], // no observation variables
);Fields§
§state_vars: Vec<(String, usize)>State variables with cardinalities
observation_vars: Vec<(String, usize)>Observation variables with cardinalities
initial_dists: HashMap<String, ArrayD<f64>>Initial distribution P(X_0) for each state variable
transition_dists: HashMap<String, ArrayD<f64>>Transition distributions P(X_t | X_{t-1})
emission_dists: HashMap<String, ArrayD<f64>>Emission distributions P(Y_t | X_t)
Implementations§
Source§impl DynamicBayesianNetwork
impl DynamicBayesianNetwork
Sourcepub fn new(
state_vars: Vec<(String, usize)>,
observation_vars: Vec<(String, usize)>,
) -> Self
pub fn new( state_vars: Vec<(String, usize)>, observation_vars: Vec<(String, usize)>, ) -> Self
Create a new DBN with state and observation variables.
Sourcepub fn set_initial(&mut self, var: &str, dist: ArrayD<f64>) -> Result<&mut Self>
pub fn set_initial(&mut self, var: &str, dist: ArrayD<f64>) -> Result<&mut Self>
Set initial distribution for a state variable.
Sourcepub fn set_transition(
&mut self,
var: &str,
dist: ArrayD<f64>,
) -> Result<&mut Self>
pub fn set_transition( &mut self, var: &str, dist: ArrayD<f64>, ) -> Result<&mut Self>
Set transition distribution P(X_t | X_{t-1}) for a state variable.
Sourcepub fn set_emission(
&mut self,
obs_var: &str,
dist: ArrayD<f64>,
) -> Result<&mut Self>
pub fn set_emission( &mut self, obs_var: &str, dist: ArrayD<f64>, ) -> Result<&mut Self>
Set emission distribution P(Y | X) for an observation variable.
Sourcepub fn unroll(&self, num_steps: usize) -> Result<FactorGraph>
pub fn unroll(&self, num_steps: usize) -> Result<FactorGraph>
Unroll the DBN for a fixed number of time steps.
Returns a FactorGraph representing the unrolled DBN.
Sourcepub fn filter(
&self,
observations: &[HashMap<String, usize>],
) -> Result<Vec<HashMap<String, ArrayD<f64>>>>
pub fn filter( &self, observations: &[HashMap<String, usize>], ) -> Result<Vec<HashMap<String, ArrayD<f64>>>>
Perform filtering to compute P(X_t | y_{1:t}).
Returns marginal distributions for state variables at each time step.
Sourcepub fn smooth(
&self,
observations: &[HashMap<String, usize>],
) -> Result<Vec<HashMap<String, ArrayD<f64>>>>
pub fn smooth( &self, observations: &[HashMap<String, usize>], ) -> Result<Vec<HashMap<String, ArrayD<f64>>>>
Perform smoothing to compute P(X_t | y_{1:T}) for all t.
Uses variable elimination on the unrolled DBN.
Sourcepub fn viterbi(
&self,
observations: &[HashMap<String, usize>],
) -> Result<Vec<HashMap<String, usize>>>
pub fn viterbi( &self, observations: &[HashMap<String, usize>], ) -> Result<Vec<HashMap<String, usize>>>
Compute most likely sequence using Viterbi algorithm on unrolled DBN.
Sourcepub fn state_cardinalities(&self) -> HashMap<String, usize>
pub fn state_cardinalities(&self) -> HashMap<String, usize>
Get interface (state) variable cardinalities.
Sourcepub fn observation_cardinalities(&self) -> HashMap<String, usize>
pub fn observation_cardinalities(&self) -> HashMap<String, usize>
Get observation variable cardinalities.
Sourcepub fn all_variables(&self) -> HashSet<String>
pub fn all_variables(&self) -> HashSet<String>
Get all variables in the DBN.
Trait Implementations§
Source§impl Clone for DynamicBayesianNetwork
impl Clone for DynamicBayesianNetwork
Source§fn clone(&self) -> DynamicBayesianNetwork
fn clone(&self) -> DynamicBayesianNetwork
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for DynamicBayesianNetwork
impl RefUnwindSafe for DynamicBayesianNetwork
impl Send for DynamicBayesianNetwork
impl Sync for DynamicBayesianNetwork
impl Unpin for DynamicBayesianNetwork
impl UnwindSafe for DynamicBayesianNetwork
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
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>
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
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.