annotate toolboxes/FullBNT-1.0.7/bnt/inference/dynamic/@bk_ff_hmm_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
rev   line source
wolffd@0 1 function [engine, loglik] = enter_evidence(engine, evidence, varargin)
wolffd@0 2 % ENTER_EVIDENCE Add the specified evidence to the network (bk_ff_hmm)
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 bnet = bnet_from_engine(engine);
wolffd@0 35 ss = length(bnet.intra);
wolffd@0 36 onodes = bnet.observed;
wolffd@0 37 hnodes = mysetdiff(1:ss, onodes);
wolffd@0 38 T = size(evidence, 2);
wolffd@0 39 assertBNT(~any(isemptycell(evidence(onodes,:))));
wolffd@0 40
wolffd@0 41 obslik = mk_hmm_obs_lik_mat(bnet, onodes, evidence);
wolffd@0 42
wolffd@0 43 ns = bnet.node_sizes_slice;
wolffd@0 44 ns(onodes) = 1;
wolffd@0 45
wolffd@0 46 [gamma, loglik, marginals, marginalsT] = bk_ff_fb(engine.prior, engine.transmat, obslik, filter, hnodes, ns);
wolffd@0 47
wolffd@0 48 for t=1:T
wolffd@0 49 for i=hnodes(:)'
wolffd@0 50 engine.marginals{i,t} = pot_to_marginal(marginalsT{i,t});
wolffd@0 51 end
wolffd@0 52 for i=onodes(:)'
wolffd@0 53 m.domain = i + (t-1)*ss;
wolffd@0 54 m.T = 1;
wolffd@0 55 engine.marginals{i,t} = m;
wolffd@0 56 end
wolffd@0 57 end
wolffd@0 58
wolffd@0 59
wolffd@0 60