annotate toolboxes/FullBNT-1.0.7/bnt/inference/dynamic/@jtree_unrolled_dbn_inf_engine/jtree_unrolled_dbn_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_unrolled_dbn_inf_engine(bnet, T, varargin)
wolffd@0 2 % JTREE_UNROLLED_DBN_INF_ENGINE Unroll the DBN for T time-slices and apply jtree to the resulting static net
wolffd@0 3 % engine = jtree_unrolled_dbn_inf_engine(bnet, T, ...)
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 % useC - 1 means use jtree_C_inf_engine instead of jtree_inf_engine [0]
wolffd@0 9 % constrained - 1 means we constrain ourselves to eliminate slice t before t+1 [1]
wolffd@0 10 %
wolffd@0 11 % e.g., engine = jtree_unrolled_inf_engine(bnet, 'useC', 1);
wolffd@0 12
wolffd@0 13 % set default params
wolffd@0 14 N = length(bnet.intra);
wolffd@0 15 useC = 0;
wolffd@0 16 constrained = 1;
wolffd@0 17
wolffd@0 18 if nargin >= 3
wolffd@0 19 args = varargin;
wolffd@0 20 nargs = length(args);
wolffd@0 21 if isstr(args{1})
wolffd@0 22 for i=1:2:nargs
wolffd@0 23 switch args{i},
wolffd@0 24 case 'useC', useC = args{i+1};
wolffd@0 25 case 'constrained', constrained = 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 else
wolffd@0 31 error(['invalid argument name ' args{1}]);
wolffd@0 32 end
wolffd@0 33 end
wolffd@0 34
wolffd@0 35 bnet2 = dbn_to_bnet(bnet, T);
wolffd@0 36 ss = length(bnet.intra);
wolffd@0 37 engine.ss = ss;
wolffd@0 38
wolffd@0 39 % If constrained_order = 1 we constrain ourselves to eliminate slice t before t+1.
wolffd@0 40 % This prevents cliques containing nodes from far-apart time-slices.
wolffd@0 41 if constrained
wolffd@0 42 stages = num2cell(unroll_set(1:ss, ss, T), 1);
wolffd@0 43 else
wolffd@0 44 stages = { 1:length(bnet2.dag) };
wolffd@0 45 end
wolffd@0 46 if useC
wolffd@0 47 jengine = jtree_C_inf_engine(bnet2, 'stages', stages);
wolffd@0 48 else
wolffd@0 49 jengine = jtree_inf_engine(bnet2, 'stages', stages);
wolffd@0 50 end
wolffd@0 51
wolffd@0 52 engine.unrolled_engine = jengine;
wolffd@0 53 % we don't inherit from jtree_inf_engine, because that would only store bnet2,
wolffd@0 54 % and we would lose access to the DBN-specific fields like intra/inter
wolffd@0 55
wolffd@0 56 engine.nslices = T;
wolffd@0 57 engine = class(engine, 'jtree_unrolled_dbn_inf_engine', inf_engine(bnet));