From 28ed1a40b32bb1a6629e5a67b379ed0b56c89861 Mon Sep 17 00:00:00 2001 From: AlessandroBregoli Date: Wed, 16 Nov 2022 14:52:39 +0100 Subject: [PATCH] Fix for clippy --- reCTBN/src/lib.rs | 2 +- reCTBN/src/process/ctbn.rs | 13 ++-- reCTBN/src/process/ctmp.rs | 60 +++++++++++-------- reCTBN/src/sampling.rs | 2 +- .../src/structure_learning/hypothesis_test.rs | 2 +- .../src/structure_learning/score_function.rs | 2 +- reCTBN/src/tools.rs | 2 +- reCTBN/tests/ctbn.rs | 4 +- reCTBN/tests/ctmp.rs | 6 +- 9 files changed, 52 insertions(+), 41 deletions(-) diff --git a/reCTBN/src/lib.rs b/reCTBN/src/lib.rs index 6ab59cb..c62c42e 100644 --- a/reCTBN/src/lib.rs +++ b/reCTBN/src/lib.rs @@ -5,7 +5,7 @@ extern crate approx; pub mod parameter_learning; pub mod params; +pub mod process; pub mod sampling; pub mod structure_learning; pub mod tools; -pub mod process; diff --git a/reCTBN/src/process/ctbn.rs b/reCTBN/src/process/ctbn.rs index a6be923..7cb327d 100644 --- a/reCTBN/src/process/ctbn.rs +++ b/reCTBN/src/process/ctbn.rs @@ -70,7 +70,7 @@ impl CtbnNetwork { nodes: Vec::new(), } } - + ///Transform the **CTBN** into a **CTMP** /// /// # Return @@ -105,10 +105,8 @@ impl CtbnNetwork { let mut next_state = current_state.clone(); next_state[idx_node] = next_node_state; - let next_state_statetype: Vec = next_state - .iter() - .map(|x| StateType::Discrete(*x)) - .collect(); + let next_state_statetype: Vec = + next_state.iter().map(|x| StateType::Discrete(*x)).collect(); let idx_next_state = self.get_param_index_from_custom_parent_set( &next_state_statetype, &variables_set, @@ -127,13 +125,14 @@ impl CtbnNetwork { "ctmp".to_string(), BTreeSet::from_iter((0..state_space).map(|x| x.to_string())), ); - + println!("{:?}", amalgamated_cim); amalgamated_param.set_cim(amalgamated_cim).unwrap(); let mut ctmp = CtmpProcess::new(); - ctmp.add_node(Params::DiscreteStatesContinousTime(amalgamated_param)).unwrap(); + ctmp.add_node(Params::DiscreteStatesContinousTime(amalgamated_param)) + .unwrap(); return ctmp; } diff --git a/reCTBN/src/process/ctmp.rs b/reCTBN/src/process/ctmp.rs index b0b042a..81509fa 100644 --- a/reCTBN/src/process/ctmp.rs +++ b/reCTBN/src/process/ctmp.rs @@ -1,11 +1,14 @@ use std::collections::BTreeSet; -use crate::{process, params::{Params, StateType}}; +use crate::{ + params::{Params, StateType}, + process, +}; use super::NetworkProcess; pub struct CtmpProcess { - param: Option + param: Option, } impl CtmpProcess { @@ -24,26 +27,28 @@ impl NetworkProcess for CtmpProcess { None => { self.param = Some(n); Ok(0) - }, - Some(_) => Err(process::NetworkError::NodeInsertionError("CtmpProcess has only one node".to_string())) + } + Some(_) => Err(process::NetworkError::NodeInsertionError( + "CtmpProcess has only one node".to_string(), + )), } } - fn add_edge(&mut self, parent: usize, child: usize) { + fn add_edge(&mut self, _parent: usize, _child: usize) { unimplemented!("CtmpProcess has only one node") } fn get_node_indices(&self) -> std::ops::Range { match self.param { None => 0..0, - Some(_) => 0..1 + Some(_) => 0..1, } } fn get_number_of_nodes(&self) -> usize { match self.param { None => 0, - Some(_) => 1 + Some(_) => 1, } } @@ -63,11 +68,14 @@ impl NetworkProcess for CtmpProcess { } } - fn get_param_index_network(&self, node: usize, current_state: &Vec) - -> usize { + fn get_param_index_network( + &self, + node: usize, + current_state: &Vec, + ) -> usize { if node == 0 { match current_state[0] { - StateType::Discrete(x) => x + StateType::Discrete(x) => x, } } else { unimplemented!("CtmpProcess has only one node") @@ -76,31 +84,35 @@ impl NetworkProcess for CtmpProcess { fn get_param_index_from_custom_parent_set( &self, - current_state: &Vec, - parent_set: &std::collections::BTreeSet, + _current_state: &Vec, + _parent_set: &std::collections::BTreeSet, ) -> usize { unimplemented!("CtmpProcess has only one node") } fn get_parent_set(&self, node: usize) -> std::collections::BTreeSet { match self.param { - Some(_) => if node == 0 { - BTreeSet::new() - } else { - unimplemented!("CtmpProcess has only one node") - }, - None => panic!("Uninitialized CtmpProcess") + Some(_) => { + if node == 0 { + BTreeSet::new() + } else { + unimplemented!("CtmpProcess has only one node") + } + } + None => panic!("Uninitialized CtmpProcess"), } } fn get_children_set(&self, node: usize) -> std::collections::BTreeSet { match self.param { - Some(_) => if node == 0 { - BTreeSet::new() - } else { - unimplemented!("CtmpProcess has only one node") - }, - None => panic!("Uninitialized CtmpProcess") + Some(_) => { + if node == 0 { + BTreeSet::new() + } else { + unimplemented!("CtmpProcess has only one node") + } + } + None => panic!("Uninitialized CtmpProcess"), } } } diff --git a/reCTBN/src/sampling.rs b/reCTBN/src/sampling.rs index 050daeb..0662994 100644 --- a/reCTBN/src/sampling.rs +++ b/reCTBN/src/sampling.rs @@ -1,8 +1,8 @@ //! Module containing methods for the sampling. use crate::{ - process::NetworkProcess, params::{self, ParamsTrait}, + process::NetworkProcess, }; use rand::SeedableRng; use rand_chacha::ChaCha8Rng; diff --git a/reCTBN/src/structure_learning/hypothesis_test.rs b/reCTBN/src/structure_learning/hypothesis_test.rs index 4ec3377..344c995 100644 --- a/reCTBN/src/structure_learning/hypothesis_test.rs +++ b/reCTBN/src/structure_learning/hypothesis_test.rs @@ -6,7 +6,7 @@ use ndarray::{Array3, Axis}; use statrs::distribution::{ChiSquared, ContinuousCDF}; use crate::params::*; -use crate::{process, parameter_learning}; +use crate::{parameter_learning, process}; pub trait HypothesisTest { fn call( diff --git a/reCTBN/src/structure_learning/score_function.rs b/reCTBN/src/structure_learning/score_function.rs index 8943478..f8b38b5 100644 --- a/reCTBN/src/structure_learning/score_function.rs +++ b/reCTBN/src/structure_learning/score_function.rs @@ -5,7 +5,7 @@ use std::collections::BTreeSet; use ndarray::prelude::*; use statrs::function::gamma; -use crate::{process, parameter_learning, params, tools}; +use crate::{parameter_learning, params, process, tools}; pub trait ScoreFunction { fn call( diff --git a/reCTBN/src/tools.rs b/reCTBN/src/tools.rs index 6f2f648..2e727e8 100644 --- a/reCTBN/src/tools.rs +++ b/reCTBN/src/tools.rs @@ -3,7 +3,7 @@ use ndarray::prelude::*; use crate::sampling::{ForwardSampler, Sampler}; -use crate::{process, params}; +use crate::{params, process}; pub struct Trajectory { time: Array1, diff --git a/reCTBN/tests/ctbn.rs b/reCTBN/tests/ctbn.rs index a7752f2..7db2bae 100644 --- a/reCTBN/tests/ctbn.rs +++ b/reCTBN/tests/ctbn.rs @@ -1,12 +1,12 @@ mod utils; use std::collections::BTreeSet; -use std::f64::EPSILON; + use approx::AbsDiffEq; use ndarray::arr3; use reCTBN::params::{self, ParamsTrait}; use reCTBN::process::NetworkProcess; -use reCTBN::process::{ctbn::*, ctmp::*}; +use reCTBN::process::{ctbn::*}; use utils::generate_discrete_time_continous_node; #[test] diff --git a/reCTBN/tests/ctmp.rs b/reCTBN/tests/ctmp.rs index 31bc6df..830bfe0 100644 --- a/reCTBN/tests/ctmp.rs +++ b/reCTBN/tests/ctmp.rs @@ -45,7 +45,7 @@ fn add_edge_to_ctmp() { let _n1 = net .add_node(generate_discrete_time_continous_node(String::from("n1"), 2)) .unwrap(); - let n2 = net.add_node(generate_discrete_time_continous_node(String::from("n1"), 2)); + let _n2 = net.add_node(generate_discrete_time_continous_node(String::from("n1"), 2)); net.add_edge(0, 1) } @@ -64,7 +64,7 @@ fn childen_and_parents() { #[test] #[should_panic] fn get_childen_panic() { - let mut net = CtmpProcess::new(); + let net = CtmpProcess::new(); net.get_children_set(0); } @@ -81,7 +81,7 @@ fn get_childen_panic2() { #[test] #[should_panic] fn get_parent_panic() { - let mut net = CtmpProcess::new(); + let net = CtmpProcess::new(); net.get_parent_set(0); }