Jump to content

Bayesian Networks UDF


JRowe
 Share

Recommended Posts

This set of functions deals with interacting with Bayesian Networks or Influence Diagrams built (or exported) with GeNIe. Bayesian Networks are another awesome computational tool that allow you to create a graphical model of a system or problem and get intelligent results from it, making predictions, inferences, or assumptions based on available evidence, formulas, and probabilities. I'll go into potential uses later in the post.

IMPORTANT: You'll need the ActiveX component from here:

http://genie.sis.pitt.edu/download/smilex.zip

Once you've downloaded it, unzip SmileX.ocx it to a directory like c:/SmileX, then you'll need to register it.

Press Windows Key + R, then type in regsvr32 c:/SmileX/SmileX.ocx

(win7/Vista users, let me know what the equivalent is if it's changed?)

Now you need the UDF and a sample bayesian network:

smilex1_0.rar

Here's a demo script. It guesses what animal you're thinking of after you select the characteristics from the drop-down menus.

#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include "_SmileX.au3"


$Form1 = GUICreate("Form1", 436, 226, 192, 124)
GUISetBkColor(0x000000)
$Progress1 = GUICtrlCreateProgress(264, 24, 150, 17)
$Progress2 = GUICtrlCreateProgress(264, 56, 150, 17)
$Progress3 = GUICtrlCreateProgress(264, 88, 150, 17)
$Progress4 = GUICtrlCreateProgress(264, 120, 150, 17)
$Progress5 = GUICtrlCreateProgress(264, 152, 150, 17)
$Label1 = GUICtrlCreateLabel("Monkey", 208, 24, 42, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
$Label2 = GUICtrlCreateLabel("Penguin", 208, 56, 43, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
$Label3 = GUICtrlCreateLabel("Platypus", 208, 88, 44, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
$Label4 = GUICtrlCreateLabel("Robin", 208, 120, 32, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
$Label5 = GUICtrlCreateLabel("Turtle", 208, 152, 31, 17)
GUICtrlSetColor(-1, 0xFFFFFF)
$Combo1 = GUICtrlCreateCombo("Environment", 32, 24, 145, 25)
$Combo2 = GUICtrlCreateCombo("Body Covering", 32, 56, 145, 25)
$Combo3 = GUICtrlCreateCombo("Warm Blooded", 32, 88, 145, 25)
$Combo4 = GUICtrlCreateCombo("Has Shell", 32, 120, 145, 25)
$Combo5 = GUICtrlCreateCombo("Bears Young", 32, 152, 145, 25)
$Combo6 = GUICtrlCreateCombo("Class", 32, 184, 145, 25)
$Button1 = GUICtrlCreateButton("Clear All Evidence", 280, 184, 123, 25)
GUISetState(@SW_SHOW)



GUICtrlSetData($Combo1, "Air|Land|Water", "Air")
GUICtrlSetData($Combo2, "Hair|Down|Scales", "Hair")
GUICtrlSetData($Combo3, "True|False", "Warm Blooded")
GUICtrlSetData($Combo4, "True|False", "True")
GUICtrlSetData($Combo5, "Eggs|Live", "Eggs")
GUICtrlSetData($Combo6, "Bird|Mammal|Reptile", "Bird")

$mySmileX = ObjCreate("SMILEX.SmilexCtrl.1")
_SmilexCreateNetwork($mySmileX, "Animals.dsl")
_UpdateGuess()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Combo1
                $mySmileX.SetEvidence("Environment", GUICtrlRead($Combo1))
                    _UpdateGuess()

        Case $Combo2
            _SmilexSetEvidence($mySmileX, "BodyCovering", GUICtrlRead($Combo2))
            _UpdateGuess()
        Case $Combo3
            _SmilexSetEvidence($mySmileX, "WarmBlooded", GUICtrlRead($Combo3))
            _UpdateGuess()
        Case $Combo4
            _SmilexSetEvidence($mySmileX, "HasShell", GUICtrlRead($Combo4))
            _UpdateGuess()
        Case $Combo5
            _SmilexSetEvidence($mySmileX, "BearsYoungAs", GUICtrlRead($Combo5))
            _UpdateGuess()
        Case $Combo6
            _SmilexSetEvidence($mySmileX, "Class", GUICtrlRead($Combo6))
            _UpdateGuess()
        Case $Button1
            _SmilexClearAllEvidence($mySmileX)
            _UpdateGuess()
    EndSwitch
WEnd


Func _UpdateGuess()
                    _SmilexUpdateBeliefs($mySmileX, "Lauritzen")

                    $aResult = _SmilexGetBeliefs($mySmileX, "Animal")
                    GUICtrlSetData($Progress1, $aResult[0]*100)
                    GUICtrlSetData($Progress2, $aResult[1]*100)
                    GUICtrlSetData($Progress3, $aResult[2]*100)
                    GUICtrlSetData($Progress4, $aResult[3]*100)
                    GUICtrlSetData($Progress5, $aResult[4]*100)
EndFunc

Ok, so Bayesian Networks are a way of using probability, evidence, and math to make intelligent inferences from a system. You see them used a lot in forensics, economics, law, military, medicine, and a ton of other real-world applications. What makes them useful is their near universal applicability. The system can be used to model almost anything.

You could, for example, create a model of World of Warcraft gameplay, then use AutoIt to plug in knowledge(values from the game) and interface with the game (keystrokes, mouse movement.) These networks are the ideal in Model - View - Controller system design, because they're inherently restricted to the Model aspect, and leverage a lot of computational power by abstracting the algorithms used in Model design. You don't get the view and controller mixed up in the Model, so you can do a lot more kung-fu with the Model design.

Here's some sample networks. They're not really useful for anything we on the forum would need, except maybe the win98 printer troubleshooter system. However, if you download GeNIe 2 and look at them, you can get a feel for how complicated networks are put together, by using expert opinion, real world statistics, and mathematics.

You're required to contact http://genie.sis.pitt.edu/license.html the developers before using SmileX in a commercial application.

It seems complicated at first, but by using some of the simple models (like the Animals guessing game) you get a feel for what's going on. These networks formalize the abstraction of the system you're modeling, and allow you to focus on development of the model, once your interface is complete.

The networks are also useful because they can provide you with a probability for a scenario. In the demo script, you'll notice that occasionally the bars will display less than 100% full, because the network believes in the options to varying degrees. Once you've provided enough information, though, the selection resolves and it displays exactly the animal with the characteristics you chose. In scenarios where you don't have complete information, however, you can direct the system to continue based on the most probable selection, and you have a clear and justifiable reason for the choice. Doctors often use these networks for diagnosis.

Here's the COM object documentation:

http://genie.sis.pitt.edu/SmileX/manual/SmileX_0.html

GeNIe:

http://genie.sis.pitt.edu/downloads.html

Screenshots of Networks in action:

http://genie.sis.pitt.edu/screenshots.html

And last, but definitely not least, the GeNIe documentation, with tutorials and lots of background knowledge.

http://genie.sis.pitt.edu/wiki/Main_Page

Good luck!

Link to comment
Share on other sites

  • 2 weeks later...
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...