wolffd@0
|
1 function [engine, loglik] = enter_evidence(engine, evidence, varargin)
|
wolffd@0
|
2 % ENTER_EVIDENCE Add the specified evidence to the network (global_joint)
|
wolffd@0
|
3 % [engine, loglik] = enter_evidence(engine, evidence, ...)
|
wolffd@0
|
4 %
|
wolffd@0
|
5 % evidence{i} = [] if if X(i) is hidden, and otherwise contains its observed value.
|
wolffd@0
|
6 %
|
wolffd@0
|
7 % Warning: Computing the log likelihood requires marginalizing all the nodes and can be slow.
|
wolffd@0
|
8 %
|
wolffd@0
|
9 % The list below gives optional arguments [default value in brackets].
|
wolffd@0
|
10 %
|
wolffd@0
|
11 % exclude - list of nodes whose potential will not be included in the joint [ [] ]
|
wolffd@0
|
12 %
|
wolffd@0
|
13 % e.g., engine = enter_evidence(engine, ev, 'exclude', 3)
|
wolffd@0
|
14
|
wolffd@0
|
15 exclude = [];
|
wolffd@0
|
16 maximize = 0;
|
wolffd@0
|
17
|
wolffd@0
|
18 if nargin >= 3
|
wolffd@0
|
19 args = varargin;
|
wolffd@0
|
20 nargs = length(args);
|
wolffd@0
|
21 for i=1:2:nargs
|
wolffd@0
|
22 switch args{i},
|
wolffd@0
|
23 case 'exclude', exclude = args{i+1};
|
wolffd@0
|
24 case 'maximize', maximize = args{i+1};
|
wolffd@0
|
25 otherwise,
|
wolffd@0
|
26 error(['invalid argument name ' args{i}]);
|
wolffd@0
|
27 end
|
wolffd@0
|
28 end
|
wolffd@0
|
29 end
|
wolffd@0
|
30
|
wolffd@0
|
31 assert(~maximize)
|
wolffd@0
|
32 bnet = bnet_from_engine(engine);
|
wolffd@0
|
33 N = length(bnet.node_sizes);
|
wolffd@0
|
34 %[engine.jpot, loglik] = compute_joint_pot(bnet, mysetdiff(1:N, exclude), evidence, 1:N);
|
wolffd@0
|
35 [engine.jpot] = compute_joint_pot(bnet, mysetdiff(1:N, exclude), evidence, 1:N);
|
wolffd@0
|
36 % jpot should not be normalized, otherwise it gives wrong resutls for limids like asia_dt1
|
wolffd@0
|
37 if nargout == 2
|
wolffd@0
|
38 [m] = marginal_nodes(engine, []);
|
wolffd@0
|
39 [T, lik] = normalize(m.T);
|
wolffd@0
|
40 loglik = log(lik);
|
wolffd@0
|
41 end
|
wolffd@0
|
42 %[engine.jpot loglik] = normalize_pot(engine.jpot);
|