Bayesian Networks

Copyright Tristan Aubrey-Jones April 2007.

computePosteriorProbs.m

home Home   up Up   ( Download )


function results = computePosteriorProbs(sample, prior, step, limit) % size of sample sz = size(sample); if nargin == 3 limit = sz(1); end % init results results = []; % prior probabilities of models %prior = [1/12; 5/12; 6/12]; % current log likelihoods loglhood = [0; 0; 0]; % iterate through increasing sample sizes for i = 1:limit % compute prob of current event p = probOfEvent(sample(i,1:sz(2))); % compute product of likelihoods so far loglhood = loglhood + log(p); % if should take a reading if mod(i,step) == 0 % get current likelihoods lhoods = exp(loglhood); % sum over hypotheses hyp = sum(lhoods .* prior); % compute posteriors posts = (lhoods .* prior) ./ hyp; % add to results rsz = size(results); results(rsz(1)+1, 1:3) = posts'; end end x = 1:step:limit; plot(x, results);