From 6d42d8a805c493aad5dcbdd63a4fad4bb638646c Mon Sep 17 00:00:00 2001 From: meliurwen Date: Mon, 19 Dec 2022 12:54:08 +0100 Subject: [PATCH] Solved issue with `candidate_parent_set` variable in CTPC and added loop to fill the adjacency matrix --- .../constraint_based_algorithm.rs | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/reCTBN/src/structure_learning/constraint_based_algorithm.rs b/reCTBN/src/structure_learning/constraint_based_algorithm.rs index 6fd5b79..d94c793 100644 --- a/reCTBN/src/structure_learning/constraint_based_algorithm.rs +++ b/reCTBN/src/structure_learning/constraint_based_algorithm.rs @@ -48,6 +48,7 @@ impl StructureLearningAlgorithm for CTPC

{ .collect(); let mut b = 0; while b < candidate_parent_set.len() { + let mut not_parent_node: usize = child_node; for parent_node in candidate_parent_set.iter() { for separation_set in candidate_parent_set .iter() @@ -62,16 +63,30 @@ impl StructureLearningAlgorithm for CTPC

{ *parent_node, &separation_set, &mut self.cache, - ) && self.Chi2test.call(&net, child_node, *parent_node, &separation_set, &mut self.cache) { - candidate_parent_set.remove(&parent_node); + ) && self.Chi2test.call( + &net, + child_node, + *parent_node, + &separation_set, + &mut self.cache, + ) { + not_parent_node = parent_node.clone(); break; } } + if not_parent_node != child_node { + break; + } + } + if not_parent_node != child_node { + candidate_parent_set.remove(¬_parent_node); } b = b + 1; } + for parent_node in candidate_parent_set.iter() { + net.add_edge(*parent_node, child_node); + } } - net } }