C Sharp Tutorials: Tutorial 4: Performing Inference in Influence Diagrams
From DSL
In this tutorial we will find out how to compute the expected utilities of the different policies of our influence diagram. We will show where to find and how to interpret the results.
Let's load and update the influence diagram created in the last tutorial.
Network net = new Network();
net.ReadFile("tutorial_b.xdsl");
net.UpdateBeliefs();
The question is: what is the expected utility of investing? What about not investing? We will find the numbers in the utility node Gain. Let us get the results in exactly the same way that we did in previous examples. One thing to notice is that, when dealing with influence diagrams, the value of every node is "indexed" by the choices of every decision node that affects it. In this case, the value of the node Gain is indexed by the choices of the node Invest (as may seem evident). We will use GetValueIndexingParents() method. It will return a list with the handles of the nodes that index this value. In the present case, the list will contain only one handle: the handle of the node Invest.
Once again, there is only one decision node in our diagram that indexes the interesting utility node's value. That is why GetValueIndexingParents() method will return a single-valued array. We will store the handle of that decision node together with its name.
int[] aValueIndexingParents = net.gGetValueIndexingParents("Gain");
int nodeDecision = aValueIndexingParents[0];
String decisionName = net.GetNodeName(nodeDecision);
Note, that we retrieved a handle of the decision node (nodeDecision variable).
Now we are ready to display the possible expected utilities. To do that we will iterate through all the outcomes of the Invest node. We will use those outcomes' indices to read the corresponding expected value. Note that the Gain node's value is a vector.
Console.WriteLine("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];
Console.Write(" - \"" + decisionName + "\" = " + parentOutcomeId + ": ");
Console.WriteLine("Expected Utility = " + expectedUtility);
}
The best policy is, evidently, the one that yields the highest expected utility.
