Bayesian Networks

Copyright Tristan Aubrey-Jones April 2007.

computeProb.m

home Home   up Up   ( Download )


function prob = computeProb(conds, currentVar) % COMPUTEPROB computes the probability of all of % the conditions occuring by directly manipulating % the joint distribution. It works by summing over % all values of unspecified variables. if nargin == 1 % start prob = computeProb(conds, 1); else % if still constructing events sz = size(conds); if currentVar ~= 6 % recursing through sumOver = 1; for i = 1:sz(1) if conds(i, 1) == currentVar sumOver = 0; break; end end if sumOver % summing over both values of this variable conds(sz(1)+1, 1:2) = [currentVar 1]; prob = computeProb(conds, currentVar+1); conds(sz(1)+1, 1:2) = [currentVar 0]; prob = prob + computeProb(conds, currentVar+1); else % this variable appears in the interesection prob = computeProb(conds, currentVar+1); end else % compute the probability of this event event = zeros(1,5); for i = 1:sz(1) event(1,conds(i,1)) = conds(i,2); end prob = probOfEvent(event); end end