content: package eu.amidst.core.examples.huginlink;
  
  import eu.amidst.core.inference.InferenceAlgorithm;
  import eu.amidst.core.io.BayesianNetworkLoader;
  import eu.amidst.core.models.BayesianNetwork;
  import eu.amidst.core.variables.Assignment;
  import eu.amidst.core.variables.HashMapAssignment;
  import eu.amidst.core.variables.Variable;
  import eu.amidst.huginlink.inference.HuginInference;
  
  import java.io.IOException;
  
  /**
   * Created by rcabanas on 24/06/16.
   */
  public class HuginInferenceExample {
      public static void main(String[] args) throws IOException, ClassNotFoundException {
          //We first load the WasteIncinerator bayesian network
          //which has multinomial and Gaussian variables.
          BayesianNetwork bn = BayesianNetworkLoader.loadFromFile("./networks/simulated/WasteIncinerator.bn");
  
          //We recover the relevant variables for this example:
          //Mout which is normally distributed, and W which is multinomial.
          Variable varMout = bn.getVariables().getVariableByName("Mout");
          Variable varW = bn.getVariables().getVariableByName("W");
  
          //First we create an instance of a inference algorithm.
          //In this case, we use the ImportanceSampling class.
          InferenceAlgorithm inferenceAlgorithm = new HuginInference();
  
          //Then, we set the BN model
          inferenceAlgorithm.setModel(bn);
  
          //If exists, we also set the evidence.
          Assignment assignment = new HashMapAssignment(1);
          assignment.setValue(varW, 0);
          inferenceAlgorithm.setEvidence(assignment);
  
          //Then we run inference
          inferenceAlgorithm.runInference();
  
          //Then we query the posterior of
          System.out.println("P(Mout|W=0) = " + inferenceAlgorithm.getPosterior(varMout));
  
          //Or some more refined queries
          System.out.println("P(0.7<Mout<3.5 | W=0) = "
                  + inferenceAlgorithm.getExpectedValue(varMout, v -> (0.7 < v && v < 3.5) ? 1.0 : 0.0));
  
      }
  }
  