wolffd@0: function fg = bnet_to_fgraph(bnet) wolffd@0: % BNET_TO_FGRAPH Convert a Bayes net to a factor graph wolffd@0: % fg = bnet_to_fgraph(bnet) wolffd@0: % wolffd@0: % We create one factor per family, whose kernel is the CPD wolffd@0: wolffd@0: nnodes = length(bnet.dag); wolffd@0: G = zeros(nnodes, nnodes); wolffd@0: for i=1:nnodes wolffd@0: G(family(bnet.dag, i), i) = 1; wolffd@0: end wolffd@0: wolffd@0: fg = mk_fgraph(G, bnet.node_sizes, bnet.CPD, 'equiv_class', bnet.equiv_class, 'discrete', bnet.dnodes); wolffd@0: wolffd@0: wolffd@0: