Fix for clippy

pull/73/head
AlessandroBregoli 2 years ago
parent 4a7a8c5fba
commit 28ed1a40b3
  1. 2
      reCTBN/src/lib.rs
  2. 13
      reCTBN/src/process/ctbn.rs
  3. 60
      reCTBN/src/process/ctmp.rs
  4. 2
      reCTBN/src/sampling.rs
  5. 2
      reCTBN/src/structure_learning/hypothesis_test.rs
  6. 2
      reCTBN/src/structure_learning/score_function.rs
  7. 2
      reCTBN/src/tools.rs
  8. 4
      reCTBN/tests/ctbn.rs
  9. 6
      reCTBN/tests/ctmp.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;

@ -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<StateType> = next_state
.iter()
.map(|x| StateType::Discrete(*x))
.collect();
let next_state_statetype: Vec<StateType> =
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;
}

@ -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<Params>
param: Option<Params>,
}
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<usize> {
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<crate::params::StateType>)
-> usize {
fn get_param_index_network(
&self,
node: usize,
current_state: &Vec<crate::params::StateType>,
) -> 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<crate::params::StateType>,
parent_set: &std::collections::BTreeSet<usize>,
_current_state: &Vec<crate::params::StateType>,
_parent_set: &std::collections::BTreeSet<usize>,
) -> usize {
unimplemented!("CtmpProcess has only one node")
}
fn get_parent_set(&self, node: usize) -> std::collections::BTreeSet<usize> {
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<usize> {
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"),
}
}
}

@ -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;

@ -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<T, P>(

@ -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<T>(

@ -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<f64>,

@ -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]

@ -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);
}

Loading…
Cancel
Save