annotate toolboxes/FullBNT-1.0.7/bnt/inference/online/@jtree_2TBN_inf_engine/jtree_2TBN_inf_engine.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 = jtree_2TBN_inf_engine(bnet, varargin)
wolffd@0 2 % JTREE_ONLINE_INF_ENGINE Online Junction tree inference algorithm for DBNs.
wolffd@0 3 % engine = jtree_online_inf_engine(bnet, ...)
wolffd@0 4 %
wolffd@0 5 % The following optional arguments can be specified in the form of name/value pairs:
wolffd@0 6 % [default value in brackets]
wolffd@0 7 %
wolffd@0 8 % clusters - specifies variables that must be grouped in the 1.5 slice DBN
wolffd@0 9 %
wolffd@0 10 % The same nodes must be observed in every slice.
wolffd@0 11 %
wolffd@0 12 % This uses the forwards interface of slice t-1 plus all of slice t.
wolffd@0 13 % By contrast, jtree_dbn uses all of slice t-1 plus the backwards interface of slice t.
wolffd@0 14 % See my thesis for details.
wolffd@0 15
wolffd@0 16
wolffd@0 17 clusters = {};
wolffd@0 18
wolffd@0 19 args = varargin;
wolffd@0 20 nargs = length(args);
wolffd@0 21 for i=1:2:length(args)
wolffd@0 22 switch args{i},
wolffd@0 23 case 'clusters', clusters = args{i+1};
wolffd@0 24 otherwise, error(['unrecognized argument ' args{i}])
wolffd@0 25 end
wolffd@0 26 end
wolffd@0 27
wolffd@0 28 engine.maximize = 0;
wolffd@0 29 engine.evidence = [];
wolffd@0 30 engine.node_sizes = [];
wolffd@0 31
wolffd@0 32 int = compute_fwd_interface(bnet.intra, bnet.inter);
wolffd@0 33 engine.interface = int;
wolffd@0 34 ss = length(bnet.intra);
wolffd@0 35 engine.nonint = mysetdiff(1:ss, int);
wolffd@0 36 onodes = bnet.observed;
wolffd@0 37
wolffd@0 38 bnet15 = mk_slice_and_half_dbn(bnet, int);
wolffd@0 39
wolffd@0 40 % use unconstrained elimination,
wolffd@0 41 % but force there to be a clique containing both interfaces
wolffd@0 42 clusters(end+1:end+2) = {int, int+ss};
wolffd@0 43 engine.jtree_engine = jtree_inf_engine(bnet15, 'clusters', clusters, 'root', int+ss);
wolffd@0 44 jtree_engine = struct(engine.jtree_engine); % violate object privacy
wolffd@0 45
wolffd@0 46 engine.in_clq = clq_containing_nodes(engine.jtree_engine, int);
wolffd@0 47 engine.out_clq = clq_containing_nodes(engine.jtree_engine, int+ss);
wolffd@0 48 engine.clq_ass_to_node = jtree_engine.clq_ass_to_node;
wolffd@0 49 engine.root = jtree_engine.root_clq;
wolffd@0 50
wolffd@0 51 % Also create an engine just for slice 1
wolffd@0 52 bnet1 = mk_bnet(bnet.intra1, bnet.node_sizes_slice, 'discrete', myintersect(bnet.dnodes,1:ss), ...
wolffd@0 53 'equiv_class', bnet.equiv_class(:,1), 'observed', onodes);
wolffd@0 54 for i=1:max(bnet1.equiv_class)
wolffd@0 55 bnet1.CPD{i} = bnet.CPD{i};
wolffd@0 56 end
wolffd@0 57 engine.jtree_engine1 = jtree_inf_engine(bnet1, 'clusters', {int}, 'root', int);
wolffd@0 58 jtree_engine1 = struct(engine.jtree_engine1); % violate object privacy
wolffd@0 59 engine.int_clq1 = clq_containing_nodes(engine.jtree_engine1, int);
wolffd@0 60 engine.clq_ass_to_node1 = jtree_engine1.clq_ass_to_node;
wolffd@0 61 engine.root1 = jtree_engine1.root_clq;
wolffd@0 62
wolffd@0 63 engine.observed = [onodes onodes+ss];
wolffd@0 64 engine.observed1 = onodes;
wolffd@0 65 engine.pot_type = determine_pot_type(bnet, onodes);
wolffd@0 66 engine.slice_size = bnet.nnodes_per_slice;
wolffd@0 67
wolffd@0 68 engine = class(engine, 'jtree_2TBN_inf_engine', inf_engine(bnet));
wolffd@0 69