matthiasm@8: function [engine, loglik] = enter_evidence(engine, evidence, varargin) matthiasm@8: % this is unchanged from bk_inf_engine. matthiasm@8: % ENTER_EVIDENCE Add the specified evidence to the network (bk) matthiasm@8: % [engine, loglik] = enter_evidence(engine, evidence, ...) matthiasm@8: % matthiasm@8: % evidence{i,t} = [] if if X(i,t) is hidden, and otherwise contains its observed value (scalar or column vector) matthiasm@8: % matthiasm@8: % The following optional arguments can be specified in the form of name/value pairs: matthiasm@8: % [default value in brackets] matthiasm@8: % matthiasm@8: % maximize - if 1, does max-product instead of sum-product [0] matthiasm@8: % filter - if 1, do filtering, else smoothing [0] matthiasm@8: % matthiasm@8: % e.g., engine = enter_evidence(engine, ev, 'maximize', 1) matthiasm@8: matthiasm@8: maximize = 0; matthiasm@8: filter = 0; matthiasm@8: matthiasm@8: % parse optional params matthiasm@8: args = varargin; matthiasm@8: nargs = length(args); matthiasm@8: if nargs > 0 matthiasm@8: for i=1:2:nargs matthiasm@8: switch args{i}, matthiasm@8: case 'maximize', maximize = args{i+1}; matthiasm@8: case 'filter', filter = args{i+1}; matthiasm@8: otherwise, matthiasm@8: error(['invalid argument name ' args{i}]); matthiasm@8: end matthiasm@8: end matthiasm@8: end matthiasm@8: matthiasm@8: [ss T] = size(evidence); matthiasm@8: engine.filter = filter; matthiasm@8: engine.maximize = maximize; matthiasm@8: engine.T = T; matthiasm@8: matthiasm@8: if maximize matthiasm@8: error('BK does not yet support max propagation') matthiasm@8: % because it calls enter_soft_evidence, not enter_evidence matthiasm@8: end matthiasm@8: matthiasm@8: observed_bitv = ~isemptycell(evidence); matthiasm@8: onodes = find(observed_bitv); matthiasm@8: bnet = bnet_from_engine(engine); matthiasm@8: pot_type = determine_pot_type(bnet, onodes); matthiasm@8: CPDpot = convert_dbn_CPDs_to_pots(bnet, evidence, pot_type); matthiasm@8: [engine.clpot, loglik] = enter_soft_evidence(engine, CPDpot, observed_bitv, pot_type, filter);