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