Jump to content



Photo

Bayesian Networks UDF


  • Please log in to reply
4 replies to this topic

#1 JRowe

JRowe

    Chasing the white rabbits

  • Active Members
  • PipPipPipPipPipPip
  • 1,764 posts

Posted 21 October 2009 - 01:30 PM

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:
Attached File  smilex1_0.rar   2.28KB   396 downloads



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

AutoIt         
#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!







#2 MartiniThePilot

MartiniThePilot

    Seeker

  • Active Members
  • 23 posts

Posted 30 October 2009 - 04:46 PM

More cool 'artificial intelligence' stuff from you! :)

Already tried the Artificial Neural Networks UDF.

I wonder why there is (almost) no response for this.

Thanks again,

Martini

#3 Authenticity

Authenticity

    Universalist

  • MVPs
  • 2,619 posts

Posted 30 October 2009 - 05:00 PM

Well done :)
How did you manage to get this object to work?

Edit: Just finished reading your topic at the GeNIe forums. Man you're great. :)

Edited by Authenticity, 30 October 2009 - 05:23 PM.


#4 JRowe

JRowe

    Chasing the white rabbits

  • Active Members
  • PipPipPipPipPipPip
  • 1,764 posts

Posted 30 October 2009 - 06:53 PM

Congrats on the well deserved MVP title, Authenticity. And thank you!

#5 Andreik

Andreik

    Bishop

  • Active Members
  • PipPipPipPipPipPip
  • 2,502 posts

Posted 04 November 2009 - 02:03 PM

Wow JRowe, awesome UDF. In a little time should appear some interesting scripts that use your AI UDFs in AutoIt. :)
When the words fail... music speaks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users