Examples of GraphNode


Examples of org.drools.beliefs.graph.GraphNode


    public void moralize() {
        for (GraphNode<BayesVariable> v : graph ) {
            for ( Edge e1 : v.getInEdges() ) {
                GraphNode pV1 = graph.getNode(e1.getOutGraphNode().getId());
                moralize(v, pV1);
            }
        }
    }
View Full Code Here

Examples of org.drools.beliefs.graph.GraphNode

    }

    public void moralize(GraphNode<BayesVariable> v, GraphNode v1) {
        for ( Edge e2 : v.getInEdges() ) {
            // moralize, by connecting each parent with each other
            GraphNode v2 = graph.getNode(e2.getOutGraphNode().getId());
            if ( v1 == v2 ) {
                continue; // don't connect to itself
            }
            if ( adjacencyMatrix[v1.getId()][v2.getId()] ) {
                // already connected, continue
                continue;
            }
            connect(getAdjacencyMatrix(), v1.getId(), v2.getId());
        }
    }
View Full Code Here

Examples of org.drools.beliefs.graph.GraphNode

    @Test
    public void testMoralize1() {
        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(x2, x1);
        connectParentToChildren(x3, x1);
        connectParentToChildren(x4, x1);
View Full Code Here

Examples of org.drools.beliefs.graph.GraphNode

    @Test
    public void testMoralize2() {
        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, x3);
        connectParentToChildren(x2, x4);
        connectParentToChildren(x4, x5);
        connectParentToChildren(x3, x5);
        connectParentToChildren(x6, x5);

        JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder( graph );
        jtBuilder.moralize();

        assertLinkedNode(jtBuilder, new int[]{x1.getId(), 2, 3});

        assertLinkedNode(jtBuilder, new int[]{x2.getId(), 1, 4});

        assertLinkedNode(jtBuilder, new int[]{x3.getId(), 1, 4, 5, 6});

        assertLinkedNode(jtBuilder, new int[]{x4.getId(), 2, 3, 5, 6});

        assertLinkedNode(jtBuilder, new int[]{x5.getId(), 3, 4, 6});

        assertLinkedNode(jtBuilder, new int[]{x6.getId(), 3, 4, 5});

    }
View Full Code Here

Examples of org.drools.beliefs.graph.GraphNode

    @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();
View Full Code Here

Examples of org.drools.beliefs.graph.GraphNode

    }

    @Test
    public void testEliminationCandidate2() {
        Graph 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);
        connectParentToChildren(x3, x4);

        JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder( graph );
View Full Code Here

