From 672de56c3119e700583b9fcb44d3feed76ef81bb Mon Sep 17 00:00:00 2001 From: meliurwen Date: Wed, 12 Oct 2022 15:51:52 +0200 Subject: [PATCH 01/12] Added a brief description of the project in form of docstrings at the crate level --- reCTBN/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/reCTBN/src/lib.rs b/reCTBN/src/lib.rs index 280bd21..da1aa06 100644 --- a/reCTBN/src/lib.rs +++ b/reCTBN/src/lib.rs @@ -1,3 +1,9 @@ +//! # reCTBN +//! +//! > **Note:** At the moment it's in pre-alpha state. 🧪⚗️💥 +//! +//! `reCTBN` is a Continuous Time Bayesian Networks Library written in Rust. 🦀 + #![allow(non_snake_case)] #[cfg(test)] extern crate approx; -- 2.36.3 From 616d5ec3d551269f184141f48a7a9d638fc49767 Mon Sep 17 00:00:00 2001 From: meliurwen Date: Wed, 12 Oct 2022 16:33:47 +0200 Subject: [PATCH 02/12] Fixed and prettified some imprecisions to old docstrings and added new ones in `ctbn.rs` --- reCTBN/src/ctbn.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/reCTBN/src/ctbn.rs b/reCTBN/src/ctbn.rs index e2f5dd7..fae7f4d 100644 --- a/reCTBN/src/ctbn.rs +++ b/reCTBN/src/ctbn.rs @@ -5,16 +5,18 @@ use ndarray::prelude::*; use crate::network; use crate::params::{Params, ParamsTrait, StateType}; -///CTBN network. It represents both the structure and the parameters of a CTBN. CtbnNetwork is -///composed by the following elements: -///- **adj_metrix**: a 2d ndarray representing the adjacency matrix -///- **nodes**: a vector containing all the nodes and their parameters. -///The index of a node inside the vector is also used as index for the adj_matrix. +/// It represents both the structure and the parameters of a CTBN. /// -///# Examples +/// # Arguments /// -///``` -/// +/// * `adj_matrix` - A 2D ndarray representing the adjacency matrix +/// * `nodes` - A vector containing all the nodes and their parameters. +/// +/// The index of a node inside the vector is also used as index for the `adj_matrix`. +/// +/// # Example +/// +/// ```rust /// use std::collections::BTreeSet; /// use reCTBN::network::Network; /// use reCTBN::params; @@ -66,12 +68,14 @@ impl CtbnNetwork { } impl network::Network for CtbnNetwork { + /// Initialize an Adjacency matrix. fn initialize_adj_matrix(&mut self) { self.adj_matrix = Some(Array2::::zeros( (self.nodes.len(), self.nodes.len()).f(), )); } + /// Add a new node. fn add_node(&mut self, mut n: Params) -> Result { n.reset_params(); self.adj_matrix = Option::None; @@ -79,6 +83,7 @@ impl network::Network for CtbnNetwork { Ok(self.nodes.len() - 1) } + /// Connect two nodes with a new edge. fn add_edge(&mut self, parent: usize, child: usize) { if let None = self.adj_matrix { self.initialize_adj_matrix(); @@ -94,6 +99,7 @@ impl network::Network for CtbnNetwork { 0..self.nodes.len() } + /// Get the number of nodes of the network. fn get_number_of_nodes(&self) -> usize { self.nodes.len() } @@ -138,6 +144,7 @@ impl network::Network for CtbnNetwork { .0 } + /// Get all the parents of the given node. fn get_parent_set(&self, node: usize) -> BTreeSet { self.adj_matrix .as_ref() @@ -149,6 +156,7 @@ impl network::Network for CtbnNetwork { .collect() } + /// Get all the children of the given node. fn get_children_set(&self, node: usize) -> BTreeSet { self.adj_matrix .as_ref() -- 2.36.3 From ccced921495558a26703bf351310d5c8429ce7d0 Mon Sep 17 00:00:00 2001 From: meliurwen Date: Mon, 17 Oct 2022 11:48:08 +0200 Subject: [PATCH 03/12] Fixed some docstrings in `params.rs` --- reCTBN/src/params.rs | 47 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/reCTBN/src/params.rs b/reCTBN/src/params.rs index f994b99..d7bf8f8 100644 --- a/reCTBN/src/params.rs +++ b/reCTBN/src/params.rs @@ -23,9 +23,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,8 +64,8 @@ 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 { @@ -76,14 +75,14 @@ pub enum Params { /// 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 +/// - `label` +/// - `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`: permanence 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, @@ -104,15 +103,17 @@ impl DiscreteStatesContinousTimeParams { } } - ///Getter function for CIM + /// Getter function for CIM pub fn get_cim(&self) -> &Option> { &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 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 returns + /// `ParamsError`. pub fn set_cim(&mut self, cim: Array3) -> Result<(), ParamsError> { self.cim = Some(cim); match self.validate_params() { @@ -124,27 +125,27 @@ impl DiscreteStatesContinousTimeParams { } } - ///Unchecked version of the setter function for CIM. + /// Unchecked version of the setter function for CIM. pub fn set_cim_unchecked(&mut self, cim: Array3) { self.cim = Some(cim); } - ///Getter function for transitions + /// Getter function for transitions. pub fn get_transitions(&self) -> &Option> { &self.transitions } - ///Setter function for transitions + /// Setter function for transitions. pub fn set_transitions(&mut self, transitions: Array3) { self.transitions = Some(transitions); } - ///Getter function for residence_time + /// Getter function for residence_time. pub fn get_residence_time(&self) -> &Option> { &self.residence_time } - ///Setter function for residence_time + ///Setter function for residence_time. pub fn set_residence_time(&mut self, residence_time: Array2) { self.residence_time = Some(residence_time); } -- 2.36.3 From 2153f46758b367f9803bc520fcf0d9ee7be2abbb Mon Sep 17 00:00:00 2001 From: meliurwen Date: Mon, 17 Oct 2022 12:03:14 +0200 Subject: [PATCH 04/12] Fixed small lint problem and added a paragraph to the README --- README.md | 8 ++++++++ reCTBN/src/params.rs | 3 +-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f928955..6a60dff 100644 --- a/README.md +++ b/README.md @@ -56,3 +56,11 @@ To check the **formatting**: ```sh cargo fmt --all -- --check ``` + +## Documentation + +To generate the **documentation**: + +```sh +cargo rustdoc --package reCTBN --open -- --default-theme=ayu +``` diff --git a/reCTBN/src/params.rs b/reCTBN/src/params.rs index d7bf8f8..65db06c 100644 --- a/reCTBN/src/params.rs +++ b/reCTBN/src/params.rs @@ -72,7 +72,6 @@ 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: /// - `label` @@ -109,7 +108,7 @@ impl DiscreteStatesContinousTimeParams { } /// 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 returns -- 2.36.3 From 064b582833e25b903ebee32bc062967870272c78 Mon Sep 17 00:00:00 2001 From: meliurwen Date: Mon, 17 Oct 2022 12:59:39 +0200 Subject: [PATCH 05/12] Added docstrings for the chi-squared test --- .../src/structure_learning/hypothesis_test.rs | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/reCTBN/src/structure_learning/hypothesis_test.rs b/reCTBN/src/structure_learning/hypothesis_test.rs index 4f2ce18..7083d38 100644 --- a/reCTBN/src/structure_learning/hypothesis_test.rs +++ b/reCTBN/src/structure_learning/hypothesis_test.rs @@ -20,6 +20,17 @@ pub trait HypothesisTest { P: parameter_learning::ParameterLearning; } +/// Does the chi-squared test (χ2 test). +/// +/// Used to determine if a difference between two sets of data is due to chance, or if it is due to +/// a relationship (dependence) between the variables. +/// +/// # Arguments +/// +/// * `alpha` - is the significance level, the probability to reject a true null hypothesis; +/// in other words is the risk of concluding that an association between the variables exists +/// when there is no actual association. + pub struct ChiSquare { alpha: f64, } @@ -30,8 +41,21 @@ impl ChiSquare { pub fn new(alpha: f64) -> ChiSquare { ChiSquare { alpha } } - // Restituisce true quando le matrici sono molto simili, quindi indipendenti - // false quando sono diverse, quindi dipendenti + + /// Compare two matrices extracted from two 3rd-orer tensors. + /// + /// # Arguments + /// + /// * `i` - Position of the matrix of `M1` to compare with `M2`. + /// * `M1` - 3rd-order tensor 1. + /// * `j` - Position of the matrix of `M2` to compare with `M1`. + /// * `M2` - 3rd-order tensor 2. + /// + /// # Returns + /// + /// * `true` - when the matrices `M1` and `M2` are very similar, then **dependendent**. + /// * `false` - when the matrices `M1` and `M2` are too different, then **independent**. + pub fn compare_matrices( &self, i: usize, -- 2.36.3 From 9ca8973550010a503b0c74cb6b1672886401ee22 Mon Sep 17 00:00:00 2001 From: meliurwen Date: Mon, 17 Oct 2022 13:17:34 +0200 Subject: [PATCH 06/12] Harmonized some docstrings in `params.rs` --- reCTBN/src/params.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/reCTBN/src/params.rs b/reCTBN/src/params.rs index 65db06c..e533f21 100644 --- a/reCTBN/src/params.rs +++ b/reCTBN/src/params.rs @@ -73,14 +73,17 @@ pub enum Params { } /// This represents the parameters of a classical discrete node for ctbn and it's composed by the -/// following elements: -/// - `label` -/// - `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 +/// 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`: permanence time in each possible state, given a specific realization of the +/// * `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 { @@ -109,9 +112,9 @@ impl DiscreteStatesContinousTimeParams { /// 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 returns + /// 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) -> Result<(), ParamsError> { self.cim = Some(cim); @@ -144,7 +147,7 @@ impl DiscreteStatesContinousTimeParams { &self.residence_time } - ///Setter function for residence_time. + /// Setter function for residence_time. pub fn set_residence_time(&mut self, residence_time: Array2) { self.residence_time = Some(residence_time); } -- 2.36.3 From f7165d034598a14cc3f0460ee09ddbd31a831e95 Mon Sep 17 00:00:00 2001 From: meliurwen Date: Mon, 17 Oct 2022 14:19:26 +0200 Subject: [PATCH 07/12] Added docstrings to `networks.rs` --- reCTBN/src/network.rs | 87 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 78 insertions(+), 9 deletions(-) diff --git a/reCTBN/src/network.rs b/reCTBN/src/network.rs index cbae339..8fc8271 100644 --- a/reCTBN/src/network.rs +++ b/reCTBN/src/network.rs @@ -11,33 +11,102 @@ pub enum NetworkError { NodeInsertionError(String), } -///Network -///The Network trait define the required methods for a structure used as pgm (such as ctbn). +/// It defines the required methods for a structure used as a PGM (such as a CTBN). pub trait Network { fn initialize_adj_matrix(&mut self); fn add_node(&mut self, n: params::Params) -> Result; + /// Add an **directed edge** between a two nodes of the network. + /// + /// # Arguments + /// + /// * `parent` - parent node. + /// * `child` - child node. fn add_edge(&mut self, parent: usize, child: usize); - ///Get all the indices of the nodes contained inside the network + /// Get all the indices of the nodes contained inside the network. fn get_node_indices(&self) -> std::ops::Range; + + /// Get the numbers of nodes contained in the network. fn get_number_of_nodes(&self) -> usize; + + /// Get the **node param**. + /// + /// # Arguments + /// + /// * `node_idx` - node index value. + /// + /// # Return + /// + /// * The selected **node param**. fn get_node(&self, node_idx: usize) -> ¶ms::Params; + + /// Get the **node param**. + /// + /// # Arguments + /// + /// * `node_idx` - node index value. + /// + /// # Return + /// + /// * The selected **node mutable param**. fn get_node_mut(&mut self, node_idx: usize) -> &mut params::Params; - ///Compute the index that must be used to access the parameters of a node given a specific - ///configuration of the network. Usually, the only values really used in *current_state* are - ///the ones in the parent set of the *node*. + /// Compute the index that must be used to access the parameters of a `node`, given a specific + /// configuration of the network. + /// + /// Usually, the only values really used in `current_state` are the ones in the parent set of + /// the `node`. + /// + /// # Arguments + /// + /// * `node` - selected node. + /// * `current_state` - current configuration of the network. + /// + /// # Return + /// + /// * Index of the `node` relative to the network. fn get_param_index_network(&self, node: usize, current_state: &Vec) -> usize; - ///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*. + /// 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`. + /// + /// # Arguments + /// + /// * `current_state` - current configuration of the network. + /// * `parent_set` - parent set of the selected `node`. + /// + /// # Return + /// + /// * Index of the `node` relative to the network. fn get_param_index_from_custom_parent_set( &self, current_state: &Vec, parent_set: &BTreeSet, ) -> usize; + + /// Get the **parent set** of a given **node**. + /// + /// # Arguments + /// + /// * `node` - node index value. + /// + /// # Return + /// + /// * The **parent set** of the selected node. fn get_parent_set(&self, node: usize) -> BTreeSet; + + /// Get the **children set** of a given **node**. + /// + /// # Arguments + /// + /// * `node` - node index value. + /// + /// # Return + /// + /// * The **children set** of the selected node. fn get_children_set(&self, node: usize) -> BTreeSet; } -- 2.36.3 From 08623e28d4f479cfcacc3746c19e1ff903a0e5ef Mon Sep 17 00:00:00 2001 From: meliurwen Date: Tue, 18 Oct 2022 15:11:15 +0200 Subject: [PATCH 08/12] Added various docstrings notes to all rust modules --- reCTBN/src/ctbn.rs | 2 ++ reCTBN/src/network.rs | 5 ++++- reCTBN/src/parameter_learning.rs | 2 ++ reCTBN/src/params.rs | 2 ++ reCTBN/src/sampling.rs | 2 ++ reCTBN/src/structure_learning.rs | 2 ++ reCTBN/src/structure_learning/constraint_based_algorithm.rs | 2 ++ reCTBN/src/structure_learning/hypothesis_test.rs | 2 ++ reCTBN/src/structure_learning/score_based_algorithm.rs | 2 ++ reCTBN/src/structure_learning/score_function.rs | 2 ++ reCTBN/src/tools.rs | 2 ++ 11 files changed, 24 insertions(+), 1 deletion(-) diff --git a/reCTBN/src/ctbn.rs b/reCTBN/src/ctbn.rs index fae7f4d..2b01d14 100644 --- a/reCTBN/src/ctbn.rs +++ b/reCTBN/src/ctbn.rs @@ -1,3 +1,5 @@ +//! Continuous Time Bayesian Network + use std::collections::BTreeSet; use ndarray::prelude::*; diff --git a/reCTBN/src/network.rs b/reCTBN/src/network.rs index 8fc8271..fbdd2e6 100644 --- a/reCTBN/src/network.rs +++ b/reCTBN/src/network.rs @@ -1,3 +1,5 @@ +//! Defines methods for dealing with Probabilistic Graphical Models like the CTBNs + use std::collections::BTreeSet; use thiserror::Error; @@ -11,7 +13,8 @@ pub enum NetworkError { NodeInsertionError(String), } -/// It defines the required methods for a structure used as a PGM (such as a CTBN). +/// It defines the required methods for a structure used as a Probabilistic Graphical Models (such +/// as a CTBN). pub trait Network { fn initialize_adj_matrix(&mut self); fn add_node(&mut self, n: params::Params) -> Result; diff --git a/reCTBN/src/parameter_learning.rs b/reCTBN/src/parameter_learning.rs index bdb5d4a..61d4dca 100644 --- a/reCTBN/src/parameter_learning.rs +++ b/reCTBN/src/parameter_learning.rs @@ -1,3 +1,5 @@ +//! Module containing methods used to learn the parameters. + use std::collections::BTreeSet; use ndarray::prelude::*; diff --git a/reCTBN/src/params.rs b/reCTBN/src/params.rs index e533f21..070c997 100644 --- a/reCTBN/src/params.rs +++ b/reCTBN/src/params.rs @@ -1,3 +1,5 @@ +//! Module containing methods to define different types of nodes. + use std::collections::BTreeSet; use enum_dispatch::enum_dispatch; diff --git a/reCTBN/src/sampling.rs b/reCTBN/src/sampling.rs index 0660939..d435634 100644 --- a/reCTBN/src/sampling.rs +++ b/reCTBN/src/sampling.rs @@ -1,3 +1,5 @@ +//! Module containing methods for the sampling. + use crate::{ network::Network, params::{self, ParamsTrait}, diff --git a/reCTBN/src/structure_learning.rs b/reCTBN/src/structure_learning.rs index 8b90cdf..57fed1e 100644 --- a/reCTBN/src/structure_learning.rs +++ b/reCTBN/src/structure_learning.rs @@ -1,3 +1,5 @@ +//! Learn the structure of the network. + pub mod constraint_based_algorithm; pub mod hypothesis_test; pub mod score_based_algorithm; diff --git a/reCTBN/src/structure_learning/constraint_based_algorithm.rs b/reCTBN/src/structure_learning/constraint_based_algorithm.rs index b3fc3e1..670c8ed 100644 --- a/reCTBN/src/structure_learning/constraint_based_algorithm.rs +++ b/reCTBN/src/structure_learning/constraint_based_algorithm.rs @@ -1,3 +1,5 @@ +//! Module containing constraint based algorithms like CTPC and Hiton. + //pub struct CTPC { // //} diff --git a/reCTBN/src/structure_learning/hypothesis_test.rs b/reCTBN/src/structure_learning/hypothesis_test.rs index 7083d38..1404b8e 100644 --- a/reCTBN/src/structure_learning/hypothesis_test.rs +++ b/reCTBN/src/structure_learning/hypothesis_test.rs @@ -1,3 +1,5 @@ +//! Module containing an hypothesis test for constraint based algorithms like chi-squared test, F test, etc... + use std::collections::BTreeSet; use ndarray::{Array3, Axis}; diff --git a/reCTBN/src/structure_learning/score_based_algorithm.rs b/reCTBN/src/structure_learning/score_based_algorithm.rs index cc8541a..9e329eb 100644 --- a/reCTBN/src/structure_learning/score_based_algorithm.rs +++ b/reCTBN/src/structure_learning/score_based_algorithm.rs @@ -1,3 +1,5 @@ +//! Module containing score based algorithms like Hill Climbing and Tabu Search. + use std::collections::BTreeSet; use crate::structure_learning::score_function::ScoreFunction; diff --git a/reCTBN/src/structure_learning/score_function.rs b/reCTBN/src/structure_learning/score_function.rs index b3b1597..cb6ad7b 100644 --- a/reCTBN/src/structure_learning/score_function.rs +++ b/reCTBN/src/structure_learning/score_function.rs @@ -1,3 +1,5 @@ +//! Module for score based algorithms containing score functions algorithms like Log Likelihood, BIC, etc... + use std::collections::BTreeSet; use ndarray::prelude::*; diff --git a/reCTBN/src/tools.rs b/reCTBN/src/tools.rs index 70bbf76..aa48883 100644 --- a/reCTBN/src/tools.rs +++ b/reCTBN/src/tools.rs @@ -1,3 +1,5 @@ +//! Contains commonly used methods used across the crate. + use ndarray::prelude::*; use crate::sampling::{ForwardSampler, Sampler}; -- 2.36.3 From 245b3b5d4598b8fa14c44ce85a830c336966d888 Mon Sep 17 00:00:00 2001 From: meliurwen Date: Tue, 18 Oct 2022 15:34:37 +0200 Subject: [PATCH 09/12] Replaced the static docstrings at the crate level in `lib.rs` withthe external file `README.md` --- reCTBN/src/lib.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/reCTBN/src/lib.rs b/reCTBN/src/lib.rs index da1aa06..b1cf773 100644 --- a/reCTBN/src/lib.rs +++ b/reCTBN/src/lib.rs @@ -1,8 +1,4 @@ -//! # reCTBN -//! -//! > **Note:** At the moment it's in pre-alpha state. 🧪⚗️💥 -//! -//! `reCTBN` is a Continuous Time Bayesian Networks Library written in Rust. 🦀 +#![doc = include_str!("../../README.md")] #![allow(non_snake_case)] #[cfg(test)] -- 2.36.3 From 3522e1b6f633fd4ed0c9bee167ef604d869502ea Mon Sep 17 00:00:00 2001 From: meliurwen Date: Tue, 18 Oct 2022 15:40:59 +0200 Subject: [PATCH 10/12] Small formatting fix and rewording of a docstring --- reCTBN/src/lib.rs | 1 - reCTBN/src/structure_learning/hypothesis_test.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/reCTBN/src/lib.rs b/reCTBN/src/lib.rs index b1cf773..db33ae4 100644 --- a/reCTBN/src/lib.rs +++ b/reCTBN/src/lib.rs @@ -1,5 +1,4 @@ #![doc = include_str!("../../README.md")] - #![allow(non_snake_case)] #[cfg(test)] extern crate approx; diff --git a/reCTBN/src/structure_learning/hypothesis_test.rs b/reCTBN/src/structure_learning/hypothesis_test.rs index 1404b8e..f931e77 100644 --- a/reCTBN/src/structure_learning/hypothesis_test.rs +++ b/reCTBN/src/structure_learning/hypothesis_test.rs @@ -1,4 +1,4 @@ -//! Module containing an hypothesis test for constraint based algorithms like chi-squared test, F test, etc... +//! Module for constraint based algorithms containing hypothesis test algorithms like chi-squared test, F test, etc... use std::collections::BTreeSet; -- 2.36.3 From 832922922ade46f91904842c75841ceebd67e429 Mon Sep 17 00:00:00 2001 From: meliurwen Date: Thu, 20 Oct 2022 08:58:02 +0200 Subject: [PATCH 11/12] Fixed error in chi2 compare matrices docstring --- reCTBN/src/structure_learning/hypothesis_test.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reCTBN/src/structure_learning/hypothesis_test.rs b/reCTBN/src/structure_learning/hypothesis_test.rs index f931e77..4e1cb24 100644 --- a/reCTBN/src/structure_learning/hypothesis_test.rs +++ b/reCTBN/src/structure_learning/hypothesis_test.rs @@ -55,8 +55,8 @@ impl ChiSquare { /// /// # Returns /// - /// * `true` - when the matrices `M1` and `M2` are very similar, then **dependendent**. - /// * `false` - when the matrices `M1` and `M2` are too different, then **independent**. + /// * `true` - when the matrices `M1` and `M2` are very similar, then **independendent**. + /// * `false` - when the matrices `M1` and `M2` are too different, then **dependent**. pub fn compare_matrices( &self, -- 2.36.3 From 0ae2168a9439635b91ffaa680db79569b3604c29 Mon Sep 17 00:00:00 2001 From: meliurwen Date: Thu, 20 Oct 2022 09:36:02 +0200 Subject: [PATCH 12/12] Commented out some prints in chi2 compare matrices --- .../src/structure_learning/hypothesis_test.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/reCTBN/src/structure_learning/hypothesis_test.rs b/reCTBN/src/structure_learning/hypothesis_test.rs index 4e1cb24..6474155 100644 --- a/reCTBN/src/structure_learning/hypothesis_test.rs +++ b/reCTBN/src/structure_learning/hypothesis_test.rs @@ -97,7 +97,7 @@ impl ChiSquare { let n = K.len(); K.into_shape((n, 1)).unwrap() }; - println!("K: {:?}", K); + //println!("K: {:?}", K); let L = 1.0 / &K; // ===== 2 // \ (K . M - L . M) @@ -108,18 +108,18 @@ impl ChiSquare { // x'ϵVal /X \ // \ i/ let mut X_2 = (&K * &M2 - &L * &M1).mapv(|a| a.powi(2)) / (&M2 + &M1); - println!("M1: {:?}", M1); - println!("M2: {:?}", M2); - println!("L*M1: {:?}", (L * &M1)); - println!("K*M2: {:?}", (K * &M2)); - println!("X_2: {:?}", X_2); + //println!("M1: {:?}", M1); + //println!("M2: {:?}", M2); + //println!("L*M1: {:?}", (L * &M1)); + //println!("K*M2: {:?}", (K * &M2)); + //println!("X_2: {:?}", X_2); X_2.diag_mut().fill(0.0); let X_2 = X_2.sum_axis(Axis(1)); let n = ChiSquared::new((X_2.dim() - 1) as f64).unwrap(); - println!("CHI^2: {:?}", n); - println!("CHI^2 CDF: {:?}", X_2.mapv(|x| n.cdf(x))); + //println!("CHI^2: {:?}", n); + //println!("CHI^2 CDF: {:?}", X_2.mapv(|x| n.cdf(x))); let ret = X_2.into_iter().all(|x| n.cdf(x) < (1.0 - self.alpha)); - println!("test: {:?}", ret); + //println!("test: {:?}", ret); ret } } -- 2.36.3