use of org.drools.beliefs.graph.GraphNode in project drools by kiegroup.
the class JunctionTreeBuilderTest method testSepSetCompareWithDifferentMass.
@Test
public void testSepSetCompareWithDifferentMass() {
Graph<BayesVariable> graph = new BayesNetwork();
GraphNode x0 = addNode(graph);
GraphNode x1 = addNode(graph);
GraphNode x2 = addNode(graph);
GraphNode x3 = addNode(graph);
GraphNode x4 = addNode(graph);
GraphNode x5 = addNode(graph);
GraphNode x6 = addNode(graph);
OpenBitSet OpenBitSet1_1 = bitSet("00001110");
OpenBitSet OpenBitSet1_2 = bitSet("01101100");
SeparatorSet s1 = new SeparatorSet(OpenBitSet1_1, 0, OpenBitSet1_2, 0, graph);
OpenBitSet OpenBitSet2_1 = bitSet("00001110");
OpenBitSet OpenBitSet2_2 = bitSet("00100100");
SeparatorSet s2 = new SeparatorSet(OpenBitSet2_1, 0, OpenBitSet2_2, 0, graph);
List<SeparatorSet> list = new ArrayList<SeparatorSet>();
list.add(s1);
list.add(s2);
Collections.sort(list);
assertEquals(s1, list.get(0));
}
use of org.drools.beliefs.graph.GraphNode in project drools by kiegroup.
the class JunctionTreeBuilderTest method testJunctionTree.
@Test
public void testJunctionTree() {
Graph<BayesVariable> graph = new BayesNetwork();
GraphNode x0 = addNode(graph);
GraphNode x1 = addNode(graph);
GraphNode x2 = addNode(graph);
GraphNode x3 = addNode(graph);
GraphNode x4 = addNode(graph);
GraphNode x5 = addNode(graph);
GraphNode x6 = addNode(graph);
OpenBitSet OpenBitSet1 = bitSet("00001110");
OpenBitSet OpenBitSet2 = bitSet("00011100");
OpenBitSet OpenBitSet3 = bitSet("00110000");
OpenBitSet OpenBitSet4 = bitSet("01110000");
List<OpenBitSet> cliques = new ArrayList<OpenBitSet>();
cliques.add(OpenBitSet1);
cliques.add(OpenBitSet2);
cliques.add(OpenBitSet3);
cliques.add(OpenBitSet4);
List<SeparatorSet> separatorSets = new ArrayList<SeparatorSet>();
for (int i = 0; i < cliques.size(); i++) {
OpenBitSet ci = cliques.get(i);
for (int j = i + 1; j < cliques.size(); j++) {
OpenBitSet cj = cliques.get(j);
if (ci.intersects(cj)) {
SeparatorSet separatorSet = new SeparatorSet(ci, 0, cj, 0, graph);
}
}
}
Collections.sort(separatorSets);
}
use of org.drools.beliefs.graph.GraphNode in project drools by kiegroup.
the class JunctionTreeBuilderTest method testEliminationCandidate1.
@Test
public void testEliminationCandidate1() {
Graph<BayesVariable> graph = new BayesNetwork();
GraphNode x0 = addNode(graph);
GraphNode x1 = addNode(graph);
GraphNode x2 = addNode(graph);
GraphNode x3 = addNode(graph);
GraphNode x4 = addNode(graph);
connectParentToChildren(x1, x2, x3, x4);
JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder(graph);
jtBuilder.moralize();
EliminationCandidate vt1 = new EliminationCandidate(graph, jtBuilder.getAdjacencyMatrix(), x1);
assertEquals(3, vt1.getNewEdgesRequired());
assertEquals(bitSet("11110"), vt1.getCliqueBitSit());
}
use of org.drools.beliefs.graph.GraphNode in project drools by kiegroup.
the class JunctionTreeBuilderTest method testTriangulate1.
@Test
public void testTriangulate1() {
Graph<BayesVariable> graph = new BayesNetwork();
GraphNode x0 = addNode(graph);
GraphNode x1 = addNode(graph);
GraphNode x2 = addNode(graph);
GraphNode x3 = addNode(graph);
GraphNode x4 = addNode(graph);
GraphNode x5 = addNode(graph);
GraphNode x6 = addNode(graph);
// *
// / | \
// * | *
// | | |
// * | *
// \ /
// *
connectParentToChildren(x1, x2);
connectParentToChildren(x1, x3);
connectParentToChildren(x1, x6);
connectParentToChildren(x2, x4);
connectParentToChildren(x3, x5);
connectParentToChildren(x4, x6);
connectParentToChildren(x5, x6);
JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder(graph);
jtBuilder.moralize();
jtBuilder.triangulate();
// assert all new edges
assertLinkedVertex(jtBuilder.getAdjacencyMatrix(), new int[] { 1, 2, 3, 4, 5, 6 });
assertLinkedVertex(jtBuilder.getAdjacencyMatrix(), new int[] { 2, 1, 4 });
assertLinkedVertex(jtBuilder.getAdjacencyMatrix(), new int[] { 3, 1, 5 });
assertLinkedVertex(jtBuilder.getAdjacencyMatrix(), new int[] { 4, 1, 2, 5, 6 });
assertLinkedVertex(jtBuilder.getAdjacencyMatrix(), new int[] { 5, 1, 3, 4, 6 });
assertLinkedVertex(jtBuilder.getAdjacencyMatrix(), new int[] { 6, 1, 4, 5 });
}
use of org.drools.beliefs.graph.GraphNode in project drools by kiegroup.
the class JunctionTreeBuilderTest method testJunctionTreeNoPruning.
@Test
public void testJunctionTreeNoPruning() {
Graph<BayesVariable> graph = new BayesNetwork();
GraphNode x0 = addNode(graph);
GraphNode x1 = addNode(graph);
GraphNode x2 = addNode(graph);
GraphNode x3 = addNode(graph);
GraphNode x4 = addNode(graph);
GraphNode x5 = addNode(graph);
GraphNode x6 = addNode(graph);
GraphNode x7 = addNode(graph);
List<OpenBitSet> list = new ArrayList<OpenBitSet>();
OpenBitSet OpenBitSet1 = bitSet("00001111");
OpenBitSet OpenBitSet2 = bitSet("00111100");
// linear
OpenBitSet OpenBitSet3 = bitSet("11100000");
OpenBitSet intersect1And2 = ((OpenBitSet) OpenBitSet2.clone());
intersect1And2.and(OpenBitSet1);
OpenBitSet intersect2And3 = ((OpenBitSet) OpenBitSet2.clone());
intersect2And3.and(OpenBitSet3);
list.add(OpenBitSet1);
list.add(OpenBitSet2);
list.add(OpenBitSet3);
JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder(graph);
JunctionTreeClique jtNode = jtBuilder.junctionTree(list, false).getRoot();
assertEquals(OpenBitSet1, jtNode.getBitSet());
assertEquals(1, jtNode.getChildren().size());
JunctionTreeSeparator sep = jtNode.getChildren().get(0);
assertEquals(OpenBitSet1, sep.getParent().getBitSet());
assertEquals(OpenBitSet2, sep.getChild().getBitSet());
assertEquals(intersect1And2, sep.getBitSet());
jtNode = sep.getChild();
assertEquals(OpenBitSet2, jtNode.getBitSet());
assertEquals(1, jtNode.getChildren().size());
sep = jtNode.getChildren().get(0);
assertEquals(OpenBitSet2, sep.getParent().getBitSet());
assertEquals(OpenBitSet3, sep.getChild().getBitSet());
assertEquals(intersect2And3, sep.getBitSet());
}
Aggregations