causal_hub/models/continuous_time_bayesian_network/
mod.rs

1mod categorical;
2pub use categorical::*;
3
4use crate::{models::graphs::DiGraph, types::Map};
5
6/// A trait for continuous time Bayesian networks (CTBNs).
7pub trait CTBN {
8    /// The type of the CIM.
9    type CIM;
10    /// The type of the initial distribution.
11    type InitialDistribution;
12    /// The type of the observed event.
13    type Event;
14    /// The type of the observed trajectory.
15    type Trajectory;
16    /// The type of a collection of trajectories.
17    type Trajectories;
18
19    /// Constructs a new CTBN.
20    ///
21    /// # Arguments
22    ///
23    /// * `graph` - The underlying graph.
24    /// * `cims` - The conditional intensity matrices.
25    ///
26    /// # Notes
27    ///
28    /// The distribution of the initial state (i.e. initial distribution) is uniform.
29    /// See `with_initial_distribution` to specify the initial distribution.
30    ///
31    /// # Returns
32    ///
33    /// A new CTBN instance.
34    ///
35    fn new<I>(graph: DiGraph, cims: I) -> Self
36    where
37        I: IntoIterator<Item = Self::CIM>;
38
39    /// Returns the initial distribution.
40    ///
41    /// # Returns
42    ///
43    /// A reference to the initial distribution.
44    ///
45    fn initial_distribution(&self) -> &Self::InitialDistribution;
46
47    /// Returns the underlying graph.
48    ///
49    /// # Returns
50    ///
51    /// A reference to the graph.
52    ///
53    fn graph(&self) -> &DiGraph;
54
55    /// Returns the a map labels-distributions.
56    ///
57    /// # Returns
58    ///
59    /// A reference to the CIMs.
60    ///
61    fn cims(&self) -> &Map<String, Self::CIM>;
62
63    /// Returns the parameters size.
64    ///
65    /// # Returns
66    ///
67    /// The parameters size.
68    ///
69    fn parameters_size(&self) -> usize;
70
71    /// Creates a new categorical continuous-time Bayesian network with optional fields.
72    ///
73    /// # Arguments
74    ///
75    /// * `name` - The name of the model.
76    /// * `description` - The description of the model.
77    /// * `graph` - The underlying graph.
78    /// * `cims` - The conditional intensity matrices.
79    ///
80    /// # Panics
81    ///
82    /// * Panics if `name` is an empty string.
83    /// * Panics if `description` is an empty string.
84    ///
85    /// # Returns
86    ///
87    /// A new categorical continuous-time Bayesian network instance.
88    ///
89    fn with_optionals<I>(
90        name: Option<String>,
91        description: Option<String>,
92        initial_distribution: Self::InitialDistribution,
93        graph: DiGraph,
94        cims: I,
95    ) -> Self
96    where
97        I: IntoIterator<Item = Self::CIM>;
98}