//! Test information source location. use cnetworks::*; fn setup_net(c: f64, seed: &str) -> Network { let mut net = Network::with_seed(10, Model::None, Weight::Constant { c }, seed); for (node, targets) in [ (0, vec![1, 3, 4]), (1, vec![0, 2, 4, 5, 9]), (2, vec![1, 9, 8]), (3, vec![0, 4, 7]), (4, vec![0, 3, 6, 7, 5, 1]), (5, vec![1, 4, 7, 8, 9]), (6, vec![3, 7, 4]), (7, vec![4, 3, 6, 5, 8]), (8, vec![7, 5, 2]), (9, vec![1, 5, 2]), ] { for target in targets { net.link(node, target).unwrap(); } } net } #[test] fn test_pearson() { for c in [0.5, 0.75, 1.0] { let net = setup_net(c, "test seed"); let mut observers = si::spread(&net, 5, 10).unwrap(); observers.keep(&[0, 1, 2, 3]); let result = locate::pearson(&net, &observers).unwrap(); let (most_likely, _score) = result.top().unwrap(); dbg!(result); assert!(most_likely == 5); } } #[test] fn test_pinto() { for c in [0.5, 0.75, 1.0] { let net = setup_net(c, "test seed"); let mut observers = si::spread(&net, 5, 10).unwrap(); observers.keep(&[0, 1, 2, 3]); let result = locate::lptv(&net, &observers).unwrap(); let (most_likely, _score) = result.top().unwrap(); assert!(most_likely == 5); } } #[test] #[ignore] fn test_pearson_stats() { let mut acc = 0.0; let size = 100.0; let p = 8.0 / size; for _ in 0..5000 { let net = Network::new( size as usize, Model::ER { p, whole: true }, Weight::default(), ); let mut observers = si::spread(&net, 5, 10).unwrap(); let result = locate::pearson( &net, observers.keep_portion(0.1, &mut *net.rng_lock().unwrap()), ) .unwrap(); acc += result.precision(); } acc /= 5000.0; assert!(acc > 0.95); } #[test] #[ignore] fn test_pinto_stats() { let mut acc = 0.0; let size = 100.0; let p = 8.0 / size; for _ in 0..5000 { let net = Network::new( size as usize, Model::ER { p, whole: true }, Weight::default(), ); let mut observers = si::spread(&net, 5, 10).unwrap(); let result = locate::lptv( &net, observers.keep_portion(0.1, &mut *net.rng_lock().unwrap()), ) .unwrap(); acc += result.precision(); } acc /= 5000.0; dbg!(acc); assert!(acc > 0.95); }