wolffd@0: function CPDpot = convert_dbn_CPDs_to_tables_slow(bnet, evidence) wolffd@0: % CONVERT_DBN_CPDS_TO_TABLES_SLOW Convert CPDs of (possibly instantiated) DBN nodes to tables wolffd@0: % CPDpot = convert_dbn_CPDs_to_tables_slow(bnet, evidence) wolffd@0: % wolffd@0: % CPDpot{n,t} is a table containing P(n,t|pa(n,t), ev) wolffd@0: % All hidden nodes are assumed to be discrete wolffd@0: % wolffd@0: % Non-vectorized method; this is less efficient for long sequences of observed Gaussian wolffd@0: % nodes, because of the (unnecessary) repeated matrix inversion. wolffd@0: wolffd@0: obs_bitv = ~isemptycell(evidence(:)); wolffd@0: [ss T] = size(evidence); wolffd@0: ns = bnet.node_sizes(:); wolffd@0: wolffd@0: CPDpot = cell(ss,T); wolffd@0: wolffd@0: t = 1; wolffd@0: for n=1:ss wolffd@0: %ps = engine.bnet_parents{n}; wolffd@0: ps = parents(bnet.dag, n); wolffd@0: e = bnet.equiv_class(n, 1); wolffd@0: if ~any(obs_bitv(ps)) wolffd@0: CPDpot{n,t} = convert_CPD_to_table_hidden_ps(bnet.CPD{e}, evidence{n,t}); wolffd@0: else wolffd@0: CPDpot{n,t} = convert_to_table(bnet.CPD{e}, [ps n], evidence(:,1)); wolffd@0: end wolffd@0: end wolffd@0: for t=2:T wolffd@0: for n=1:ss wolffd@0: self = n+ss; wolffd@0: ps = parents(bnet.dag, self); wolffd@0: e = bnet.equiv_class(n, 2); wolffd@0: if ~any(obs_bitv(ps)) wolffd@0: CPDpot{n,t} = convert_CPD_to_table_hidden_ps(bnet.CPD{e}, evidence{n,t}); wolffd@0: else wolffd@0: CPDpot{n,t} = convert_to_table(bnet.CPD{e}, [ps self], evidence(:,t-1:t)); wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: