<< Click to Display Table of Contents >> Navigation: Tutorials > Tutorial 5: Inference in an Influence Diagram |
This tutorial loads the influence diagram created in Tutorial 4. We will perform multiple inference calls and display calculated utilities.
The tutorial starts with now-familiar sequence of redirecting error messages, loading the file and obtaining the handle to the node Financial gain. When we invoke DSL_network::UpdateBeliefs for the first time, the model has no evidence. A local helper function, PrintFinancialGain, is called to print out the utilities.
static void PrintFinancialGain(DSL_network &net, int gainHandle)
{
DSL_node *node = net.GetNode(gainHandle);
const char *nodeName = node->GetName();
printf("%s:\n", nodeName);
const DSL_nodeVal *val = node->Val();
const DSL_Dmatrix &mtx = *val->GetMatrix();
const DSL_intArray &parents = val->GetIndexingParents();
PrintMatrix(net, mtx, "Utility", NULL, parents);
}
The function prints the name of the node specified by its 2nd parameter (which points always to node Financial gain in this tutorial), then prepares the input arguments for the PrintMatrix function: the node value matrix (utilties) and an array with handles of nodes indexing the utilities (these are all uninstantiated decision nodes and all nodes that have not been observed but should have been observed because they have outgoing arcs that enter decision nodes). PrintMatrix in this manual is a slightly modified version of the function from Tutorial 3. The changes are needed to properly display utility matrix with its last dimension set to 1, as utility nodes have no outcomes.
The calculated expected utilities without evidence suggest that we should not invest. Here is the relevant output from our program:
Financial gain:
Utility(Invest=Invest)=-1850
Utility(Invest=DoNotInvest)=500
Next, we model the analyst’s forecast by setting Forecast to Good with DSL_nodeVal::SetEvidence, and recalculate the probabilities and utilities.
res = net.GetNode("Forecast")->Val()->SetEvidence("Good");
Based on the output from the program we should invest:
Financial gain:
Utility(Invest=Invest)=4455.78
Utility(Invest=DoNotInvest)=500
Now we observe the state of the economy and conclude that it is growing. We set the outcome Up as evidence in the Economy node with another DSL_nodeVal::SetEvidence call. Growing economy makes our chances even better:
Financial gain:
Utility(Invest=Invest)=5000
Utility(Invest=DoNotInvest)=500
This concludes Tutorial 5.