annotate toolboxes/FullBNT-1.0.7/bnt/inference/dynamic/@bk_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)
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 instead of 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 [ss T] = size(evidence);
wolffd@0 33 engine.filter = filter;
wolffd@0 34 engine.maximize = maximize;
wolffd@0 35 engine.T = T;
wolffd@0 36
wolffd@0 37 if maximize
wolffd@0 38 error('BK does not yet support max propagation')
wolffd@0 39 % because it calls enter_soft_evidence, not enter_evidence
wolffd@0 40 end
wolffd@0 41
wolffd@0 42 observed_bitv = ~isemptycell(evidence);
wolffd@0 43 onodes = find(observed_bitv);
wolffd@0 44 bnet = bnet_from_engine(engine);
wolffd@0 45 pot_type = determine_pot_type(bnet, onodes);
wolffd@0 46 CPDpot = convert_dbn_CPDs_to_pots(bnet, evidence, pot_type);
wolffd@0 47 [engine.clpot, loglik] = enter_soft_evidence(engine, CPDpot, observed_bitv, pot_type, filter);
wolffd@0 48