wolffd@0
|
1 function [engine, loglik] = enter_evidence(engine, evidence, varargin)
|
wolffd@0
|
2 % ENTER_EVIDENCE Add the specified evidence to the network (frontier)
|
wolffd@0
|
3 % [engine, loglik] = enter_evidence(engine, evidence, ...)
|
wolffd@0
|
4 %
|
wolffd@0
|
5 % evidence{i,t} = [] if if X(i,t) is hidden, and otherwise contains its observed value (scalar or column vector)
|
wolffd@0
|
6 %
|
wolffd@0
|
7 % The following optional arguments can be specified in the form of name/value pairs:
|
wolffd@0
|
8 % [default value in brackets]
|
wolffd@0
|
9 %
|
wolffd@0
|
10 % maximize - if 1, does max-product (not yet supported), else sum-product [0]
|
wolffd@0
|
11 % filter - if 1, do filtering, else smoothing [0]
|
wolffd@0
|
12 %
|
wolffd@0
|
13 % e.g., engine = enter_evidence(engine, ev, 'maximize', 1)
|
wolffd@0
|
14
|
wolffd@0
|
15 maximize = 0;
|
wolffd@0
|
16 filter = 0;
|
wolffd@0
|
17
|
wolffd@0
|
18 % parse optional params
|
wolffd@0
|
19 args = varargin;
|
wolffd@0
|
20 nargs = length(args);
|
wolffd@0
|
21 if nargs > 0
|
wolffd@0
|
22 for i=1:2:nargs
|
wolffd@0
|
23 switch args{i},
|
wolffd@0
|
24 case 'maximize', maximize = args{i+1};
|
wolffd@0
|
25 case 'filter', filter = args{i+1};
|
wolffd@0
|
26 otherwise,
|
wolffd@0
|
27 error(['invalid argument name ' args{i}]);
|
wolffd@0
|
28 end
|
wolffd@0
|
29 end
|
wolffd@0
|
30 end
|
wolffd@0
|
31
|
wolffd@0
|
32 assert(~maximize);
|
wolffd@0
|
33
|
wolffd@0
|
34 [ss T] = size(evidence);
|
wolffd@0
|
35 bnet = bnet_from_engine(engine);
|
wolffd@0
|
36 onodes = find(~isemptycell(evidence));
|
wolffd@0
|
37 cnodes = unroll_set(bnet.cnodes(:), ss, T);
|
wolffd@0
|
38 pot_type = determine_pot_type(bnet, onodes);
|
wolffd@0
|
39
|
wolffd@0
|
40 CPDpot = convert_dbn_CPDs_to_pots(bnet, evidence, pot_type);
|
wolffd@0
|
41
|
wolffd@0
|
42 [engine.fwdback, loglik, engine.fwd_frontier, engine.back_frontier] = ...
|
wolffd@0
|
43 enter_soft_evidence(engine, CPDpot, onodes, pot_type, filter);
|
wolffd@0
|
44
|