A new, blazing-fast learning engine for Continuous Time Bayesian Networks. Written in pure Rust. 🦀
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
reCTBN/src/network.rs

40 lines
1.7 KiB

3 years ago
use thiserror::Error;
use crate::params;
use crate::node;
use std::collections::BTreeSet;
3 years ago
3 years ago
/// Error types for trait Network
3 years ago
#[derive(Error, Debug)]
pub enum NetworkError {
#[error("Error during node insertion")]
3 years ago
NodeInsertionError(String)
3 years ago
}
3 years ago
///Network
///The Network trait define the required methods for a structure used as pgm (such as ctbn).
3 years ago
pub trait Network {
fn initialize_adj_matrix(&mut self);
fn add_node(&mut self, n: node::Node) -> Result<usize, NetworkError>;
fn add_edge(&mut self, parent: usize, child: usize);
3 years ago
///Get all the indices of the nodes contained inside the network
fn get_node_indices(&self) -> std::ops::Range<usize>;
3 years ago
fn get_number_of_nodes(&self) -> usize;
fn get_node(&self, node_idx: usize) -> &node::Node;
fn get_node_mut(&mut self, node_idx: usize) -> &mut node::Node;
3 years ago
3 years ago
///Compute the index that must be used to access the parameters of a node given a specific
3 years ago
///configuration of the network. Usually, the only values really used in *current_state* are
///the ones in the parent set of the *node*.
fn get_param_index_network(&self, node: usize, current_state: &Vec<params::StateType>) -> usize;
3 years ago
///Compute the index that must be used to access the parameters of a node given a specific
///configuration of the network and a generic parent_set. Usually, the only values really used
///in *current_state* are the ones in the parent set of the *node*.
fn get_param_index_from_custom_parent_set(&self, current_state: &Vec<params::StateType>, parent_set: &BTreeSet<usize>) -> usize;
fn get_parent_set(&self, node: usize) -> BTreeSet<usize>;
fn get_children_set(&self, node: usize) -> BTreeSet<usize>;
3 years ago
}