📄 franks_from_bnt.m
字号:
function [parents,child,node_sizes,postorder,preorder,cliquetable,septable,clq_ass_to_node,pot_to_CPT]= franks_from_BNT(bnet,N)
%franks_from_BNT transforms BNT structure to my structure, which should be
%faster in doing EM because 1) a lot a work is done only once instead of at
%each iteration, 2) we matricized some of the functions
%make junction tree (murphy's function)
engine = jtree_inf_engine(bnet);
a=struct(engine); %violate object privacy to get at its fields
numb_clqs=length(a.cliques); %number of cliques
postorder=a.postorder; %order of collect evidence
preorder=a.preorder; %order of distribute evidence
clq_ass_to_node=a.clq_ass_to_node; %gives the clique to which the node is assigned
parents=bnet.parents;
node_sizes=bnet.node_sizes;
%cliquetable is structure array for the cliques
cliquetable.pots=cell(numb_clqs,1); %potentials
cliquetable.ind=cell(numb_clqs,1); %identification number of the nodes
cliquetable.nod=cell(numb_clqs,1); %identification number of the nodes assigned to the clique
cliquetable.dim=cell(numb_clqs,1); %dimension of the nodes
numb_nodes=length(node_sizes);
child=cell(1,numb_nodes);
for i=1:numb_nodes
child{i}=children(bnet.dag,i);
end
for i=1:numb_clqs
cliquetable.pots{i}=ones([ bnet.node_sizes(a.cliques{i}) N]);%N=number of persons
cliquetable.ind{i}= a.cliques{i};
cliquetable.dim{i}=[bnet.node_sizes(a.cliques{i}) N ];
cliquetable.nod{i}=find(a.clq_ass_to_node==i);
end
%septable is structure array for the separators
septable.pots=cell(numb_clqs,numb_clqs);%potentials
septable.ind=cell(numb_clqs,numb_clqs);%identification number of the nodes
septable.proj=cell(numb_clqs,numb_clqs);%dimensionnr of the nodes to sum over
septable.abs=cell(numb_clqs,numb_clqs);%deimensionnr of the nodes to replicate across
septable.dim=cell(numb_clqs,numb_clqs); %sizes of the nodes
for i=1:numb_clqs
e=postorder(i);
for j=i+1:numb_clqs
k=postorder(j);
if ~isempty(a.separator{e,k})
septable.pots{e,k}=ones([bnet.node_sizes(a.separator{e,k}) N ]);
septable.ind{e,k}= a.separator{e,k};
map=mysetdiff(cliquetable.ind{e},septable.ind{e,k});%identification number of the nodes to sum over
septable.proj{e,k}=find_equiv_posns(map,cliquetable.ind{e});
map=mysetdiff(cliquetable.ind{k},septable.ind{e,k});%identification number of the nodes to replicate across
septable.abs{e,k}=find_equiv_posns(map,cliquetable.ind{k});
septable.dim{e,k}=[ bnet.node_sizes(a.separator{e,k}) N];
end
end
end
for i=1:numb_clqs
e=preorder(i);
for j=i+1:numb_clqs
k=preorder(j);
if ~isempty(a.separator{e,k})
septable.pots{e,k}=ones([bnet.node_sizes(a.separator{e,k}) N ]);
septable.ind{e,k}= a.separator{e,k};
map=mysetdiff(cliquetable.ind{e},septable.ind{e,k});%identification number of the nodes to sum over
septable.proj{e,k}=find_equiv_posns(map,cliquetable.ind{e});
map=mysetdiff(cliquetable.ind{k},septable.ind{e,k});%identification number of the nodes to replicate across
septable.abs{e,k}=find_equiv_posns(map,cliquetable.ind{k});
septable.dim{e,k}=[ bnet.node_sizes(a.separator{e,k}) N];
end
end
end
%how to obtains CPTS from potentials
pot_to_CPT=link_pot_to_CPT(cliquetable,clq_ass_to_node,parents);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -