Hello Bayes |
Startpage
|
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 Dim glob as new HAPI.Globals 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 hc as new HuginCollection Dim parseErrors As Object ' really a VB 6.0 Collection ' Create the Vb 6.0 Collection parseErrors=hc.toCollection() ' Load the domain from the murder.net file and compile it. Set d = glob.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 we need to create an instance of the HAPI.Globals, as VB.net
does not allow for singleton instances. This instance is then used
when the domain variable is initialized by calling the API function
LoadDomainFromNet
with the path of the murder network and
a HuginCollection object in case of parse errors as arguments. Here,
we need to use a special HuginCollection,
to create a VB 6.0 Collection,
since the Collection class in VB.net is not compatible with VB 6.0
Collections. 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!