annotate toolboxes/FullBNT-1.0.7/bnt/CPDs/@tabular_CPD/Old/prob_node.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function p = prob_node(CPD, self_ev, pev)
Daniel@0 2 % PROB_NODE Compute P(y|pa(y), theta) (tabular)
Daniel@0 3 % p = prob_node(CPD, self_ev, pev)
Daniel@0 4 %
Daniel@0 5 % self_ev{m} is the evidence on this node in case m
Daniel@0 6 % pev{i,m} is the evidence on the i'th parent in case m
Daniel@0 7 % If there is a single case, self_ev can be a scalar instead of a cell array
Daniel@0 8
Daniel@0 9 ncases = size(pev, 2);
Daniel@0 10
Daniel@0 11 %assert(~any(isemptycell(pev))); % slow
Daniel@0 12 %assert(~any(isemptycell(self_ev))); % slow
Daniel@0 13
Daniel@0 14 CPT = CPD_to_CPT(CPD);
Daniel@0 15 sz = mysize(CPT);
Daniel@0 16 nparents = length(sz)-1;
Daniel@0 17 assert(nparents == size(pev, 1));
Daniel@0 18
Daniel@0 19 if ncases==1
Daniel@0 20 x = cat(1, pev{:});
Daniel@0 21 if iscell(y)
Daniel@0 22 y = self_ev{1};
Daniel@0 23 else
Daniel@0 24 y = self_ev;
Daniel@0 25 end
Daniel@0 26 switch nparents
Daniel@0 27 case 0, p = CPT(y);
Daniel@0 28 case 1, p = CPT(x(1), y);
Daniel@0 29 case 2, p = CPT(x(1), x(2), y);
Daniel@0 30 case 3, p = CPT(x(1), x(2), x(3), y);
Daniel@0 31 otherwise,
Daniel@0 32 ind = subv2ind(CPD.sizes, [x y]);
Daniel@0 33 p = CPT(ind);
Daniel@0 34 end
Daniel@0 35 else
Daniel@0 36 x = num2cell(pev)'; % each row is a case
Daniel@0 37 y = cat(1, self_ev{:})';
Daniel@0 38 ind = subv2ind(CPD.sizes, [x y]);
Daniel@0 39 p = CPT(ind);
Daniel@0 40 end