causal-hub 0.0.5

A library for causal models, inference and discovery.
Documentation
mod categorical;
pub use categorical::*;

use crate::{
    models::graphs::DiGraph,
    types::{Map, Result},
};

/// A trait for continuous time Bayesian networks (CTBNs).
pub trait CTBN {
    /// The type of the CIM.
    type CIM;
    /// The type of the initial distribution.
    type InitialDistribution;
    /// The type of the observed event.
    type Event;
    /// The type of the observed trajectory.
    type Trajectory;
    /// The type of a collection of trajectories.
    type Trajectories;

    /// Constructs a new CTBN.
    ///
    /// # Arguments
    ///
    /// * `graph` - The underlying graph.
    /// * `cims` - The conditional intensity matrices.
    ///
    /// # Notes
    ///
    /// The distribution of the initial state (i.e. initial distribution) is uniform.
    /// See `with_initial_distribution` to specify the initial distribution.
    ///
    /// # Errors
    ///
    /// * If the number of CIMs does not match the number of vertices in the graph.
    /// * If the labels of the CIMs do not match the labels of the graph.
    /// * If the conditioning labels of the CIMs do not match the parents of the vertices in the graph.
    ///
    /// # Returns
    ///
    /// A new CTBN instance.
    ///
    fn new<I>(graph: DiGraph, cims: I) -> Result<Self>
    where
        I: IntoIterator<Item = Self::CIM>,
        Self: Sized;

    /// Returns the initial distribution.
    ///
    /// # Returns
    ///
    /// A reference to the initial distribution.
    ///
    fn initial_distribution(&self) -> &Self::InitialDistribution;

    /// Returns the underlying graph.
    ///
    /// # Returns
    ///
    /// A reference to the graph.
    ///
    fn graph(&self) -> &DiGraph;

    /// Returns a map labels-distributions.
    ///
    /// # Returns
    ///
    /// A reference to the CIMs.
    ///
    fn cims(&self) -> &Map<String, Self::CIM>;

    /// Returns the parameters size.
    ///
    /// # Returns
    ///
    /// The parameters size.
    ///
    fn parameters_size(&self) -> usize;

    /// Creates a new categorical continuous-time Bayesian network with optional fields.
    ///
    /// # Arguments
    ///
    /// * `name` - The name of the model.
    /// * `description` - The description of the model.
    /// * `initial_distribution` - The initial distribution of the model.
    /// * `graph` - The underlying graph.
    /// * `cims` - The conditional intensity matrices.
    ///
    /// # Errors
    ///
    /// * If `name` is an empty string.
    /// * If `description` is an empty string.
    /// * If the number of CIMs does not match the number of vertices in the graph.
    /// * If the labels of the CIMs do not match the labels of the graph.
    /// * If the conditioning labels of the CIMs do not match the parents of the vertices in the graph.
    ///
    /// # Returns
    ///
    /// A new categorical continuous-time Bayesian network instance.
    ///
    fn with_optionals<I>(
        name: Option<String>,
        description: Option<String>,
        initial_distribution: Self::InitialDistribution,
        graph: DiGraph,
        cims: I,
    ) -> Result<Self>
    where
        I: IntoIterator<Item = Self::CIM>,
        Self: Sized;
}