From c4f44f63ea862ccf43596f9b8b03cd8721c6398b Mon Sep 17 00:00:00 2001 From: meliurwen Date: Fri, 29 Jul 2022 12:53:38 +0200 Subject: [PATCH 1/2] Silenced `non_snake_case` warning globally in `src/`, solved some unused imports and other negligible leftovers --- src/lib.rs | 2 +- src/parameter_learning.rs | 5 +---- src/params.rs | 2 +- src/structure_learning/hypothesis_test.rs | 1 - 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index bcbde3f..1dcc637 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,5 @@ +#![allow(non_snake_case)] #[cfg(test)] -#[macro_use] extern crate approx; pub mod params; diff --git a/src/parameter_learning.rs b/src/parameter_learning.rs index bf5b96a..ffd1db8 100644 --- a/src/parameter_learning.rs +++ b/src/parameter_learning.rs @@ -2,7 +2,6 @@ use crate::network; use crate::params::*; use crate::tools; use ndarray::prelude::*; -use ndarray::{concatenate, Slice}; use std::collections::BTreeSet; pub trait ParameterLearning{ @@ -137,15 +136,13 @@ impl ParameterLearning for BayesianApproach { node: usize, parent_set: Option>, ) -> Params { - //TODO: make this function general. Now it works only on ContinousTimeDiscreteState nodes - //Use parent_set from parameter if present. Otherwise use parent_set from network. let parent_set = match parent_set { Some(p) => p, None => net.get_parent_set(node), }; - let (mut M, mut T) = sufficient_statistics(net, dataset, node.clone(), &parent_set); + let (M, T) = sufficient_statistics(net, dataset, node.clone(), &parent_set); let alpha: f64 = self.alpha as f64 / M.shape()[0] as f64; let tau: f64 = self.tau as f64 / M.shape()[0] as f64; diff --git a/src/params.rs b/src/params.rs index d9f307f..c2768b1 100644 --- a/src/params.rs +++ b/src/params.rs @@ -1,7 +1,7 @@ use enum_dispatch::enum_dispatch; use ndarray::prelude::*; use rand::Rng; -use std::collections::{BTreeSet, HashMap}; +use std::collections::{BTreeSet}; use thiserror::Error; use rand_chacha::ChaCha8Rng; diff --git a/src/structure_learning/hypothesis_test.rs b/src/structure_learning/hypothesis_test.rs index eb6b570..f8eeb30 100644 --- a/src/structure_learning/hypothesis_test.rs +++ b/src/structure_learning/hypothesis_test.rs @@ -1,4 +1,3 @@ -use ndarray::Array2; use ndarray::Array3; use ndarray::Axis; use statrs::distribution::{ChiSquared, ContinuousCDF}; From d0515a3f2627f289bbe27f142068aad1f5a5cd9f Mon Sep 17 00:00:00 2001 From: meliurwen Date: Fri, 29 Jul 2022 13:27:38 +0200 Subject: [PATCH 2/2] Solved all warnings in `tests/` --- tests/parameter_learning.rs | 4 ++-- tests/params.rs | 4 +++- tests/structure_learning.rs | 4 +++- tests/tools.rs | 2 +- tests/utils.rs | 7 +------ 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/parameter_learning.rs b/tests/parameter_learning.rs index 1ce5d51..b624e94 100644 --- a/tests/parameter_learning.rs +++ b/tests/parameter_learning.rs @@ -1,3 +1,5 @@ +#![allow(non_snake_case)] + mod utils; use utils::*; @@ -6,9 +8,7 @@ use reCTBN::ctbn::*; use reCTBN::network::Network; use reCTBN::parameter_learning::*; use reCTBN::{params, tools::*}; -use std::collections::BTreeSet; -#[macro_use] extern crate approx; fn learn_binary_cim(pl: T) { diff --git a/tests/params.rs b/tests/params.rs index c002d7b..e07121c 100644 --- a/tests/params.rs +++ b/tests/params.rs @@ -7,8 +7,8 @@ mod utils; #[macro_use] extern crate approx; - fn create_ternary_discrete_time_continous_param() -> DiscreteStatesContinousTimeParams { + #![allow(unused_must_use)] let mut params = utils::generate_discrete_time_continous_params("A".to_string(), 3); let cim = array![[[-3.0, 2.0, 1.0], [1.0, -5.0, 4.0], [2.3, 1.7, -4.0]]]; @@ -25,6 +25,7 @@ fn test_get_label() { #[test] fn test_uniform_generation() { + #![allow(irrefutable_let_patterns)] let param = create_ternary_discrete_time_continous_param(); let mut states = Array1::::zeros(10000); @@ -44,6 +45,7 @@ fn test_uniform_generation() { #[test] fn test_random_generation_state() { + #![allow(irrefutable_let_patterns)] let param = create_ternary_discrete_time_continous_param(); let mut states = Array1::::zeros(10000); diff --git a/tests/structure_learning.rs b/tests/structure_learning.rs index 2c9645b..790a4b6 100644 --- a/tests/structure_learning.rs +++ b/tests/structure_learning.rs @@ -1,3 +1,5 @@ +#![allow(non_snake_case)] + mod utils; use utils::*; @@ -95,7 +97,7 @@ fn check_compatibility_between_dataset_and_network params::Params { params::Params::DiscreteStatesContinousTime(generate_discrete_time_continous_params(label, cardinality)) } - pub fn generate_discrete_time_continous_params(label: String, cardinality: usize) -> params::DiscreteStatesContinousTimeParams{ let domain: BTreeSet = (0..cardinality).map(|x| x.to_string()).collect(); params::DiscreteStatesContinousTimeParams::new(label, domain) } - - - - -