Log 03-23-2013

I basically spent most of today trying to find good software and datasets for Bayes nets. (Other highlights include the Hertz lunch and running 7.5 miles with plambda group.)

There’s a lot of good datasets at http://www.bnlearn.com/bnrepository/, but they are in weird formats, and I don’t want to use bnlearn because I don’t want to have to use R.

I read through some papers to try to find possible alternate datasets, but the ones on the bnlearn website seem to be by far the most nice and standardized. So I tried to find software that could parse these (and hopefully have nice Bayes net inference software, as well). I took a look at JavaBayes (not updated since 2002!) and Samiam (reasonable GUI but not great in terms of command-line / API support) before finally setting on SMILE (http://genie.sis.pitt.edu/), which I am super-happy with (I had a few upfront compilation difficulties, but they are mainly due to me not knowing how to use g++).

SMILE is a C++ library for doing Bayes net inference that can handle a pretty extensive array of file formats, including the Hugins .net format that the bnlearn datasets are saved in. I installed SMILE, downloaded the bnlearn datasets, and wrote a simple program that uses SMILE to do inference on one of the smaller bnlearn datasets. I’m looking forward tomorrow to trying to stress SMILE out a bit more and see exactly what it can do.

Here’s some sample SMILE code in case you’re wondering whether to use it yourself:

#include <stdio.h>
#include “smile/smile.h”

double getProbability(DSL_nodeValue* value, int stateIndex){
DSL_sysCoordinates coord(*value);
coord[0] = stateIndex;
return coord.UncheckedValue();

double getProbability(DSL_node* node, const char* stateName){
DSL_nodeValue* value = node->Value();
int stateIndex = node->Definition()->GetOutcomesNames()->FindPosition(stateName);
return getProbability(value, stateIndex);

int main(){
DSL_network net;
net.ReadFile(“asia.net”, DSL_HUGIN_FORMAT);

int asia = net.FindNode(“asia”);
int tub = net.FindNode(“tub”);
int lung = net.FindNode(“lung”);
int xray = net.FindNode(“xray”);

printf(“Computing initial beliefs…\n”);
printf(“P(lung = yes) = %f\n”, getProbability(net.GetNode(lung), “yes”));
printf(“P(tub = yes) = %f\n”, getProbability(net.GetNode(tub), “yes”));
printf(“P(asia = yes) = %f\n”, getProbability(net.GetNode(asia), “yes”));

printf(“Adding and computing probability of evidence (xray = yes)…\n”);
int yes = 0, no = 1;
double p_evidence;
printf(“P(xray = yes) = %f\n”, p_evidence);

printf(“Updating beliefs given xray = yes…\n”);
printf(“P(lung = yes | xray = yes) = %f\n”, getProbability(net.GetNode(lung), “yes”));
printf(“P(tub = yes | xray = yes) = %f\n”, getProbability(net.GetNode(tub), “yes”));
printf(“P(asia = yes | xray = yes) = %f\n”, getProbability(net.GetNode(asia), “yes”));

return 0;


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s