Mercurial > hg > camir-aes2014
annotate toolboxes/FullBNT-1.0.7/bnt/CPDs/@discrete_CPD/Old/prob_node.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
rev | line source |
---|---|
wolffd@0 | 1 function [P, p] = prob_node(CPD, self_ev, pev) |
wolffd@0 | 2 % PROB_NODE Compute prod_m P(x(i,m)| x(pi_i,m), theta_i) for node i (discrete) |
wolffd@0 | 3 % [P, p] = prob_node(CPD, self_ev, pev) |
wolffd@0 | 4 % |
wolffd@0 | 5 % self_ev(m) is the evidence on this node in case m. |
wolffd@0 | 6 % pev(i,m) is the evidence on the i'th parent in case m (if there are any parents). |
wolffd@0 | 7 % (These may also be cell arrays.) |
wolffd@0 | 8 % |
wolffd@0 | 9 % p(m) = P(x(i,m)| x(pi_i,m), theta_i) |
wolffd@0 | 10 % P = prod p(m) |
wolffd@0 | 11 |
wolffd@0 | 12 if iscell(self_ev), usecell = 1; else usecell = 0; end |
wolffd@0 | 13 |
wolffd@0 | 14 ncases = length(self_ev); |
wolffd@0 | 15 sz = dom_sizes(CPD); |
wolffd@0 | 16 |
wolffd@0 | 17 nparents = length(sz)-1; |
wolffd@0 | 18 if nparents == 0 |
wolffd@0 | 19 assert(isempty(pev)); |
wolffd@0 | 20 else |
wolffd@0 | 21 assert(isequal(size(pev), [nparents ncases])); |
wolffd@0 | 22 end |
wolffd@0 | 23 |
wolffd@0 | 24 n = length(sz); |
wolffd@0 | 25 dom = 1:n; |
wolffd@0 | 26 p = zeros(1, ncases); |
wolffd@0 | 27 if nparents == 0 |
wolffd@0 | 28 for m=1:ncases |
wolffd@0 | 29 if usecell |
wolffd@0 | 30 evidence = {self_ev{m}}; |
wolffd@0 | 31 else |
wolffd@0 | 32 evidence = num2cell(self_ev(m)); |
wolffd@0 | 33 end |
wolffd@0 | 34 T = convert_to_table(CPD, dom, evidence); |
wolffd@0 | 35 p(m) = T; |
wolffd@0 | 36 end |
wolffd@0 | 37 else |
wolffd@0 | 38 for m=1:ncases |
wolffd@0 | 39 if usecell |
wolffd@0 | 40 evidence = cell(1,n); |
wolffd@0 | 41 evidence(1:n-1) = pev(:,m); |
wolffd@0 | 42 evidence(n) = self_ev(m); |
wolffd@0 | 43 else |
wolffd@0 | 44 evidence = num2cell([pev(:,m)', self_ev(m)]); |
wolffd@0 | 45 end |
wolffd@0 | 46 T = convert_to_table(CPD, dom, evidence); |
wolffd@0 | 47 p(m) = T; |
wolffd@0 | 48 end |
wolffd@0 | 49 end |
wolffd@0 | 50 P = prod(p); |
wolffd@0 | 51 |