Examples of org.drools.beliefs.graph.GraphNode

    @Test
    public void testCreateClique() {
        Graph<BayesVariable> graph = new BayesNetwork();

        GraphNode dX0 = addNode(graph);
        GraphNode dX1 = addNode(graph);
        GraphNode dX2 = addNode(graph);
        GraphNode dX3 = addNode(graph);
        GraphNode dX4 = addNode(graph);
        GraphNode dX5 = addNode(graph);

        connectParentToChildren(dX1, dX2, dX3, dX4);

        JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder( graph );
        // do not moralize, as we want to test just the clique creation through elimination of the provided vertices
View Full Code Here

Examples of org.drools.beliefs.graph.GraphNode

    @Test
    public void testPriorityQueueWithMinimalNewEdges() {
        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);
        GraphNode x8 = addNode(graph);

        GraphNode x9 = addNode(graph);
        GraphNode x10 = addNode(graph);
        GraphNode x11 = addNode(graph);
        GraphNode x12 = addNode(graph);

        // 3 new edges
        connectParentToChildren(x2, x1);
        connectParentToChildren(x3, x1);
        connectParentToChildren(x4, x1);
View Full Code Here

Examples of org.drools.beliefs.graph.GraphNode

    @Test
    public void testPriorityQueueWithMaximalCliqueWeight() {
        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);
        GraphNode x8 = addNode(graph);
        GraphNode x9 = addNode(graph);
        GraphNode x10 = addNode(graph);
        GraphNode x11 = addNode(graph);
        GraphNode x12 = addNode(graph);

        connectParentToChildren(x2, x1);
        connectParentToChildren(x3, x1);
        connectParentToChildren(x4, x1);
        x1.setContent(new BayesVariable<String>("x1", x0.getId(), new String[]{"a", "b"}, new double[][]{{0.1, 0.1}}));
        x2.setContent(new BayesVariable<String>("x2", x0.getId(), new String[]{"a", "b"}, new double[][]{{0.1, 0.1}}));
        x3.setContent(new BayesVariable<String>("x3", x0.getId(), new String[]{"a", "b"}, new double[][]{{0.1, 0.1}}));
        x4.setContent(new BayesVariable<String>("x4", x0.getId(), new String[]{"a", "b"}, new double[][]{{0.1, 0.1}}));

        connectParentToChildren(x6, x5);
        connectParentToChildren(x7, x5);
        connectParentToChildren(x8, x5);
        x5.setContent(new BayesVariable<String>("x5", x0.getId(), new String[]{"a", "b", "c"}, new double[][]{{0.1, 0.1, 0.1}}));
        x6.setContent(new BayesVariable<String>("x6", x0.getId(), new String[]{"a", "b", "c"}, new double[][]{{0.1, 0.1, 0.1}}));
        x7.setContent(new BayesVariable<String>("x7", x0.getId(), new String[]{"a", "b", "c"}, new double[][]{{0.1, 0.1, 0.1}}));
        x8.setContent(new BayesVariable<String>("x8", x0.getId(), new String[]{"a", "b", "c"}, new double[][]{{0.1, 0.1, 0.1}}));


        connectParentToChildren(x10, x9);
        connectParentToChildren(x11, x9);
        connectParentToChildren(x12, x9);
        x9.setContent(new BayesVariable<String>("x9", x0.getId(), new String[]{"a"}, new double[][]{{0.1}}));
        x10.setContent(new BayesVariable<String>("x10", x0.getId(), new String[]{"a"}, new double[][]{{0.1}}));
        x11.setContent(new BayesVariable<String>("x11", x0.getId(), new String[]{"a", "b"}, new double[][]{{0.1, 0.1}}));
        x12.setContent(new BayesVariable<String>("x12", x0.getId(), new String[]{"a", "b"}, new double[][]{{0.1, 0.1}}));

        JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder( graph );
        //jtBuilder.moralize(); // don't moralize, as we want to force a simpler construction for required edges, for the purposes of testing

        PriorityQueue<EliminationCandidate> p = new PriorityQueue<EliminationCandidate>(graph.size());
View Full Code Here

Examples of org.drools.beliefs.graph.GraphNode

    @Test
    public void testIterativeEliminationUsingEdgeAndWeight() {
        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);

        // need to ensure x5 followed by x4 are removed first
        x1.setContent(new BayesVariable<String>("x1", x0.getId(), new String[]{"a", "b", "c", "d", "e", "f"}, new double[][]{{0.1, 0.1, 0.1, 0.1, 0.1, 0.1}}));
        x2.setContent(new BayesVariable<String>("x2", x0.getId(), new String[]{"a", "b"}, new double[][]{{0.1, 0.1}}));
        x3.setContent(new BayesVariable<String>("x3", x0.getId(), new String[]{"a", "b"}, new double[][]{{0.1, 0.1}}));
        x4.setContent(new BayesVariable<String>("x4", x0.getId(), new String[]{"a", "b"}, new double[][]{{0.1, 0.1}}));
        x5.setContent(new BayesVariable<String>("x5", x0.getId(), new String[]{"a"}, new double[][]{{0.1 }}));
        x6.setContent(new BayesVariable<String>("x6", x0.getId(), new String[]{"a", "b"}, new double[][]{{0.1, 0.1}}));


        JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder( graph );
        //jtBuilder.moralize(); // don't moralize, as we want to force a simpler construction for vertex elimination order and updates

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.