Search in sources :

Example 11 with GraphNode

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));
}
Also used : OpenBitSet(org.drools.core.util.bitmask.OpenBitSet) ArrayList(java.util.ArrayList) GraphNode(org.drools.beliefs.graph.GraphNode) Test(org.junit.Test)

Example 12 with GraphNode

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);
}
Also used : OpenBitSet(org.drools.core.util.bitmask.OpenBitSet) ArrayList(java.util.ArrayList) GraphNode(org.drools.beliefs.graph.GraphNode) Test(org.junit.Test)

Example 13 with GraphNode

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());
}
Also used : GraphNode(org.drools.beliefs.graph.GraphNode) Test(org.junit.Test)

Example 14 with GraphNode

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 });
}
Also used : GraphNode(org.drools.beliefs.graph.GraphNode) Test(org.junit.Test)

Example 15 with GraphNode

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());
}
Also used : OpenBitSet(org.drools.core.util.bitmask.OpenBitSet) ArrayList(java.util.ArrayList) GraphNode(org.drools.beliefs.graph.GraphNode) Test(org.junit.Test)

Aggregations

GraphNode (org.drools.beliefs.graph.GraphNode)39 Test (org.junit.Test)32 OpenBitSet (org.drools.core.util.bitmask.OpenBitSet)13 ArrayList (java.util.ArrayList)8 EdgeImpl (org.drools.beliefs.graph.impl.EdgeImpl)4 PriorityQueue (java.util.PriorityQueue)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 BayesNetwork (org.drools.beliefs.bayes.BayesNetwork)2 BayesVariable (org.drools.beliefs.bayes.BayesVariable)2 Edge (org.drools.beliefs.graph.Edge)2 Bif (org.drools.beliefs.bayes.model.Bif)1 Graph (org.drools.beliefs.graph.Graph)1