SMILE Tutorial 2: Performing Inference with a Bayesian Network

From DSL
Jump to: navigation, search
  public void CreateNetwork() {
  Network net = new Network();
  
  // Creating node "Success" and setting/adding outcomes:
  int nodeSuccess = net.addNode(Network.NodeType.Cpt, "Success");
  net.setOutcomeId(nodeSuccess, 0, "Success");
  net.setOutcomeId(nodeSuccess, 1, "Failure");
  
  // Creating node "Forecast" and setting/adding outcomes:
  int nodeForecast = net.addNode(Network.NodeType.Cpt, "Forecast");
  net.addOutcome(nodeForecast, "Good");
  net.addOutcome(nodeForecast, "Moderate");
  net.addOutcome(nodeForecast, "Poor");
  net.deleteOutcome(nodeForecast, 0);
  net.deleteOutcome(nodeForecast, 0);
  
  // Adding an arc from "Success" to "Forecast":
  net.addArc(nodeSuccess, nodeForecast);
  
  // Filling in the conditional distribution for node "Success". The 
  // probabilities are:
  // P("Success" = Success) = 0.2
  // P("Success" = Failure) = 0.8
  double[] aSuccessDef = {0.2, 0.8}; 
  net.setNodeDefinition(nodeSuccess, aSuccessDef);
  
  // Filling in the conditional distribution for node "Forecast". The 
  // probabilities are:
  // P("Forecast" = Good | "Success" = Success) = 0.4
  // P("Forecast" = Moderate | "Success" = Success) = 0.4
  // P("Forecast" = Poor | "Success" = Success) = 0.2
  // P("Forecast" = Good | "Success" = Failure) = 0.1
  // P("Forecast" = Moderate | "Success" = Failure) = 0.3
  // P("Forecast" = Poor | "Success" = Failure) = 0.6
  double[] aForecastDef = {0.4, 0.4, 0.2, 0.1, 0.3, 0.6}; 
  net.setNodeDefinition(nodeForecast, aForecastDef);
  
  // Writting the network to a file:
  net.writeFile("tutorial_a.xdsl");
  }
Personal tools