wolffd@0: function [engine, loglik] = enter_evidence(engine, evidence, varargin) wolffd@0: % ENTER_EVIDENCE Add the specified evidence to the network (global_joint) wolffd@0: % [engine, loglik] = enter_evidence(engine, evidence, ...) wolffd@0: % wolffd@0: % evidence{i} = [] if if X(i) is hidden, and otherwise contains its observed value. wolffd@0: % wolffd@0: % Warning: Computing the log likelihood requires marginalizing all the nodes and can be slow. wolffd@0: % wolffd@0: % The list below gives optional arguments [default value in brackets]. wolffd@0: % wolffd@0: % exclude - list of nodes whose potential will not be included in the joint [ [] ] wolffd@0: % wolffd@0: % e.g., engine = enter_evidence(engine, ev, 'exclude', 3) wolffd@0: wolffd@0: exclude = []; wolffd@0: maximize = 0; wolffd@0: wolffd@0: if nargin >= 3 wolffd@0: args = varargin; wolffd@0: nargs = length(args); wolffd@0: for i=1:2:nargs wolffd@0: switch args{i}, wolffd@0: case 'exclude', exclude = args{i+1}; wolffd@0: case 'maximize', maximize = args{i+1}; wolffd@0: otherwise, wolffd@0: error(['invalid argument name ' args{i}]); wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: assert(~maximize) wolffd@0: bnet = bnet_from_engine(engine); wolffd@0: N = length(bnet.node_sizes); wolffd@0: %[engine.jpot, loglik] = compute_joint_pot(bnet, mysetdiff(1:N, exclude), evidence, 1:N); wolffd@0: [engine.jpot] = compute_joint_pot(bnet, mysetdiff(1:N, exclude), evidence, 1:N); wolffd@0: % jpot should not be normalized, otherwise it gives wrong resutls for limids like asia_dt1 wolffd@0: if nargout == 2 wolffd@0: [m] = marginal_nodes(engine, []); wolffd@0: [T, lik] = normalize(m.T); wolffd@0: loglik = log(lik); wolffd@0: end wolffd@0: %[engine.jpot loglik] = normalize_pot(engine.jpot);