Daniel@0: function [engine, loglik] = enter_evidence(engine, evidence, varargin) Daniel@0: % this is unchanged from bk_inf_engine. Daniel@0: % ENTER_EVIDENCE Add the specified evidence to the network (bk) 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 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 instead of 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: [ss T] = size(evidence); Daniel@0: engine.filter = filter; Daniel@0: engine.maximize = maximize; Daniel@0: engine.T = T; Daniel@0: Daniel@0: if maximize Daniel@0: error('BK does not yet support max propagation') Daniel@0: % because it calls enter_soft_evidence, not enter_evidence Daniel@0: end Daniel@0: Daniel@0: observed_bitv = ~isemptycell(evidence); Daniel@0: onodes = find(observed_bitv); Daniel@0: bnet = bnet_from_engine(engine); Daniel@0: pot_type = determine_pot_type(bnet, onodes); Daniel@0: CPDpot = convert_dbn_CPDs_to_pots(bnet, evidence, pot_type); Daniel@0: [engine.clpot, loglik] = enter_soft_evidence(engine, CPDpot, observed_bitv, pot_type, filter);