Java Tutorial Code 4: Performing Inference in Influence Diagrams
From DSL
(Redirected from Java Code: Tutorial 4: Performing Inference in Influence Diagrams)
public void InferenceWithInfluenceDiagram() {
try {
// Loading and updating the influence diagram:
Network net = new Network();
net.readFile("tutorial_b.xdsl");
net.updateBeliefs();
// Getting the utility node's handle:
net.getNode("Gain");
// Getting the handle and the name of value indexing parent (decision node):
int[] aValueIndexingParents = net.getValueIndexingParents("Gain");
int nodeDecision = aValueIndexingParents[0];
String decisionName = net.getNodeName(nodeDecision);
// Displaying the possible expected values:
System.out.println("These are the expected utilities:");
for (int i = 0; i < net.getOutcomeCount(nodeDecision); i++) {
String parentOutcomeId = net.getOutcomeId(nodeDecision, i);
double expectedUtility = net.getNodeValue("Gain")[i];
System.out.print(" - \"" + decisionName + "\" = " + parentOutcomeId + ": ");
System.out.println("Expected Utility = " + expectedUtility);
}
}
catch (SMILEException e) {
System.out.println(e.getMessage());
}
}
