<< Click to Display Table of Contents >> Navigation: Tutorials > Tutorial 5: Inference in an Influence Diagram |
This tutorial loads the influence diagram that we have created in Tutorial 4. We will perform multiple inference calls and display calculated utilities.
With model loaded, we calculate the probabilities and utilities by calling Network.updateBeliefs. A helper function, printFinancialGain, is called to print out the utilities stored in the Gain node. printFinancialGain uses Network.getNodeValue to obtain the utilities. To properly interpret the utilities, we also need to call Network.getValueIndexingParents, which is an array containing the handles of decision nodes not set to evidence.
Java:
double[] expectedUtility = net.getNodeValue("Gain");
int[] utilParents = net.getValueIndexingParents("Gain");
printGainMatrix(net, expectedUtility, utilParents);
Python:
expected_utility = net.get_node_value("Gain")
util_parents = net.get_value_indexing_parents("Gain")
self.print_gain_matrix(net, expected_utility, util_parents)
C#:
double[] expectedUtility = net.GetNodeValue("Gain");
int[] utilParents = net.GetValueIndexingParents("Gain");
printGainMatrix(net, expectedUtility, utilParents);
printGainMatrix is a modification of printCptMatrix from Tutorial 3. It iterates over the elements of an array and converts the linear index into multi-dimensional coordinates.
When we call printGainMatrix for the first time, the network has no evidence set. The utilities calculated without evidence suggest that we should not invest - here's what is printed on the screen:
Financial gain:
Utility(Invest=Invest)=-1850
Utility(Invest=DoNotInvest)=500
Next, we model the analyst’s forecast to be good by calling local helper function changeEvidenceAndUpdate, which is based on the function with the same name from Tutorial 2.
Java:
changeEvidenceAndUpdate(net, "Forecast", "Good");
Python:
self.change_evidence_and_update(net, "Forecast", "Good")
C#:
ChangeEvidenceAndUpdate(net, "Forecast", "Good");
The expected gain changes, now the optimal decision is to 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 - the program performs another changeEvidenceAndUpdate call . Growing economy makes our chances even better:
Financial gain:
Utility(Invest=Invest)=5000
Utility(Invest=DoNotInvest)=500
This concludes Tutorial 5.