Daniel@0: function marginal = marginal_nodes(engine, query, add_ev) Daniel@0: % MARGINAL_NODES Compute the marginal on the specified query nodes (jtree) Daniel@0: % marginal = marginal_nodes(engine, query, add_ev) Daniel@0: % Daniel@0: % 'query' must be a subset of some clique; an error will be raised if not. Daniel@0: % add_ev is an optional argument; if 1, we will "inflate" the marginal of observed nodes Daniel@0: % to their original size, adding 0s to the positions which contradict the evidence Daniel@0: Daniel@0: if nargin < 3, add_ev = 0; end Daniel@0: Daniel@0: c = clq_containing_nodes(engine, query); Daniel@0: if c == -1 Daniel@0: error(['no clique contains ' num2str(query)]); Daniel@0: end Daniel@0: marginal = pot_to_marginal(marginalize_pot(engine.clpot{c}, query, engine.maximize)); Daniel@0: Daniel@0: if add_ev Daniel@0: bnet = bnet_from_engine(engine); Daniel@0: %marginal = add_ev_to_dmarginal(marginal, engine.evidence, bnet.node_sizes); Daniel@0: marginal = add_evidence_to_gmarginal(marginal, engine.evidence, bnet.node_sizes, bnet.cnodes); Daniel@0: end Daniel@0: