comparison toolboxes/FullBNT-1.0.7/bnt/inference/static/@global_joint_inf_engine/enter_evidence.m @ 0:e9a9cd732c1e tip

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