Inference: an Overview


Introduction

MSBN3's primary task is inference, in other words, when told some things about the world it estimates the probability of other things in the world. It can also recommend what additional information would be most valuable.

This overview illustrates inference by annotating a simple Visual Basic program. The full program is available in Samples\VB\Inference.bas.

Loading a Model and Accessing Its Inference Engine

Here we load a model for troubleshooting car problems. A model's inference engine is available from its Engine property.

Dim aMSBN As New MSBN3Lib.MSBN
'Load the Auto model
Dim modelAuto As MSBN3Lib.Model
Set modelAuto = aMSBN.Models.Add("Auto", FileName:="auto.dsc", ErrorFilename:="loaderror.log")
'Call the model's inference engine "inferAuto"
Dim inferAuto As MSBN3Lib.Engine
Set inferAuto = modelAuto.Engine

Finding a Probability

This model has a node named "EngineStart" that has a state named "yes". To find the probability that the car's engine will start, we apply the inference engine's Belief function to the node and state of interest.

' Check a probability
Debug.Print "The probability that the car will start is "
Debug.Print inferAuto.Belief("EngineStart", "yes")
Debug.Print

Output:

The probability that the car will start is 
0.899733245651341

To assert a fact, we add a node and state to the Evidence collection using the Add method:

' Add some evidence and check some probabilities
Debug.Print "Tell it that the car, in fact, doesn't start."
inferAuto.Evidence.Add "EngineStart", "no"

Now, if we ask for the probability that the car will start it will say 0. We can also ask about other probabilities.

Debug.Print "The probability that the car will start is "
Debug.Print inferAuto.Belief("EngineStart", "yes")
Debug.Print "The probability that the battery is good is "
Debug.Print inferAuto.Belief("Battery", "good")
Debug.Print

Output:

Tell it that the car, in fact, doesn't start.
The probability that the car will start is
0
The probability that the battery is good is
0.990498642853832

We'll tell it that the lights don't work and ask about the probability that the battery is good.

' Add some more evidence and check some probabilities
Debug.Print "Tell it the lights don't work"
inferAuto.Evidence.Add "LightsShine", "don't work"
Debug.Print "The probability that the battery is good is "
Debug.Print inferAuto.Belief("Battery", "good")
Debug.Print

Output:

Tell it the lights don't work
The probability that the battery is good is
0.97598617912302

Using the Set method on the Evidence collection, we can change the evidence and say that lights do work.

' Change some evidence and check some probabilities
Debug.Print "Tell it the lights do work"
inferAuto.Evidence.Set "LightsShine", "work"
Debug.Print "The probability that the battery is good is "
Debug.Print inferAuto.Belief("Battery", "good")
Debug.Print

Output:

Tell it the lights do work
The probability that the battery is good is
1

 

By enumerating every node and every state, we can see every probability:

'For every node and every state, show the probability
Dim aNode As MSBN3Lib.Node
Dim aState As MSBN3Lib.state
Debug.Print "Nodes and probabilities"
For Each aNode In modelAuto.ModelNodes
Debug.Print aNode.Name,
For Each aState In aNode.States
Debug.Print "P("; aState.Name; ")="; inferAuto.Belief(aNode, aState),
Next aState
Debug.Print
Next aNode
Debug.Print

Output:

Nodes and probabilities
Alternator P(good)= 0.999989576605324 P(bad)= 1.0423394676112E-05
Battery P(good)= 1 P(bad)= 0
BatteryPower P(good)= 1 P(low)= 0 P(none)= 0
CD P(yes)= 0.999957618165044 P(no)= 4.23818349563663E-05
CDLeak P(good)= 0.999998957660463 P(bad)= 1.0423395366561E-06
Distributor P(good)= 0.841989863011888 P(bad)= 0.158010136988112
ESLeak P(good)= 0.984198985254525 P(bad)= 1.58010147454754E-02
ETO P(yes)= 0.83456582766937 P(no)= 0.16543417233063
ETOLeak P(good)= 0.984946844194984 P(bad)= 1.50531558050155E-02
EngineStart P(yes)= 0 P(no)= 1
FanBelt P(ok)= 0.999968729816554 P(loose)= 3.12701834458835E-05
FuelLine P(good)= 0.841989863011888 P(bad)= 0.158010136988112
FuelPump P(good)= 0.699067412143921 P(bad)= 0.300932587856079
Gas P(not empty)= 0.991603194714833 P(empty)= 8.39680528516724E-03
GasGauge P(not empty)= 0.990611591485833 P(empty)= 9.3884085141671E-03
LightsShine P(work)= 1 P(don't work)= 0
RadioPlays P(works)= 0.998999999965425 P(doesn't work)= 1.00000003457535E-03
SparkPlugs P(good)= 0.774046752305156 P(bad)= 0.225953247694844
Starter P(good)= 0.849468451921102 P(bad)= 0.150531548078898

Recommendations

Use the Recommendations collection to find how useful additional information about a node would be. The first item in Recommendations.Keys is the name of the most valuable node.

'Show a recommendation
Debug.Print "Knowing the state of "; inferAuto.Recommendations.Keys(0); "would be most useful."
Debug.Print

Output:

Knowing the state of ETOwould be most useful.

 

Enumerating the Recommendations collection (and its KeyObjects collection) list all the useful nodes and their utility (in order of utility).

'List all recommendations
Debug.Print "Node", "Utility"
For Each aNode In inferAuto.Recommendations.KeyObjects
Debug.Print aNode.Name, inferAuto.Recommendations(aNode)
Next aNode

Output:

Node Utility
ETO -166.471758124647
GasGauge -203.17297015686
SparkPlugs -205.971769894314
Distributor -206.95861573907
Gas -216.904853682089
FanBelt -220.954647059405
Alternator -220.965951259178
FuelPump -234.409330429375
ESLeak -247.667290007677
ETOLeak -248.025747382471
FuelLine -252.400377437429
CDLeak -255.971139079536
Battery -285.971769894314
Starter -335.685042698628

For Details See:

Additional properties and methods of interest:

For more information about accessing, enumerating, displaying, counting, and editing the Evidence and  Recommendations collections, see:

To monitor evidence changes, see these events: