wolffd@0: function engine = jtree_2TBN_inf_engine(bnet, varargin) wolffd@0: % JTREE_ONLINE_INF_ENGINE Online Junction tree inference algorithm for DBNs. wolffd@0: % engine = jtree_online_inf_engine(bnet, ...) wolffd@0: % wolffd@0: % The following optional arguments can be specified in the form of name/value pairs: wolffd@0: % [default value in brackets] wolffd@0: % wolffd@0: % clusters - specifies variables that must be grouped in the 1.5 slice DBN wolffd@0: % wolffd@0: % The same nodes must be observed in every slice. wolffd@0: % wolffd@0: % This uses the forwards interface of slice t-1 plus all of slice t. wolffd@0: % By contrast, jtree_dbn uses all of slice t-1 plus the backwards interface of slice t. wolffd@0: % See my thesis for details. wolffd@0: wolffd@0: wolffd@0: clusters = {}; wolffd@0: wolffd@0: args = varargin; wolffd@0: nargs = length(args); wolffd@0: for i=1:2:length(args) wolffd@0: switch args{i}, wolffd@0: case 'clusters', clusters = args{i+1}; wolffd@0: otherwise, error(['unrecognized argument ' args{i}]) wolffd@0: end wolffd@0: end wolffd@0: wolffd@0: engine.maximize = 0; wolffd@0: engine.evidence = []; wolffd@0: engine.node_sizes = []; wolffd@0: wolffd@0: int = compute_fwd_interface(bnet.intra, bnet.inter); wolffd@0: engine.interface = int; wolffd@0: ss = length(bnet.intra); wolffd@0: engine.nonint = mysetdiff(1:ss, int); wolffd@0: onodes = bnet.observed; wolffd@0: wolffd@0: bnet15 = mk_slice_and_half_dbn(bnet, int); wolffd@0: wolffd@0: % use unconstrained elimination, wolffd@0: % but force there to be a clique containing both interfaces wolffd@0: clusters(end+1:end+2) = {int, int+ss}; wolffd@0: engine.jtree_engine = jtree_inf_engine(bnet15, 'clusters', clusters, 'root', int+ss); wolffd@0: jtree_engine = struct(engine.jtree_engine); % violate object privacy wolffd@0: wolffd@0: engine.in_clq = clq_containing_nodes(engine.jtree_engine, int); wolffd@0: engine.out_clq = clq_containing_nodes(engine.jtree_engine, int+ss); wolffd@0: engine.clq_ass_to_node = jtree_engine.clq_ass_to_node; wolffd@0: engine.root = jtree_engine.root_clq; wolffd@0: wolffd@0: % Also create an engine just for slice 1 wolffd@0: bnet1 = mk_bnet(bnet.intra1, bnet.node_sizes_slice, 'discrete', myintersect(bnet.dnodes,1:ss), ... wolffd@0: 'equiv_class', bnet.equiv_class(:,1), 'observed', onodes); wolffd@0: for i=1:max(bnet1.equiv_class) wolffd@0: bnet1.CPD{i} = bnet.CPD{i}; wolffd@0: end wolffd@0: engine.jtree_engine1 = jtree_inf_engine(bnet1, 'clusters', {int}, 'root', int); wolffd@0: jtree_engine1 = struct(engine.jtree_engine1); % violate object privacy wolffd@0: engine.int_clq1 = clq_containing_nodes(engine.jtree_engine1, int); wolffd@0: engine.clq_ass_to_node1 = jtree_engine1.clq_ass_to_node; wolffd@0: engine.root1 = jtree_engine1.root_clq; wolffd@0: wolffd@0: engine.observed = [onodes onodes+ss]; wolffd@0: engine.observed1 = onodes; wolffd@0: engine.pot_type = determine_pot_type(bnet, onodes); wolffd@0: engine.slice_size = bnet.nnodes_per_slice; wolffd@0: wolffd@0: engine = class(engine, 'jtree_2TBN_inf_engine', inf_engine(bnet)); wolffd@0: