Hello Bayes |
Startpage
|
![]() |
Figure 1: The Bayesian belief network modelling the above murder investigation. [Details] |
Colombo is definitely a Bayesian belief network illiterate and knows equally little about using the Hugin tool. Forcing him to understand the network, enter evidence, propagate, and so on is not suitable. Hence your job as knowledge-engineer is to create an easy to use application tailormade for his needs and hiding all the complexity of Bayesian belief networks. The "HelloBayes" application created in the next section accomplishes this task.
![]() |
Figure 2:Selecting the Hugin API ActiveX Server in the References Dialog box. |
Create a form and add GUI components similar to Figure 3. Two components deserve special attention.
- DNAState
- An array of option controls used to indicate the state of the
DNA-match?
node.- GuiltyProb
- A label displaying the probability that
Murderer?
is in the stateyes
.
![]() |
Figure 3: The Visual Basic Form used in the HelloBayes application. |
After the above steps it is time to add code turning the form into a
useful application. The code is divided into four different sections:
the declaration section of the module, initial operations performed on
loading the form, operations performed when closing the form and
operations performed when one of the option buttons selects a
DNA-match?
state.
d
is declared which will refer to the
murder network. To hold a network it is necessary to allocate a domain
structure of type HAPI.Domain which keeps track of the nodes
belonging to the network, the compilation status of the network etc.
Furthermore, the section declares constants in order to be able to
symbolically identify the states of the two nodes in the network.
Option Explicit Dim d As HAPI.Domain Private Const MurderYes = 0 Private Const MurderNo = 1 Private Const DNAMatch = 0 Private Const DNANoMatch = 1
Form_Load()
event is triggered when the form is
loaded. We use it to initialize the global variables and display the
guilty probability in the initial no
state of the
DNA-match?
node.
Private Sub Form_Load() ' A collection to hold the found parseErrors Dim parseErrors As Collection ' Load the domain from the murder.net file and compile it. Set d = HAPI.LoadDomainFromNet("D:\VB Projects\HelloBayes\murder.net", parseErrors, 10) d.Compile ' Initially the DNANoMatch state is selected - display the probability Call DNAState_Click(DNANoMatch) Exit Sub End Sub
First the domain variable is initialized by calling the API function
LoadDomainFromNet
with the path of the murder network and
a collection object in case of parse errors as arguments. Depending on
the location of your murder.net file you might have to use a different
path. Hereafter the domain is compiled which triangulates the graph
and constructs the junction tree. The domain is now ready for
propagation.
Initially the DNANoMatch option button is selected. We call the sub procedure described in the next section to display the guilty probability.
Private Sub Form_Terminate() ' We are done using the domain - explicitly delete it. d.Delete End Sub
DNAState_Click
event is triggered whenever the selected
DNAState
is changed.
Private Sub DNAState_Click(Index As Integer) Dim n As HAPI.Node ' Fetch the node with label "DNA-match?" and name "DNA" from the domain Set n = d.GetNodeByName("DNA") ' Instantiate the Node with state "Index" as evidence and sum propagate it n.SelectState (Index) Call d.Propagate(hEquilibriumSum, hModeNormal) ' Fetch the "Murderer?" node and display the probability for MurderYes Set n = d.GetNodeByName("M") GuiltyProb.Caption = Format(n.Belief(MurderYes) * 100, "##0.00000000") & "%" End Sub
To instantiate the DNA-match?
node we first fetch it from
the domain by calling GetNodeByName
with the
DNA-match?
node's name ("DNA") as parameter. Hereafter we
enter the state selected by the DNAState
options as a
finding and sum-propagate the information in the network.
Finally the probability for the suspect to be guilty is displayed by
calling GetBelief
for the Murderer? node with MurderYes
as the desired state.
You should now be able to to compile and run the application. The low probability in case of a DNA match indicates that such a case needs substantial strengthening before going to trial. Hopefully the probabilities will persuade Colombo to rely on more sophisticated investigation methods!
To get up and running very fast with this demo application, follow these instructions:murder.frm murder.net
![]() |
HUGIN Expert A/S, 2007 - comments to activex@hugin.com |