So, you've got something like:
%nodes=( root => { parents => [],
probs => [0.01]}, # P(root)
some => { parents => ['n1'],
probs => [0.74,0.21]}, # P(some|!root), P(some|root
+)
other =>{ parents => ['root','n1'],
probs => [0.12,0.24, # P(other|!root,!some), P(ot
+her|!root,some)
0.81,0.18]}, # P(other|root,!some), P(oth
+er|root,some)
);
I choose an array to represent the join probabilities because I thought it would be the easiest way. You get the entry you need with something like:
# the state you start from
%state=(root=>1,some=>0);
# let's get P(other|root,!some)
$i=0;
for @{$nodes{other}{parents}} {
$i=($i<<2)+$state{$_} # this is a simple encoding. Just use the same
+for updating and accessing
}
$prob=$nodes{other}{probs}[$i];
When you have trained your network, you can dump it using XML::Simple:
use XML::Simple;
print XMLout(\%nodes);
I think this code should work as well with full-fledged belief networks, since I'm using names to refer to nodes, instead of nesting their representation in the XML tree.
--
dakkar - Mobilis in mobile