@Test public void test() throws Exception { StaticModelLearning.main(null); StaticModelInference.main(null); }
public static void main(String[] args) throws IOException, ClassNotFoundException { BayesianNetwork bn = BayesianNetworkLoader.loadFromFile("networks/simulated/exampleBN.bn"); Variables variables = bn.getVariables(); Variable varTarget = variables.getVariableByName("LatentVar1"); Variable varObserved = null; Assignment assignment = new HashMapAssignment(2); varObserved = variables.getVariableByName("Income"); assignment.setValue(varObserved,0.0); InferenceAlgorithm infer = new VMP(); infer.setModel(bn); infer.setEvidence(assignment); infer.runInference(); Distribution p = infer.getPosterior(varTarget); System.out.println("P(LatentVar1|Income=0.0) = "+p); System.out.println("P(0.7<LatentVar1<6.59 |Income=0.0) = " + infer.getExpectedValue(varTarget, v -> (0.7 < v && v < 6.59) ? 1.0 : 0.0 )); }
StaticModelInference { public static void main(String[] args) throws IOException, ClassNotFoundException { BayesianNetwork bn = BayesianNetworkLoader.loadFromFile("networks/simulated/exampleBN.bn"); Variables variables = bn.getVariables(); Variable varTarget = variables.getVariableByName("LatentVar1"); Variable varObserved = null; Assignment assignment = new HashMapAssignment(2); varObserved = variables.getVariableByName("Income"); assignment.setValue(varObserved,0.0); InferenceAlgorithm infer = new VMP(); infer.setModel(bn); infer.setEvidence(assignment); infer.runInference(); Distribution p = infer.getPosterior(varTarget); System.out.println("P(LatentVar1|Income=0.0) = "+p); System.out.println("P(0.7<LatentVar1<6.59 |Income=0.0) = " + infer.getExpectedValue(varTarget, v -> (0.7 < v && v < 6.59) ? 1.0 : 0.0 )); } }
StaticModelInference { public static void main(String[] args) throws IOException, ClassNotFoundException { BayesianNetwork bn = BayesianNetworkLoader.loadFromFile("networks/simulated/exampleBN.bn"); Variables variables = bn.getVariables(); Variable varTarget = variables.getVariableByName("LatentVar1"); Variable varObserved = null; Assignment assignment = new HashMapAssignment(2); varObserved = variables.getVariableByName("Income"); assignment.setValue(varObserved,0.0); InferenceAlgorithm infer = new VMP(); infer.setModel(bn); infer.setEvidence(assignment); infer.runInference(); Distribution p = infer.getPosterior(varTarget); System.out.println("P(LatentVar1|Income=0.0) = "+p); System.out.println("P(0.7<LatentVar1<6.59 |Income=0.0) = " + infer.getExpectedValue(varTarget, v -> (0.7 < v && v < 6.59) ? 1.0 : 0.0 )); }  }
StaticModelInference { public static void main(String[] args) throws IOException, ClassNotFoundException { BayesianNetwork bn = BayesianNetworkLoader.loadFromFile("networks/simulated/exampleBN.bn"); Variables variables = bn.getVariables(); Variable varTarget = variables.getVariableByName("LatentVar1"); Variable varObserved = null; Assignment assignment = new HashMapAssignment(2); varObserved = variables.getVariableByName("Income"); assignment.setValue(varObserved,0.0); InferenceAlgorithm infer = new VMP(); infer.setModel(bn); infer.setEvidence(assignment); infer.runInference(); Distribution p = infer.getPosterior(varTarget); System.out.println("P(LatentVar1|Income=0.0) = "+p); System.out.println("P(0.7<LatentVar1<6.59 |Income=0.0) = " + infer.getExpectedValue(varTarget, v -> (0.7 < v && v < 6.59) ? 1.0 : 0.0 )); }  static void main(String[] args); }
StaticModelInference { public static void main(String[] args) throws IOException, ClassNotFoundException { BayesianNetwork bn = BayesianNetworkLoader.loadFromFile("networks/simulated/exampleBN.bn"); Variables variables = bn.getVariables(); Variable varTarget = variables.getVariableByName("LatentVar1"); Variable varObserved = null; Assignment assignment = new HashMapAssignment(2); varObserved = variables.getVariableByName("Income"); assignment.setValue(varObserved,0.0); InferenceAlgorithm infer = new VMP(); infer.setModel(bn); infer.setEvidence(assignment); infer.runInference(); Distribution p = infer.getPosterior(varTarget); System.out.println("P(LatentVar1|Income=0.0) = "+p); System.out.println("P(0.7<LatentVar1<6.59 |Income=0.0) = " + infer.getExpectedValue(varTarget, v -> (0.7 < v && v < 6.59) ? 1.0 : 0.0 )); }  static void main(String[] args);  }