Daniel@0: function [engine, loglik] = enter_evidence(engine, evidence, varargin) Daniel@0: % ENTER_EVIDENCE Add the specified evidence to the network (ff) Daniel@0: % [engine, loglik] = enter_evidence(engine, evidence, ...) Daniel@0: % Daniel@0: % evidence{i,t} = [] if if X(i,t) is hidden, and otherwise contains its observed value (scalar or Daniel@0: % column vector) Daniel@0: % Daniel@0: % The following optional arguments can be specified in the form of name/value pairs: Daniel@0: % [default value in brackets] Daniel@0: % Daniel@0: % maximize - if 1, does max-product (not yet supported), else sum-product [0] Daniel@0: % filter - if 1, do filtering, else smoothing [0] Daniel@0: % Daniel@0: % e.g., engine = enter_evidence(engine, ev, 'maximize', 1) Daniel@0: Daniel@0: maximize = 0; Daniel@0: filter = 0; Daniel@0: Daniel@0: % parse optional params Daniel@0: args = varargin; Daniel@0: nargs = length(args); Daniel@0: if nargs > 0 Daniel@0: for i=1:2:nargs Daniel@0: switch args{i}, Daniel@0: case 'maximize', maximize = args{i+1}; Daniel@0: case 'filter', filter = args{i+1}; Daniel@0: otherwise, Daniel@0: error(['invalid argument name ' args{i}]); Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: assert(~maximize); Daniel@0: Daniel@0: Daniel@0: [ss T] = size(evidence); Daniel@0: observed = ~isemptycell(evidence); Daniel@0: bnet = bnet_from_engine(engine); Daniel@0: %pot_type = determine_pot_type(find(observed(:,1)), bnet.cnodes_slice, bnet.intra); Daniel@0: pot_type = determine_pot_type(bnet, observed); Daniel@0: % we assume we can use the same pot_type in all slices Daniel@0: Daniel@0: CPDpot = convert_dbn_CPDs_to_pots(bnet, evidence, pot_type); Daniel@0: Daniel@0: % Now convert CPDs on observed nodes to be potentials just on their parents Daniel@0: assert(pot_type == 'd'); Daniel@0: onodes = bnet.observed(:); Daniel@0: ns = bnet.node_sizes_slice; Daniel@0: ns(onodes) = 1; Daniel@0: for t=1:T Daniel@0: for i=onodes Daniel@0: p = parents(bnet.dag, i); Daniel@0: %CPDpot{i,t} = set_domain_pot(CPDpot{i,t}, p); % leaves size too long Daniel@0: temp = pot_to_marginal(CPDpot{i,t}); Daniel@0: CPDpot{i,t} = dpot(p, ns(p), temp.T); % assumes pot_type = d Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: [engine.marginals, engine.fwd, engine.back, loglik] = enter_soft_evidence(engine, CPDpot, observed, pot_type, filter); Daniel@0: Daniel@0: engine.CPDpot = CPDpot; Daniel@0: engine.filter = filter;