|
|
|
@ -15,8 +15,67 @@ use log::{debug, error, info, trace, warn}; |
|
|
|
|
/// * `param` - An Option containing the parameters of the process
|
|
|
|
|
///
|
|
|
|
|
///```rust
|
|
|
|
|
/// use std::collections::BTreeSet;
|
|
|
|
|
/// use reCTBN::process::NetworkProcess;
|
|
|
|
|
/// use reCTBN::params;
|
|
|
|
|
/// use reCTBN::process::ctbn::*;
|
|
|
|
|
/// use ndarray::arr3;
|
|
|
|
|
///
|
|
|
|
|
/// //Create the domain for a discrete node
|
|
|
|
|
/// let mut domain = BTreeSet::new();
|
|
|
|
|
/// domain.insert(String::from("A"));
|
|
|
|
|
/// domain.insert(String::from("B"));
|
|
|
|
|
///
|
|
|
|
|
/// //Create the parameters for a discrete node using the domain
|
|
|
|
|
/// let param = params::DiscreteStatesContinousTimeParams::new("X1".to_string(), domain);
|
|
|
|
|
///
|
|
|
|
|
/// //Create the node using the parameters
|
|
|
|
|
/// let X1 = params::Params::DiscreteStatesContinousTime(param);
|
|
|
|
|
///
|
|
|
|
|
/// let mut domain = BTreeSet::new();
|
|
|
|
|
/// domain.insert(String::from("A"));
|
|
|
|
|
/// domain.insert(String::from("B"));
|
|
|
|
|
/// let param = params::DiscreteStatesContinousTimeParams::new("X2".to_string(), domain);
|
|
|
|
|
/// let X2 = params::Params::DiscreteStatesContinousTime(param);
|
|
|
|
|
///
|
|
|
|
|
/// //Initialize a ctbn
|
|
|
|
|
/// let mut net = CtbnNetwork::new();
|
|
|
|
|
///
|
|
|
|
|
/// //Add nodes
|
|
|
|
|
/// let X1 = net.add_node(X1).unwrap();
|
|
|
|
|
/// let X2 = net.add_node(X2).unwrap();
|
|
|
|
|
///
|
|
|
|
|
/// //Add an edge
|
|
|
|
|
/// net.add_edge(X1, X2);
|
|
|
|
|
/// match &mut net.get_node_mut(X1) {
|
|
|
|
|
/// params::Params::DiscreteStatesContinousTime(param) => {
|
|
|
|
|
/// assert_eq!(Ok(()), param.set_cim(arr3(&[[[-0.1, 0.1], [1.0, -1.0]]])));
|
|
|
|
|
/// }
|
|
|
|
|
/// }
|
|
|
|
|
///
|
|
|
|
|
/// match &mut net.get_node_mut(X2) {
|
|
|
|
|
/// params::Params::DiscreteStatesContinousTime(param) => {
|
|
|
|
|
/// assert_eq!(
|
|
|
|
|
/// Ok(()),
|
|
|
|
|
/// param.set_cim(arr3(&[
|
|
|
|
|
/// [[-0.01, 0.01], [5.0, -5.0]],
|
|
|
|
|
/// [[-5.0, 5.0], [0.01, -0.01]]
|
|
|
|
|
/// ]))
|
|
|
|
|
/// );
|
|
|
|
|
/// }
|
|
|
|
|
/// }
|
|
|
|
|
/// //Amalgamate the ctbn into a CtmpProcess
|
|
|
|
|
/// let ctmp = net.amalgamation();
|
|
|
|
|
///
|
|
|
|
|
/// //Extract the amalgamated params from the ctmp
|
|
|
|
|
///let params::Params::DiscreteStatesContinousTime(p_ctmp) = &ctmp.get_node(0);
|
|
|
|
|
///let p_ctmp = p_ctmp.get_cim().as_ref().unwrap();
|
|
|
|
|
///
|
|
|
|
|
/// //The shape of the params for an amalgamated ctmp can be computed as a Cartesian product of the
|
|
|
|
|
/// //domains variables of the ctbn
|
|
|
|
|
/// assert_eq!(p_ctmp.shape()[1], 4);
|
|
|
|
|
///```
|
|
|
|
|
|
|
|
|
|
pub struct CtmpProcess { |
|
|
|
|
param: Option<Params>, |
|
|
|
|
} |
|
|
|
@ -47,7 +106,7 @@ impl NetworkProcess for CtmpProcess { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn add_edge(&mut self, _parent: usize, _child: usize) { |
|
|
|
|
warn!("A CTMP cannot have endges") |
|
|
|
|
warn!("A CTMP cannot have endges"); |
|
|
|
|
unimplemented!("CtmpProcess has only one node") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|