@Test public void test() throws Exception { MAPInferenceExample.main(null); }
public static void main(String[] args) throws Exception { BayesianNetwork bn = BayesianNetworkLoader.loadFromFile("./networks/simulated/WasteIncinerator.bn"); List<Variable> topologicalOrder = Utils.getTopologicalOrder(bn.getDAG()); Variable varMin = bn.getVariables().getVariableByName("Min"); Variable varW = bn.getVariables().getVariableByName("W"); MAPInference mapInference = new MAPInference(); mapInference.setModel(bn); System.out.println(bn.toString()); Assignment assignment = new HashMapAssignment(2); assignment.setValue(varW, 0); assignment.setValue(varMin, 0.15); mapInference.setEvidence(assignment); System.out.println("Evidence: " + assignment.outputString(topologicalOrder) + "\n"); List<Variable> varsInterest = new ArrayList<>(); Variable var1 = bn.getVariables().getVariableByName("B"); Variable var2 = bn.getVariables().getVariableByName("C"); varsInterest.add(var1); varsInterest.add(var2); mapInference.setMAPVariables(varsInterest); System.out.println("Variables of Interest: " + var1.getName() + ", " + var2.getName() + "\n"); mapInference.setParallelMode(true); mapInference.runInference(); System.out.println("MAP = " + mapInference.getEstimate().outputString(topologicalOrder)); System.out.println("P(MAP) = " + Math.exp(mapInference.getLogProbabilityOfEstimate())); }
MAPInferenceExample { public static void main(String[] args) throws Exception { BayesianNetwork bn = BayesianNetworkLoader.loadFromFile("./networks/simulated/WasteIncinerator.bn"); List<Variable> topologicalOrder = Utils.getTopologicalOrder(bn.getDAG()); Variable varMin = bn.getVariables().getVariableByName("Min"); Variable varW = bn.getVariables().getVariableByName("W"); MAPInference mapInference = new MAPInference(); mapInference.setModel(bn); System.out.println(bn.toString()); Assignment assignment = new HashMapAssignment(2); assignment.setValue(varW, 0); assignment.setValue(varMin, 0.15); mapInference.setEvidence(assignment); System.out.println("Evidence: " + assignment.outputString(topologicalOrder) + "\n"); List<Variable> varsInterest = new ArrayList<>(); Variable var1 = bn.getVariables().getVariableByName("B"); Variable var2 = bn.getVariables().getVariableByName("C"); varsInterest.add(var1); varsInterest.add(var2); mapInference.setMAPVariables(varsInterest); System.out.println("Variables of Interest: " + var1.getName() + ", " + var2.getName() + "\n"); mapInference.setParallelMode(true); mapInference.runInference(); System.out.println("MAP = " + mapInference.getEstimate().outputString(topologicalOrder)); System.out.println("P(MAP) = " + Math.exp(mapInference.getLogProbabilityOfEstimate())); } }
MAPInferenceExample { public static void main(String[] args) throws Exception { BayesianNetwork bn = BayesianNetworkLoader.loadFromFile("./networks/simulated/WasteIncinerator.bn"); List<Variable> topologicalOrder = Utils.getTopologicalOrder(bn.getDAG()); Variable varMin = bn.getVariables().getVariableByName("Min"); Variable varW = bn.getVariables().getVariableByName("W"); MAPInference mapInference = new MAPInference(); mapInference.setModel(bn); System.out.println(bn.toString()); Assignment assignment = new HashMapAssignment(2); assignment.setValue(varW, 0); assignment.setValue(varMin, 0.15); mapInference.setEvidence(assignment); System.out.println("Evidence: " + assignment.outputString(topologicalOrder) + "\n"); List<Variable> varsInterest = new ArrayList<>(); Variable var1 = bn.getVariables().getVariableByName("B"); Variable var2 = bn.getVariables().getVariableByName("C"); varsInterest.add(var1); varsInterest.add(var2); mapInference.setMAPVariables(varsInterest); System.out.println("Variables of Interest: " + var1.getName() + ", " + var2.getName() + "\n"); mapInference.setParallelMode(true); mapInference.runInference(); System.out.println("MAP = " + mapInference.getEstimate().outputString(topologicalOrder)); System.out.println("P(MAP) = " + Math.exp(mapInference.getLogProbabilityOfEstimate())); }  }
MAPInferenceExample { public static void main(String[] args) throws Exception { BayesianNetwork bn = BayesianNetworkLoader.loadFromFile("./networks/simulated/WasteIncinerator.bn"); List<Variable> topologicalOrder = Utils.getTopologicalOrder(bn.getDAG()); Variable varMin = bn.getVariables().getVariableByName("Min"); Variable varW = bn.getVariables().getVariableByName("W"); MAPInference mapInference = new MAPInference(); mapInference.setModel(bn); System.out.println(bn.toString()); Assignment assignment = new HashMapAssignment(2); assignment.setValue(varW, 0); assignment.setValue(varMin, 0.15); mapInference.setEvidence(assignment); System.out.println("Evidence: " + assignment.outputString(topologicalOrder) + "\n"); List<Variable> varsInterest = new ArrayList<>(); Variable var1 = bn.getVariables().getVariableByName("B"); Variable var2 = bn.getVariables().getVariableByName("C"); varsInterest.add(var1); varsInterest.add(var2); mapInference.setMAPVariables(varsInterest); System.out.println("Variables of Interest: " + var1.getName() + ", " + var2.getName() + "\n"); mapInference.setParallelMode(true); mapInference.runInference(); System.out.println("MAP = " + mapInference.getEstimate().outputString(topologicalOrder)); System.out.println("P(MAP) = " + Math.exp(mapInference.getLogProbabilityOfEstimate())); }  static void main(String[] args); }
MAPInferenceExample { public static void main(String[] args) throws Exception { BayesianNetwork bn = BayesianNetworkLoader.loadFromFile("./networks/simulated/WasteIncinerator.bn"); List<Variable> topologicalOrder = Utils.getTopologicalOrder(bn.getDAG()); Variable varMin = bn.getVariables().getVariableByName("Min"); Variable varW = bn.getVariables().getVariableByName("W"); MAPInference mapInference = new MAPInference(); mapInference.setModel(bn); System.out.println(bn.toString()); Assignment assignment = new HashMapAssignment(2); assignment.setValue(varW, 0); assignment.setValue(varMin, 0.15); mapInference.setEvidence(assignment); System.out.println("Evidence: " + assignment.outputString(topologicalOrder) + "\n"); List<Variable> varsInterest = new ArrayList<>(); Variable var1 = bn.getVariables().getVariableByName("B"); Variable var2 = bn.getVariables().getVariableByName("C"); varsInterest.add(var1); varsInterest.add(var2); mapInference.setMAPVariables(varsInterest); System.out.println("Variables of Interest: " + var1.getName() + ", " + var2.getName() + "\n"); mapInference.setParallelMode(true); mapInference.runInference(); System.out.println("MAP = " + mapInference.getEstimate().outputString(topologicalOrder)); System.out.println("P(MAP) = " + Math.exp(mapInference.getLogProbabilityOfEstimate())); }  static void main(String[] args);  }