During my travels I had to calculate some values given certain conditions. Appallingly I was unable to find any instance of Bayesian networks implemented in pure Tcl. The closest thing I found was [Bayesian Spam Filtering] by [Donal Fellows], which calculated probabilites by examining token frequencies. What I needed was a more general purpose network that could handle an arbitrary depth network. To remedy said condition and with the aid of Eliezer Yudkowsky's outstanding Bayesian Reasoning tutorial ([http://yudkowsky.net/bayes/bayes.html]) I went out and wrote one myself. My program implements the ''support-except / evidence-except'' algorithm (see [http://sern.ucalgary.ca/courses/cpsc/533/W02/Uncertainty/ProbabilisticReasoningGrp9_files/main.htm] et al) thus is bounded by the limitation that the network be a polytree (a directed acyclic graph with exactly one path from any arbitrary node to another). Add nodes to it by calling [[addNode]. Then initialize the beliefs network through [[initBeliefs]. Now you can query things by calling the functions [[evidence], [[support], or [[infer]. Suppose one wanted to try the example in Yudkowsky's site: 1% of women at age forty who participate in routine screening have breast cancer. 80% of women with breast cancer will get positive mammographies. 9.6% of women without breast cancer will also get positive mammographies. A woman in this age group had a positive mammography in a routine screening. What is the probability that she actually has breast cancer? Using the code below one could build the Bayesian network like so: addNode bc {} {s} 0.01 "Have Breast Cancer" addNode s {bc} {} {0.80 0.096} "Screened Positive" Combined these two create a two node network that looks like: (bc) -> (s) Node '''bc''' has a probability of 0.01, corresponding with 1% of all women. Node '''s''' has a single parent, '''bc'''. The probability that '''s''' is true given '''bc''' is 0.80, its probability of truth when '''bc''' is false is 0.096. Now one can use the network to answer the question if she actually has cancer by calling: puts [infer +bc +s] and assuming that your computer is not broken Tcl will respond with the correct answer: 0.0776397515528 Here is another trivial example of what Bayesian networks can do. In our fictional world 20% of all programmers know Tcl (P(kt) = 0.20). 25% of all programmers also know Python (P(kp) = 0.25). Note that it is possible for a programmer to know both Tcl and Python. --- Return to [Jason Tang] --- [Category Mathematics] | [Artificial Intelligence with Tcl]