@Test public void testFullExample2() { Graph<BayesVariable> graph = new BayesNetwork(); GraphNode xElectricity = addNode(graph); GraphNode xTelecom = addNode(graph); GraphNode xRail = addNode(graph); GraphNode xAirTravel = addNode(graph); GraphNode xTransportation = addNode(graph); GraphNode xUtilities = addNode(graph); GraphNode xUSBanks = addNode(graph); GraphNode xUSStocks = addNode(graph); connectParentToChildren( xElectricity, xRail, xAirTravel, xUtilities, xTelecom ); connectParentToChildren( xTelecom, xUtilities, xUSBanks ); connectParentToChildren( xRail, xTransportation ); connectParentToChildren( xAirTravel, xTransportation ); connectParentToChildren( xUtilities, xUSStocks ); connectParentToChildren( xUSBanks, xUSStocks ); connectParentToChildren( xTransportation, xUSStocks ); OpenBitSet clique1 = bitSet("11110000"); OpenBitSet clique2 = bitSet("01110001"); OpenBitSet clique3 = bitSet("01100011"); OpenBitSet clique4 = bitSet("00011101"); OpenBitSet clique1And2 = bitSet("01110000"); OpenBitSet clique2And3 = bitSet("01100001"); OpenBitSet clique2And4 = bitSet("00010001"); xElectricity.setContent(new BayesVariable<String>("Electricity", xElectricity.getId(), new String[]{"Working", "Reduced", "NotWorking"}, new double[][]{{0.6, 0.3, 0.099}})); xTelecom.setContent(new BayesVariable<String>("Telecom", xTelecom.getId(), new String[]{"Working", "Reduced", "NotWorking"}, new double[][]{{0.544, 0.304, 0.151}})); xRail.setContent(new BayesVariable<String>("Rail", xRail.getId(), new String[]{"Working", "Reduced", "NotWorking"}, new double[][]{{0.579, 0.230, 0.190}})); xAirTravel.setContent(new BayesVariable<String>("AirTravel", xAirTravel.getId(), new String[]{"Working", "Reduced", "NotWorking"}, new double[][]{{0.449, 0.330, 0.219}})); xTransportation.setContent(new BayesVariable<String>("Transportation", xTransportation.getId(), new String[]{"Working", "Moderate", "Severe", "Failure"}, new double[][]{{0.658, 0.167, 0.097, 0.077}})); xUtilities.setContent(new BayesVariable<String>("Utilities", xUtilities.getId(), new String[]{"Working", "Moderate", "Severe", "Failure"}, new double[][]{{0.541, 0.272, 0.097, 0.088}})); xUSBanks.setContent(new BayesVariable<String>("USBanks", xUSBanks.getId(), new String[]{"Working", "Reduced", "NotWorking"}, new double[][]{{0.488, 0.370, 0.141}})); xUSStocks.setContent(new BayesVariable<String>("USStocks", xUSStocks.getId(), new String[]{"Up", "Down", "Crash"}, new double[][]{{0.433, 0.386, 0.179}})); JunctionTreeBuilder jtBuilder = new JunctionTreeBuilder( graph ); JunctionTreeClique root = jtBuilder.build(false).getRoot(); assertEquals( clique1, root.getBitSet() ); assertEquals( 1, root.getChildren().size() ); JunctionTreeSeparator sep = root.getChildren().get(0); assertEquals( clique1And2, sep.getBitSet() ); JunctionTreeClique jtNode2 = sep.getChild(); assertEquals( clique1, sep.getParent().getBitSet() ); assertEquals( clique2, jtNode2.getBitSet() ); assertEquals(2, jtNode2.getChildren().size()); assertSame( sep, jtNode2.getParentSeparator() ); sep = jtNode2.getChildren().get(0); assertEquals( clique2And3, sep.getBitSet() ); JunctionTreeClique jtNode3 = sep.getChild(); assertEquals( clique2, sep.getParent().getBitSet() ); assertEquals( clique3, jtNode3.getBitSet() ); assertEquals(0, jtNode3.getChildren().size()); sep = jtNode2.getChildren().get(1); assertEquals( clique2And4, sep.getBitSet() ); JunctionTreeClique jtNode4 = sep.getChild(); assertEquals( clique2, sep.getParent().getBitSet() ); assertEquals( clique4, jtNode4.getBitSet() ); assertEquals(0, jtNode4.getChildren().size()); }
public JunctionTree build() { return build(true); }
JunctionTreeBuilder { public JunctionTree build() { return build(true); } }
JunctionTreeBuilder { public JunctionTree build() { return build(true); } JunctionTreeBuilder(Graph<BayesVariable> graph); }
JunctionTreeBuilder { public JunctionTree build() { return build(true); } JunctionTreeBuilder(Graph<BayesVariable> graph); Graph<BayesVariable> getGraph(); JunctionTree build(); JunctionTree build(boolean init); JunctionTree build(Resource resource, String namespace, String name); JunctionTree build(Resource resource, String namespace, String name, boolean init); void moralize(); void moralize(GraphNode<BayesVariable> v, GraphNode v1); static void connect(boolean[][] adjMatrix, int v1, int v2); static void disconnect(boolean[][] adjMatrix, int v1, int v2); List<OpenBitSet> triangulate(); void eliminateVertex(PriorityQueue<EliminationCandidate> p, Map<Integer, EliminationCandidate> elmVertMap, boolean[][] clonedAdjMatrix, boolean[] adjList, Set<Integer> verticesToUpdate, EliminationCandidate v); void createClique(int v, boolean[][] clonedAdjMatrix, Set<Integer> verticesToUpdate, boolean[] adjList); static void updateCliques(List<OpenBitSet> cliques, OpenBitSet newClique); boolean[][] getAdjacencyMatrix(); static boolean[][] cloneAdjacencyMarix(boolean[][] src); JunctionTree junctionTree(List<OpenBitSet> cliques, boolean init); JunctionTree junctionTree(Resource resource, String namespace, String name, List<OpenBitSet> cliques, boolean init); void mergeGraphs(SeparatorSet[][][] graphs, SeparatorSet separatorSet); int createJunctionTreeGraph(SeparatorSet[][] sepGraph, JunctionTreeClique parent, JunctionTreeClique[] jtNodes, JunctionTreeSeparator[] jtSeps, int i); void mapNodeToCliqueFamily(OpenBitSet[] varNodeToCliques, JunctionTreeClique[] jtNodes); void mapVarNodeToCliques(OpenBitSet[] nodeToCliques, int id, OpenBitSet clique); static List<Integer> getAdjacentVertices(boolean[][] adjacencyMatrix, int i); }
JunctionTreeBuilder { public JunctionTree build() { return build(true); } JunctionTreeBuilder(Graph<BayesVariable> graph); Graph<BayesVariable> getGraph(); JunctionTree build(); JunctionTree build(boolean init); JunctionTree build(Resource resource, String namespace, String name); JunctionTree build(Resource resource, String namespace, String name, boolean init); void moralize(); void moralize(GraphNode<BayesVariable> v, GraphNode v1); static void connect(boolean[][] adjMatrix, int v1, int v2); static void disconnect(boolean[][] adjMatrix, int v1, int v2); List<OpenBitSet> triangulate(); void eliminateVertex(PriorityQueue<EliminationCandidate> p, Map<Integer, EliminationCandidate> elmVertMap, boolean[][] clonedAdjMatrix, boolean[] adjList, Set<Integer> verticesToUpdate, EliminationCandidate v); void createClique(int v, boolean[][] clonedAdjMatrix, Set<Integer> verticesToUpdate, boolean[] adjList); static void updateCliques(List<OpenBitSet> cliques, OpenBitSet newClique); boolean[][] getAdjacencyMatrix(); static boolean[][] cloneAdjacencyMarix(boolean[][] src); JunctionTree junctionTree(List<OpenBitSet> cliques, boolean init); JunctionTree junctionTree(Resource resource, String namespace, String name, List<OpenBitSet> cliques, boolean init); void mergeGraphs(SeparatorSet[][][] graphs, SeparatorSet separatorSet); int createJunctionTreeGraph(SeparatorSet[][] sepGraph, JunctionTreeClique parent, JunctionTreeClique[] jtNodes, JunctionTreeSeparator[] jtSeps, int i); void mapNodeToCliqueFamily(OpenBitSet[] varNodeToCliques, JunctionTreeClique[] jtNodes); void mapVarNodeToCliques(OpenBitSet[] nodeToCliques, int id, OpenBitSet clique); static List<Integer> getAdjacentVertices(boolean[][] adjacencyMatrix, int i);  }