|
|
@ -1,20 +1,16 @@ |
|
|
|
mod utils; |
|
|
|
mod utils; |
|
|
|
use utils::*; |
|
|
|
use utils::*; |
|
|
|
|
|
|
|
|
|
|
|
use reCTBN::parameter_learning::*; |
|
|
|
use ndarray::arr3; |
|
|
|
use reCTBN::ctbn::*; |
|
|
|
use reCTBN::ctbn::*; |
|
|
|
use reCTBN::network::Network; |
|
|
|
use reCTBN::network::Network; |
|
|
|
use reCTBN::node; |
|
|
|
use reCTBN::parameter_learning::*; |
|
|
|
use reCTBN::params; |
|
|
|
use reCTBN::{params, tools::*}; |
|
|
|
use reCTBN::tools::*; |
|
|
|
|
|
|
|
use ndarray::arr3; |
|
|
|
|
|
|
|
use std::collections::BTreeSet; |
|
|
|
use std::collections::BTreeSet; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[macro_use] |
|
|
|
#[macro_use] |
|
|
|
extern crate approx; |
|
|
|
extern crate approx; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn learn_binary_cim<T: ParameterLearning>(pl: T) { |
|
|
|
fn learn_binary_cim<T: ParameterLearning>(pl: T) { |
|
|
|
let mut net = CtbnNetwork::new(); |
|
|
|
let mut net = CtbnNetwork::new(); |
|
|
|
let n1 = net |
|
|
|
let n1 = net |
|
|
@ -25,29 +21,32 @@ fn learn_binary_cim<T: ParameterLearning> (pl: T) { |
|
|
|
.unwrap(); |
|
|
|
.unwrap(); |
|
|
|
net.add_edge(n1, n2); |
|
|
|
net.add_edge(n1, n2); |
|
|
|
|
|
|
|
|
|
|
|
match &mut net.get_node_mut(n1).params { |
|
|
|
match &mut net.get_node_mut(n1) { |
|
|
|
params::Params::DiscreteStatesContinousTime(param) => { |
|
|
|
params::Params::DiscreteStatesContinousTime(param) => { |
|
|
|
assert_eq!(Ok(()), param.set_cim(arr3(&[[[-3.0, 3.0], [2.0, -2.0]]]))); |
|
|
|
assert_eq!(Ok(()), param.set_cim(arr3(&[[[-3.0, 3.0], [2.0, -2.0]]]))); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
match &mut net.get_node_mut(n2).params { |
|
|
|
match &mut net.get_node_mut(n2) { |
|
|
|
params::Params::DiscreteStatesContinousTime(param) => { |
|
|
|
params::Params::DiscreteStatesContinousTime(param) => { |
|
|
|
assert_eq!(Ok(()), param.set_cim(arr3(&[ |
|
|
|
assert_eq!( |
|
|
|
|
|
|
|
Ok(()), |
|
|
|
|
|
|
|
param.set_cim(arr3(&[ |
|
|
|
[[-1.0, 1.0], [4.0, -4.0]], |
|
|
|
[[-1.0, 1.0], [4.0, -4.0]], |
|
|
|
[[-6.0, 6.0], [2.0, -2.0]], |
|
|
|
[[-6.0, 6.0], [2.0, -2.0]], |
|
|
|
]))); |
|
|
|
])) |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let data = trajectory_generator(&net, 100, 100.0, Some(6347747169756259),); |
|
|
|
let data = trajectory_generator(&net, 100, 100.0, Some(6347747169756259)); |
|
|
|
let (CIM, M, T) = pl.fit(&net, &data, 1, None); |
|
|
|
let (CIM, M, T) = pl.fit(&net, &data, 1, None); |
|
|
|
print!("CIM: {:?}\nM: {:?}\nT: {:?}\n", CIM, M, T); |
|
|
|
print!("CIM: {:?}\nM: {:?}\nT: {:?}\n", CIM, M, T); |
|
|
|
assert_eq!(CIM.shape(), [2, 2, 2]); |
|
|
|
assert_eq!(CIM.shape(), [2, 2, 2]); |
|
|
|
assert!(CIM.abs_diff_eq(&arr3(&[ |
|
|
|
assert!(CIM.abs_diff_eq( |
|
|
|
[[-1.0, 1.0], [4.0, -4.0]], |
|
|
|
&arr3(&[[[-1.0, 1.0], [4.0, -4.0]], [[-6.0, 6.0], [2.0, -2.0]],]), |
|
|
|
[[-6.0, 6.0], [2.0, -2.0]], |
|
|
|
0.1 |
|
|
|
]), 0.1)); |
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
@ -56,12 +55,9 @@ fn learn_binary_cim_MLE() { |
|
|
|
learn_binary_cim(mle); |
|
|
|
learn_binary_cim(mle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn learn_binary_cim_BA() { |
|
|
|
fn learn_binary_cim_BA() { |
|
|
|
let ba = BayesianApproach{ |
|
|
|
let ba = BayesianApproach { alpha: 1, tau: 1.0 }; |
|
|
|
alpha: 1, |
|
|
|
|
|
|
|
tau: 1.0}; |
|
|
|
|
|
|
|
learn_binary_cim(ba); |
|
|
|
learn_binary_cim(ba); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -75,48 +71,55 @@ fn learn_ternary_cim<T: ParameterLearning> (pl: T) { |
|
|
|
.unwrap(); |
|
|
|
.unwrap(); |
|
|
|
net.add_edge(n1, n2); |
|
|
|
net.add_edge(n1, n2); |
|
|
|
|
|
|
|
|
|
|
|
match &mut net.get_node_mut(n1).params { |
|
|
|
match &mut net.get_node_mut(n1) { |
|
|
|
params::Params::DiscreteStatesContinousTime(param) => { |
|
|
|
params::Params::DiscreteStatesContinousTime(param) => { |
|
|
|
assert_eq!(Ok(()), param.set_cim(arr3(&[[[-3.0, 2.0, 1.0],
|
|
|
|
assert_eq!( |
|
|
|
|
|
|
|
Ok(()), |
|
|
|
|
|
|
|
param.set_cim(arr3(&[[ |
|
|
|
|
|
|
|
[-3.0, 2.0, 1.0], |
|
|
|
[1.5, -2.0, 0.5], |
|
|
|
[1.5, -2.0, 0.5], |
|
|
|
[0.4, 0.6, -1.0]]]))); |
|
|
|
[0.4, 0.6, -1.0] |
|
|
|
|
|
|
|
]])) |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
match &mut net.get_node_mut(n2).params { |
|
|
|
match &mut net.get_node_mut(n2) { |
|
|
|
params::Params::DiscreteStatesContinousTime(param) => { |
|
|
|
params::Params::DiscreteStatesContinousTime(param) => { |
|
|
|
assert_eq!(Ok(()), param.set_cim(arr3(&[ |
|
|
|
assert_eq!( |
|
|
|
|
|
|
|
Ok(()), |
|
|
|
|
|
|
|
param.set_cim(arr3(&[ |
|
|
|
[[-1.0, 0.5, 0.5], [3.0, -4.0, 1.0], [0.9, 0.1, -1.0]], |
|
|
|
[[-1.0, 0.5, 0.5], [3.0, -4.0, 1.0], [0.9, 0.1, -1.0]], |
|
|
|
[[-6.0, 2.0, 4.0], [1.5, -2.0, 0.5], [3.0, 1.0, -4.0]], |
|
|
|
[[-6.0, 2.0, 4.0], [1.5, -2.0, 0.5], [3.0, 1.0, -4.0]], |
|
|
|
[[-1.0, 0.1, 0.9], [2.0, -2.5, 0.5], [0.9, 0.1, -1.0]], |
|
|
|
[[-1.0, 0.1, 0.9], [2.0, -2.5, 0.5], [0.9, 0.1, -1.0]], |
|
|
|
]))); |
|
|
|
])) |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let data = trajectory_generator(&net, 100, 200.0, Some(6347747169756259),); |
|
|
|
let data = trajectory_generator(&net, 100, 200.0, Some(6347747169756259)); |
|
|
|
let (CIM, M, T) = pl.fit(&net, &data, 1, None); |
|
|
|
let (CIM, M, T) = pl.fit(&net, &data, 1, None); |
|
|
|
print!("CIM: {:?}\nM: {:?}\nT: {:?}\n", CIM, M, T); |
|
|
|
print!("CIM: {:?}\nM: {:?}\nT: {:?}\n", CIM, M, T); |
|
|
|
assert_eq!(CIM.shape(), [3, 3, 3]); |
|
|
|
assert_eq!(CIM.shape(), [3, 3, 3]); |
|
|
|
assert!(CIM.abs_diff_eq(&arr3(&[ |
|
|
|
assert!(CIM.abs_diff_eq( |
|
|
|
|
|
|
|
&arr3(&[ |
|
|
|
[[-1.0, 0.5, 0.5], [3.0, -4.0, 1.0], [0.9, 0.1, -1.0]], |
|
|
|
[[-1.0, 0.5, 0.5], [3.0, -4.0, 1.0], [0.9, 0.1, -1.0]], |
|
|
|
[[-6.0, 2.0, 4.0], [1.5, -2.0, 0.5], [3.0, 1.0, -4.0]], |
|
|
|
[[-6.0, 2.0, 4.0], [1.5, -2.0, 0.5], [3.0, 1.0, -4.0]], |
|
|
|
[[-1.0, 0.1, 0.9], [2.0, -2.5, 0.5], [0.9, 0.1, -1.0]], |
|
|
|
[[-1.0, 0.1, 0.9], [2.0, -2.5, 0.5], [0.9, 0.1, -1.0]], |
|
|
|
]), 0.1)); |
|
|
|
]), |
|
|
|
|
|
|
|
0.1 |
|
|
|
|
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn learn_ternary_cim_MLE() { |
|
|
|
fn learn_ternary_cim_MLE() { |
|
|
|
let mle = MLE {}; |
|
|
|
let mle = MLE {}; |
|
|
|
learn_ternary_cim(mle); |
|
|
|
learn_ternary_cim(mle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn learn_ternary_cim_BA() { |
|
|
|
fn learn_ternary_cim_BA() { |
|
|
|
let ba = BayesianApproach{ |
|
|
|
let ba = BayesianApproach { alpha: 1, tau: 1.0 }; |
|
|
|
alpha: 1, |
|
|
|
|
|
|
|
tau: 1.0}; |
|
|
|
|
|
|
|
learn_ternary_cim(ba); |
|
|
|
learn_ternary_cim(ba); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -130,50 +133,54 @@ fn learn_ternary_cim_no_parents<T: ParameterLearning> (pl: T) { |
|
|
|
.unwrap(); |
|
|
|
.unwrap(); |
|
|
|
net.add_edge(n1, n2); |
|
|
|
net.add_edge(n1, n2); |
|
|
|
|
|
|
|
|
|
|
|
match &mut net.get_node_mut(n1).params { |
|
|
|
match &mut net.get_node_mut(n1) { |
|
|
|
params::Params::DiscreteStatesContinousTime(param) => { |
|
|
|
params::Params::DiscreteStatesContinousTime(param) => { |
|
|
|
assert_eq!(Ok(()), param.set_cim(arr3(&[[[-3.0, 2.0, 1.0],
|
|
|
|
assert_eq!( |
|
|
|
|
|
|
|
Ok(()), |
|
|
|
|
|
|
|
param.set_cim(arr3(&[[ |
|
|
|
|
|
|
|
[-3.0, 2.0, 1.0], |
|
|
|
[1.5, -2.0, 0.5], |
|
|
|
[1.5, -2.0, 0.5], |
|
|
|
[0.4, 0.6, -1.0]]]))); |
|
|
|
[0.4, 0.6, -1.0] |
|
|
|
|
|
|
|
]])) |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
match &mut net.get_node_mut(n2).params { |
|
|
|
match &mut net.get_node_mut(n2) { |
|
|
|
params::Params::DiscreteStatesContinousTime(param) => { |
|
|
|
params::Params::DiscreteStatesContinousTime(param) => { |
|
|
|
assert_eq!(Ok(()), param.set_cim(arr3(&[ |
|
|
|
assert_eq!( |
|
|
|
|
|
|
|
Ok(()), |
|
|
|
|
|
|
|
param.set_cim(arr3(&[ |
|
|
|
[[-1.0, 0.5, 0.5], [3.0, -4.0, 1.0], [0.9, 0.1, -1.0]], |
|
|
|
[[-1.0, 0.5, 0.5], [3.0, -4.0, 1.0], [0.9, 0.1, -1.0]], |
|
|
|
[[-6.0, 2.0, 4.0], [1.5, -2.0, 0.5], [3.0, 1.0, -4.0]], |
|
|
|
[[-6.0, 2.0, 4.0], [1.5, -2.0, 0.5], [3.0, 1.0, -4.0]], |
|
|
|
[[-1.0, 0.1, 0.9], [2.0, -2.5, 0.5], [0.9, 0.1, -1.0]], |
|
|
|
[[-1.0, 0.1, 0.9], [2.0, -2.5, 0.5], [0.9, 0.1, -1.0]], |
|
|
|
]))); |
|
|
|
])) |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let data = trajectory_generator(&net, 100, 200.0, Some(6347747169756259),); |
|
|
|
let data = trajectory_generator(&net, 100, 200.0, Some(6347747169756259)); |
|
|
|
let (CIM, M, T) = pl.fit(&net, &data, 0, None); |
|
|
|
let (CIM, M, T) = pl.fit(&net, &data, 0, None); |
|
|
|
print!("CIM: {:?}\nM: {:?}\nT: {:?}\n", CIM, M, T); |
|
|
|
print!("CIM: {:?}\nM: {:?}\nT: {:?}\n", CIM, M, T); |
|
|
|
assert_eq!(CIM.shape(), [1, 3, 3]); |
|
|
|
assert_eq!(CIM.shape(), [1, 3, 3]); |
|
|
|
assert!(CIM.abs_diff_eq(&arr3(&[[[-3.0, 2.0, 1.0],
|
|
|
|
assert!(CIM.abs_diff_eq( |
|
|
|
[1.5, -2.0, 0.5], |
|
|
|
&arr3(&[[[-3.0, 2.0, 1.0], [1.5, -2.0, 0.5], [0.4, 0.6, -1.0]]]), |
|
|
|
[0.4, 0.6, -1.0]]]), 0.1)); |
|
|
|
0.1 |
|
|
|
|
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn learn_ternary_cim_no_parents_MLE() { |
|
|
|
fn learn_ternary_cim_no_parents_MLE() { |
|
|
|
let mle = MLE {}; |
|
|
|
let mle = MLE {}; |
|
|
|
learn_ternary_cim_no_parents(mle); |
|
|
|
learn_ternary_cim_no_parents(mle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn learn_ternary_cim_no_parents_BA() { |
|
|
|
fn learn_ternary_cim_no_parents_BA() { |
|
|
|
let ba = BayesianApproach{ |
|
|
|
let ba = BayesianApproach { alpha: 1, tau: 1.0 }; |
|
|
|
alpha: 1, |
|
|
|
|
|
|
|
tau: 1.0}; |
|
|
|
|
|
|
|
learn_ternary_cim_no_parents(ba); |
|
|
|
learn_ternary_cim_no_parents(ba); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn learn_mixed_discrete_cim<T: ParameterLearning>(pl: T) { |
|
|
|
fn learn_mixed_discrete_cim<T: ParameterLearning>(pl: T) { |
|
|
|
let mut net = CtbnNetwork::new(); |
|
|
|
let mut net = CtbnNetwork::new(); |
|
|
|
let n1 = net |
|
|
|
let n1 = net |
|
|
@ -190,61 +197,159 @@ fn learn_mixed_discrete_cim<T: ParameterLearning> (pl: T) { |
|
|
|
net.add_edge(n1, n3); |
|
|
|
net.add_edge(n1, n3); |
|
|
|
net.add_edge(n2, n3); |
|
|
|
net.add_edge(n2, n3); |
|
|
|
|
|
|
|
|
|
|
|
match &mut net.get_node_mut(n1).params { |
|
|
|
match &mut net.get_node_mut(n1) { |
|
|
|
params::Params::DiscreteStatesContinousTime(param) => { |
|
|
|
params::Params::DiscreteStatesContinousTime(param) => { |
|
|
|
assert_eq!(Ok(()), param.set_cim(arr3(&[[[-3.0, 2.0, 1.0],
|
|
|
|
assert_eq!( |
|
|
|
|
|
|
|
Ok(()), |
|
|
|
|
|
|
|
param.set_cim(arr3(&[[ |
|
|
|
|
|
|
|
[-3.0, 2.0, 1.0], |
|
|
|
[1.5, -2.0, 0.5], |
|
|
|
[1.5, -2.0, 0.5], |
|
|
|
[0.4, 0.6, -1.0]]]))); |
|
|
|
[0.4, 0.6, -1.0] |
|
|
|
|
|
|
|
]])) |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
match &mut net.get_node_mut(n2).params { |
|
|
|
match &mut net.get_node_mut(n2) { |
|
|
|
params::Params::DiscreteStatesContinousTime(param) => { |
|
|
|
params::Params::DiscreteStatesContinousTime(param) => { |
|
|
|
assert_eq!(Ok(()), param.set_cim(arr3(&[ |
|
|
|
assert_eq!( |
|
|
|
|
|
|
|
Ok(()), |
|
|
|
|
|
|
|
param.set_cim(arr3(&[ |
|
|
|
[[-1.0, 0.5, 0.5], [3.0, -4.0, 1.0], [0.9, 0.1, -1.0]], |
|
|
|
[[-1.0, 0.5, 0.5], [3.0, -4.0, 1.0], [0.9, 0.1, -1.0]], |
|
|
|
[[-6.0, 2.0, 4.0], [1.5, -2.0, 0.5], [3.0, 1.0, -4.0]], |
|
|
|
[[-6.0, 2.0, 4.0], [1.5, -2.0, 0.5], [3.0, 1.0, -4.0]], |
|
|
|
[[-1.0, 0.1, 0.9], [2.0, -2.5, 0.5], [0.9, 0.1, -1.0]], |
|
|
|
[[-1.0, 0.1, 0.9], [2.0, -2.5, 0.5], [0.9, 0.1, -1.0]], |
|
|
|
]))); |
|
|
|
])) |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
match &mut net.get_node_mut(n3) { |
|
|
|
match &mut net.get_node_mut(n3).params { |
|
|
|
|
|
|
|
params::Params::DiscreteStatesContinousTime(param) => { |
|
|
|
params::Params::DiscreteStatesContinousTime(param) => { |
|
|
|
assert_eq!(Ok(()), param.set_cim(arr3(&[ |
|
|
|
assert_eq!( |
|
|
|
[[-1.0, 0.5, 0.3, 0.2], [0.5, -4.0, 2.5, 1.0], [2.5, 0.5, -4.0, 1.0], [0.7, 0.2, 0.1, -1.0]], |
|
|
|
Ok(()), |
|
|
|
[[-6.0, 2.0, 3.0, 1.0], [1.5, -3.0, 0.5, 1.0], [2.0, 1.3, -5.0 ,1.7], [2.5, 0.5, 1.0, -4.0]], |
|
|
|
param.set_cim(arr3(&[ |
|
|
|
[[-1.3, 0.3, 0.1, 0.9], [1.4, -4.0, 0.5, 2.1], [1.0, 1.5, -3.0, 0.5], [0.4, 0.3, 0.1, -0.8]], |
|
|
|
[ |
|
|
|
|
|
|
|
[-1.0, 0.5, 0.3, 0.2], |
|
|
|
[[-2.0, 1.0, 0.7, 0.3], [1.3, -5.9, 2.7, 1.9], [2.0, 1.5, -4.0, 0.5], [0.2, 0.7, 0.1, -1.0]], |
|
|
|
[0.5, -4.0, 2.5, 1.0], |
|
|
|
[[-6.0, 1.0, 2.0, 3.0], [0.5, -3.0, 1.0, 1.5], [1.4, 2.1, -4.3, 0.8], [0.5, 1.0, 2.5, -4.0]], |
|
|
|
[2.5, 0.5, -4.0, 1.0], |
|
|
|
[[-1.3, 0.9, 0.3, 0.1], [0.1, -1.3, 0.2, 1.0], [0.5, 1.0, -3.0, 1.5], [0.1, 0.4, 0.3, -0.8]], |
|
|
|
[0.7, 0.2, 0.1, -1.0] |
|
|
|
|
|
|
|
], |
|
|
|
[[-2.0, 1.0, 0.6, 0.4], [2.6, -7.1, 1.4, 3.1], [5.0, 1.0, -8.0, 2.0], [1.4, 0.4, 0.2, -2.0]], |
|
|
|
[ |
|
|
|
[[-3.0, 1.0, 1.5, 0.5], [3.0, -6.0, 1.0, 2.0], [0.3, 0.5, -1.9, 1.1], [5.0, 1.0, 2.0, -8.0]], |
|
|
|
[-6.0, 2.0, 3.0, 1.0], |
|
|
|
[[-2.6, 0.6, 0.2, 1.8], [2.0, -6.0, 3.0, 1.0], [0.1, 0.5, -1.3, 0.7], [0.8, 0.6, 0.2, -1.6]], |
|
|
|
[1.5, -3.0, 0.5, 1.0], |
|
|
|
]))); |
|
|
|
[2.0, 1.3, -5.0, 1.7], |
|
|
|
|
|
|
|
[2.5, 0.5, 1.0, -4.0] |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
[-1.3, 0.3, 0.1, 0.9], |
|
|
|
|
|
|
|
[1.4, -4.0, 0.5, 2.1], |
|
|
|
|
|
|
|
[1.0, 1.5, -3.0, 0.5], |
|
|
|
|
|
|
|
[0.4,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
|
|
|
|
|
|
|
[0.1, 0.5, -1.3, 0.7], |
|
|
|
|
|
|
|
[0.8, 0.6, 0.2, -1.6] |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
])) |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let data = trajectory_generator(&net, 300, 300.0, Some(6347747169756259)); |
|
|
|
let data = trajectory_generator(&net, 300, 300.0, Some(6347747169756259),); |
|
|
|
|
|
|
|
let (CIM, M, T) = pl.fit(&net, &data, 2, None); |
|
|
|
let (CIM, M, T) = pl.fit(&net, &data, 2, None); |
|
|
|
print!("CIM: {:?}\nM: {:?}\nT: {:?}\n", CIM, M, T); |
|
|
|
print!("CIM: {:?}\nM: {:?}\nT: {:?}\n", CIM, M, T); |
|
|
|
assert_eq!(CIM.shape(), [9, 4, 4]); |
|
|
|
assert_eq!(CIM.shape(), [9, 4, 4]); |
|
|
|
assert!(CIM.abs_diff_eq(&arr3(&[ |
|
|
|
assert!(CIM.abs_diff_eq( |
|
|
|
[[-1.0, 0.5, 0.3, 0.2], [0.5, -4.0, 2.5, 1.0], [2.5, 0.5, -4.0, 1.0], [0.7, 0.2, 0.1, -1.0]], |
|
|
|
&arr3(&[ |
|
|
|
[[-6.0, 2.0, 3.0, 1.0], [1.5, -3.0, 0.5, 1.0], [2.0, 1.3, -5.0 , 1.7], [2.5, 0.5, 1.0, -4.0]], |
|
|
|
[ |
|
|
|
[[-1.3, 0.3, 0.1, 0.9], [1.4, -4.0, 0.5, 2.1], [1.0, 1.5, -3.0, 0.5], [0.4, 0.3, 0.1, -0.8]], |
|
|
|
[-1.0, 0.5, 0.3, 0.2], |
|
|
|
|
|
|
|
[0.5, -4.0, 2.5, 1.0], |
|
|
|
[[-2.0, 1.0, 0.7, 0.3], [1.3, -5.9, 2.7, 1.9], [2.0, 1.5, -4.0, 0.5], [0.2, 0.7, 0.1, -1.0]], |
|
|
|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[test] |
|
|
@ -253,11 +358,8 @@ fn learn_mixed_discrete_cim_MLE() { |
|
|
|
learn_mixed_discrete_cim(mle); |
|
|
|
learn_mixed_discrete_cim(mle); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
#[test] |
|
|
|
fn learn_mixed_discrete_cim_BA() { |
|
|
|
fn learn_mixed_discrete_cim_BA() { |
|
|
|
let ba = BayesianApproach{ |
|
|
|
let ba = BayesianApproach { alpha: 1, tau: 1.0 }; |
|
|
|
alpha: 1, |
|
|
|
|
|
|
|
tau: 1.0}; |
|
|
|
|
|
|
|
learn_mixed_discrete_cim(ba); |
|
|
|
learn_mixed_discrete_cim(ba); |
|
|
|
} |
|
|
|
} |
|
|
|