|
|
|
@ -1,3 +1,5 @@ |
|
|
|
|
//! Module containing methods to define different types of nodes.
|
|
|
|
|
|
|
|
|
|
use std::collections::BTreeSet; |
|
|
|
|
|
|
|
|
|
use enum_dispatch::enum_dispatch; |
|
|
|
@ -23,9 +25,8 @@ pub enum StateType { |
|
|
|
|
Discrete(usize), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Parameters
|
|
|
|
|
/// The Params trait is the core element for building different types of nodes. The goal is to
|
|
|
|
|
/// define the set of method required to describes a generic node.
|
|
|
|
|
/// This is a core element for building different types of nodes; the goal is to define the set of
|
|
|
|
|
/// methods required to describes a generic node.
|
|
|
|
|
#[enum_dispatch(Params)] |
|
|
|
|
pub trait ParamsTrait { |
|
|
|
|
fn reset_params(&mut self); |
|
|
|
@ -65,25 +66,27 @@ pub trait ParamsTrait { |
|
|
|
|
fn get_label(&self) -> &String; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// The Params enum is the core element for building different types of nodes. The goal is to
|
|
|
|
|
/// define all the supported type of Parameters
|
|
|
|
|
/// Is a core element for building different types of nodes; the goal is to define all the
|
|
|
|
|
/// supported type of Parameters
|
|
|
|
|
#[derive(Clone)] |
|
|
|
|
#[enum_dispatch] |
|
|
|
|
pub enum Params { |
|
|
|
|
DiscreteStatesContinousTime(DiscreteStatesContinousTimeParams), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// DiscreteStatesContinousTime.
|
|
|
|
|
/// This represents the parameters of a classical discrete node for ctbn and it's composed by the
|
|
|
|
|
/// following elements:
|
|
|
|
|
/// - **domain**: an ordered and exhaustive set of possible states
|
|
|
|
|
/// - **cim**: Conditional Intensity Matrix
|
|
|
|
|
/// - **Sufficient Statistics**: the sufficient statistics are mainly used during the parameter
|
|
|
|
|
/// learning task and are composed by:
|
|
|
|
|
/// - **transitions**: number of transitions from one state to another given a specific
|
|
|
|
|
/// realization of the parent set
|
|
|
|
|
/// - **residence_time**: permanence time in each possible states given a specific
|
|
|
|
|
/// realization of the parent set
|
|
|
|
|
/// following elements.
|
|
|
|
|
///
|
|
|
|
|
/// # Arguments
|
|
|
|
|
///
|
|
|
|
|
/// * `label` - node's variable name.
|
|
|
|
|
/// * `domain` - an ordered and exhaustive set of possible states.
|
|
|
|
|
/// * `cim` - Conditional Intensity Matrix.
|
|
|
|
|
/// * `transitions` - number of transitions from one state to another given a specific realization
|
|
|
|
|
/// of the parent set; is a sufficient statistics are mainly used during the parameter learning
|
|
|
|
|
/// task.
|
|
|
|
|
/// * `residence_time` - residence time in each possible state, given a specific realization of the
|
|
|
|
|
/// parent set; is a sufficient statistics are mainly used during the parameter learning task.
|
|
|
|
|
#[derive(Clone)] |
|
|
|
|
pub struct DiscreteStatesContinousTimeParams { |
|
|
|
|
label: String, |
|
|
|
@ -109,10 +112,12 @@ impl DiscreteStatesContinousTimeParams { |
|
|
|
|
&self.cim |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///Setter function for CIM.\\
|
|
|
|
|
///This function check if the cim is valid using the validate_params method.
|
|
|
|
|
///- **Valid cim inserted**: it substitute the CIM in self.cim and return Ok(())
|
|
|
|
|
///- **Invalid cim inserted**: it replace the self.cim value with None and it retu ParamsError
|
|
|
|
|
/// Setter function for CIM.
|
|
|
|
|
///
|
|
|
|
|
/// This function checks if the CIM is valid using the [`validate_params`](self::ParamsTrait::validate_params) method:
|
|
|
|
|
/// * **Valid CIM inserted** - it substitutes the CIM in `self.cim` and returns `Ok(())`.
|
|
|
|
|
/// * **Invalid CIM inserted** - it replaces the `self.cim` value with `None` and it returns
|
|
|
|
|
/// `ParamsError`.
|
|
|
|
|
pub fn set_cim(&mut self, cim: Array3<f64>) -> Result<(), ParamsError> { |
|
|
|
|
self.cim = Some(cim); |
|
|
|
|
match self.validate_params() { |
|
|
|
@ -129,22 +134,22 @@ impl DiscreteStatesContinousTimeParams { |
|
|
|
|
self.cim = Some(cim); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///Getter function for transitions
|
|
|
|
|
/// Getter function for transitions.
|
|
|
|
|
pub fn get_transitions(&self) -> &Option<Array3<usize>> { |
|
|
|
|
&self.transitions |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///Setter function for transitions
|
|
|
|
|
/// Setter function for transitions.
|
|
|
|
|
pub fn set_transitions(&mut self, transitions: Array3<usize>) { |
|
|
|
|
self.transitions = Some(transitions); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///Getter function for residence_time
|
|
|
|
|
/// Getter function for residence_time.
|
|
|
|
|
pub fn get_residence_time(&self) -> &Option<Array2<f64>> { |
|
|
|
|
&self.residence_time |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///Setter function for residence_time
|
|
|
|
|
/// Setter function for residence_time.
|
|
|
|
|
pub fn set_residence_time(&mut self, residence_time: Array2<f64>) { |
|
|
|
|
self.residence_time = Some(residence_time); |
|
|
|
|
} |
|
|
|
|