about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine
diff options
context:
space:
mode:
Diffstat (limited to 'sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine')
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/CVS/Entries13
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/CVS/Entries.Log1
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/Old/CVS/Entries2
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/Old/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/Old/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/Old/jtree_2TBN_inf_engine.m116
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/back.m27
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/back1.m21
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/back1_mpe.m22
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/backT.m11
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/backT_mpe.m16
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/back_mpe.m28
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/fwd.m44
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/fwd1.m26
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/jtree_2TBN_inf_engine.m69
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/marginal_family.m12
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/marginal_nodes.m32
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/set_fields.m16
20 files changed, 460 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/CVS/Entries b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/CVS/Entries
new file mode 100644
index 00000000..b64945b2
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/CVS/Entries
@@ -0,0 +1,13 @@
+/back.m/1.1.1.1/Mon Jun 17 23:34:12 2002//
+/back1.m/1.1.1.1/Mon Jun 17 23:34:26 2002//
+/back1_mpe.m/1.1.1.1/Mon Jun 17 23:49:40 2002//
+/backT.m/1.1.1.1/Mon Jun 17 23:34:20 2002//
+/backT_mpe.m/1.1.1.1/Mon Jun 17 23:38:56 2002//
+/back_mpe.m/1.1.1.1/Sun Jul 21 00:32:52 2002//
+/fwd.m/1.1.1.1/Mon Jun 17 23:46:06 2002//
+/fwd1.m/1.1.1.1/Mon Jun 17 23:46:20 2002//
+/jtree_2TBN_inf_engine.m/1.1.1.1/Thu Nov 14 16:31:58 2002//
+/marginal_family.m/1.1.1.1/Wed May 29 15:59:56 2002//
+/marginal_nodes.m/1.1.1.1/Wed May 29 15:59:56 2002//
+/set_fields.m/1.1.1.1/Sun Jul 21 01:25:30 2002//
+D
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/CVS/Entries.Log b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/CVS/Entries.Log
new file mode 100644
index 00000000..24f16336
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/CVS/Entries.Log
@@ -0,0 +1 @@
+A D/Old////
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/CVS/Repository b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/CVS/Repository
new file mode 100644
index 00000000..7f0022ff
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/inference/online/@jtree_2TBN_inf_engine
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/CVS/Root b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/Old/CVS/Entries b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/Old/CVS/Entries
new file mode 100644
index 00000000..794b5de2
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/Old/CVS/Entries
@@ -0,0 +1,2 @@
+/jtree_2TBN_inf_engine.m/1.1.1.1/Wed May 29 15:59:56 2002//
+D
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/Old/CVS/Repository b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/Old/CVS/Repository
new file mode 100644
index 00000000..a7b1e665
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/Old/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/inference/online/@jtree_2TBN_inf_engine/Old
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/Old/CVS/Root b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/Old/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/Old/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/Old/jtree_2TBN_inf_engine.m b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/Old/jtree_2TBN_inf_engine.m
new file mode 100644
index 00000000..b271e583
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/Old/jtree_2TBN_inf_engine.m
@@ -0,0 +1,116 @@
+function engine = jtree_2TBN_inf_engine(bnet, varargin)
+% JTREE_ONLINE_INF_ENGINE Online Junction tree inference algorithm for DBNs.
+% engine = jtree_online_inf_engine(bnet, ...)
+%
+% The following optional arguments can be specified in the form of name/value pairs:
+% [default value in brackets]
+%
+% clusters - specifies variables that must be grouped in the 1.5 slice DBN
+% maximize - 1 means do max-product, 0 means sum-product [0]
+%
+% The same nodes must be observed in every slice.
+
+ss = length(bnet.intra);
+clusters = {};
+engine.maximize = 0;
+
+args = varargin;
+nargs = length(args);
+for i=1:2:length(args)
+  switch args{i},
+   case 'clusters', clusters = args{i+1};
+   case 'maximize', engine.maximize = args{i+1};
+   otherwise, error(['unrecognized argument ' args{i}])
+  end
+end
+
+engine.evidence = [];
+engine.node_sizes = [];
+
+%int = compute_interface_nodes(bnet.intra, bnet.inter);
+int = [];
+
+if 1
+% include nodes with any outgoing arcs
+for u=1:ss
+  if any(bnet.inter(u,:))
+    int = [int u];
+  end
+end
+end
+
+if 0
+% include nodes with any incoming  arcs
+incoming = [];
+for u=1:ss
+  if any(bnet.inter(:,u))
+    int = [int u];
+    incoming = [incoming u];
+  end
+end
+% include nodes which are parents of nodes with incoming
+for u=1:ss
+  cs = children(bnet.intra, u);
+  if ~isempty(cs) & mysubset(cs, incoming)
+    int = [int u];
+  end
+end
+int = unique(int);
+end % if
+
+int
+engine.interface = int;
+engine.nonint = mysetdiff(1:ss, int);
+
+onodes = bnet.observed;
+
+% Create a "1.5 slice" jtree, containing the interface nodes of slice 1
+% and all the nodes of slice 2
+% To keep the node numbering the same, we simply disconnect the non-interface nodes
+% from slice 1, and set their size to 1.
+% We do this to speed things up, and so that the likelihood is computed correctly - we do not need to do
+% this if we just want to compute marginals (i.e., we can include nodes whose potentials will
+% be left as all 1s).
+intra15 = bnet.intra;
+for i=engine.nonint(:)'
+  intra15(:,i) = 0;
+  intra15(i,:) = 0;
+end
+dag15 = [intra15      bnet.inter;
+	 zeros(ss)    bnet.intra];
+ns = bnet.node_sizes(:);
+%ns(engine.nonint) = 1; % disconnected nodes get size 1
+obs_nodes = [onodes(:) onodes(:)+ss];
+bnet15 = mk_bnet(dag15, ns, 'discrete', bnet.dnodes, 'equiv_class', bnet.equiv_class(:), ...
+		 'observed', obs_nodes(:));
+
+% use unconstrained elimination,
+% but force there to be a clique containing both interfaces
+clusters(end+1:end+2) = {int, int+ss};
+engine.jtree_engine = jtree_inf_engine(bnet15, 'clusters', clusters, 'root', int+ss);
+jtree_engine = struct(engine.jtree_engine); % violate object privacy
+
+engine.in_clq = clq_containing_nodes(engine.jtree_engine, int);
+engine.out_clq = clq_containing_nodes(engine.jtree_engine, int+ss);
+engine.clq_ass_to_node = jtree_engine.clq_ass_to_node;
+engine.root = jtree_engine.root_clq;
+
+% Also create an engine just for slice 1
+bnet1 = mk_bnet(bnet.intra1, bnet.node_sizes_slice, 'discrete', myintersect(bnet.dnodes,1:ss), ...
+		'equiv_class', bnet.equiv_class(:,1), 'observed', onodes);
+for i=1:max(bnet1.equiv_class)
+  bnet1.CPD{i} = bnet.CPD{i};
+end
+engine.jtree_engine1 = jtree_inf_engine(bnet1, 'clusters', {int}, 'root', int);
+jtree_engine1 = struct(engine.jtree_engine1); % violate object privacy
+engine.int_clq1 = clq_containing_nodes(engine.jtree_engine1, int);
+engine.clq_ass_to_node1 = jtree_engine1.clq_ass_to_node;
+engine.root1 = jtree_engine1.root_clq;
+
+engine.observed = [onodes onodes+ss];
+engine.observed1 = onodes;
+engine.pot_type = determine_pot_type(bnet, onodes);
+engine.slice_size = bnet.nnodes_per_slice;
+
+engine = class(engine, 'jtree_2TBN_inf_engine', inf_engine(bnet));
+
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/back.m b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/back.m
new file mode 100644
index 00000000..7f686d55
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/back.m
@@ -0,0 +1,27 @@
+function b = back(engine, bfuture, f, t)
+
+if f.t ~= t
+  error('mixed up time stamps')
+end
+if t==1
+  b = back1(engine, bfuture, f, t);
+  return;
+end
+
+bnet = bnet_from_engine(engine);
+ss = bnet.nnodes_per_slice;
+
+int = engine.interface;
+D = engine.in_clq;
+C = engine.out_clq;
+phiD = marginalize_pot(bfuture.clpot{D}, int, engine.maximize);
+phiD = set_domain_pot(phiD, int+ss); % shift to slice 2
+phiC = marginalize_pot(f.clpot{C}, int+ss, engine.maximize);
+ratio = divide_by_pot(phiD, phiC);
+f.clpot{C} = multiply_by_pot(f.clpot{C}, ratio);
+
+[b.clpot, seppot] = distribute_evidence(engine.jtree_engine, f.clpot, f.seppot);
+for c=1:length(b.clpot)
+  [b.clpot{c}, ll(c)] = normalize_pot(b.clpot{c});
+end
+b.t = t;
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/back1.m b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/back1.m
new file mode 100644
index 00000000..a8587a72
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/back1.m
@@ -0,0 +1,21 @@
+function b = back1(engine, bfuture, f, t)
+
+if t ~= 1
+  error('mixed up time stamps')
+end
+bnet = bnet_from_engine(engine);
+ss = bnet.nnodes_per_slice;
+
+int = engine.interface;
+D = engine.in_clq; % from J2
+C = engine.int_clq1; % from J1
+phiD = marginalize_pot(bfuture.clpot{D}, int, engine.maximize);
+phiC = marginalize_pot(f.clpot{C}, int, engine.maximize);
+ratio = divide_by_pot(phiD, phiC);
+f.clpot{C} = multiply_by_pot(f.clpot{C}, ratio);
+
+[b.clpot, seppot] = distribute_evidence(engine.jtree_engine1, f.clpot, f.seppot);
+for c=1:length(b.clpot)
+  [b.clpot{c}, ll(c)] = normalize_pot(b.clpot{c});
+end
+b.t = t;
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/back1_mpe.m b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/back1_mpe.m
new file mode 100644
index 00000000..b20bfa57
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/back1_mpe.m
@@ -0,0 +1,22 @@
+function [b, mpe] = back1_mpe(engine, bfuture, f, ev1, t)
+
+if t ~= 1
+  error('mixed up time stamps')
+end
+bnet = bnet_from_engine(engine);
+ss = bnet.nnodes_per_slice;
+maximize = 1;
+
+int = engine.interface;
+D = engine.in_clq; % from J2
+C = engine.int_clq1; % from J1
+phiD = marginalize_pot(bfuture.clpot{D}, int, maximize);
+phiC = marginalize_pot(f.clpot{C}, int, maximize);
+ratio = divide_by_pot(phiD, phiC);
+f.clpot{C} = multiply_by_pot(f.clpot{C}, ratio);
+
+[mpe, b.clpot] = find_max_config(engine.jtree_engine1, f.clpot, f.seppot, ev1);
+for c=1:length(b.clpot)
+  [b.clpot{c}, ll(c)] = normalize_pot(b.clpot{c});
+end
+b.t = t;
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/backT.m b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/backT.m
new file mode 100644
index 00000000..7f7a1b42
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/backT.m
@@ -0,0 +1,11 @@
+function b = backT(engine, f, t)
+
+if t==1
+  [b.clpot, seppot] = distribute_evidence(engine.jtree_engine1, f.clpot, f.seppot);
+else
+  [b.clpot, seppot] = distribute_evidence(engine.jtree_engine, f.clpot, f.seppot);
+end
+for c=1:length(b.clpot)
+  [b.clpot{c}, ll(c)] = normalize_pot(b.clpot{c});
+end
+b.t = t;
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/backT_mpe.m b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/backT_mpe.m
new file mode 100644
index 00000000..93084eae
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/backT_mpe.m
@@ -0,0 +1,16 @@
+function [b, mpe] = backT_mpe(engine, f, ev2, t)
+
+bnet = bnet_from_engine(engine);
+ss = bnet.nnodes_per_slice;
+
+if t==1
+  % ev2 is just the evidence on slice 1
+  [mpe, b.clpot] = find_max_config(engine.jtree_engine1, f.clpot, f.seppot, ev2);
+else
+  [mpe, b.clpot] = find_max_config(engine.jtree_engine, f.clpot, f.seppot, ev2);
+  mpe = mpe((1:ss)+ss); % extract values for slice 2
+end
+for c=1:length(b.clpot)
+  [b.clpot{c}, ll(c)] = normalize_pot(b.clpot{c});
+end
+b.t = t;
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/back_mpe.m b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/back_mpe.m
new file mode 100644
index 00000000..9fdba411
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/back_mpe.m
@@ -0,0 +1,28 @@
+function [b, mpe] = back_mpe(engine, bfuture, f, ev2, t)
+
+if f.t ~= t
+  error('mixed up time stamps')
+end
+if t==1
+  error('should call back1_mpe')
+end
+
+maximize = 1;
+bnet = bnet_from_engine(engine);
+ss = bnet.nnodes_per_slice;
+
+int = engine.interface;
+D = engine.in_clq;
+C = engine.out_clq;
+phiD = marginalize_pot(bfuture.clpot{D}, int, maximize);
+phiD = set_domain_pot(phiD, int+ss); % shift to slice 2
+phiC = marginalize_pot(f.clpot{C}, int+ss, maximize);
+ratio = divide_by_pot(phiD, phiC);
+f.clpot{C} = multiply_by_pot(f.clpot{C}, ratio);
+
+[mpe, b.clpot] = find_max_config(engine.jtree_engine, f.clpot, f.seppot, ev2);
+mpe = mpe((1:ss)+ss); % extract values for slice 2
+for c=1:length(b.clpot)
+  [b.clpot{c}, ll(c)] = normalize_pot(b.clpot{c});
+end
+b.t = t;
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/fwd.m b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/fwd.m
new file mode 100644
index 00000000..9c59cc3b
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/fwd.m
@@ -0,0 +1,44 @@
+function [f, logscale] = fwd(engine, fpast, ev, t)
+% Forwards pass.
+
+bnet = bnet_from_engine(engine);
+ss = bnet.nnodes_per_slice;
+
+ev2 = cell(ss, 2);
+ev2(:,1) = fpast.evidence;
+ev2(:,2) = ev;
+
+CPDpot = cell(1,ss);
+for n=1:ss
+  fam = family(bnet.dag, n, 2);
+  e = bnet.equiv_class(n, 2);
+  CPDpot{n} = convert_to_pot(bnet.CPD{e}, engine.pot_type, fam(:), ev2);
+end       
+f.evidence = ev;
+f.t = t;
+
+% get prior
+int = engine.interface;
+if fpast.t==1
+  prior = marginalize_pot(fpast.clpot{engine.int_clq1}, int, engine.maximize);
+else
+  prior = marginalize_pot(fpast.clpot{engine.out_clq}, int+ss, engine.maximize);
+  prior = set_domain_pot(prior, int); % shift back to slice 1
+end
+
+pots = [ {prior} CPDpot ];
+slice1 = 1:ss;
+slice2 = slice1 + ss; 
+CPDclqs = engine.clq_ass_to_node(slice2);
+D = engine.in_clq;
+clqs = [D CPDclqs];
+
+[f.clpot, f.seppot] =  init_pot(engine.jtree_engine, clqs, pots, engine.pot_type, engine.observed);
+[f.clpot, f.seppot] = collect_evidence(engine.jtree_engine, f.clpot, f.seppot);
+for c=1:length(f.clpot)
+  [f.clpot{c}, ll(c)] = normalize_pot(f.clpot{c});
+end
+logscale = ll(engine.root);
+
+
+
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/fwd1.m b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/fwd1.m
new file mode 100644
index 00000000..68de1e50
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/fwd1.m
@@ -0,0 +1,26 @@
+function [f, logscale] = fwd1(engine, ev, t)
+% Forwards pass for slice 1.
+
+bnet = bnet_from_engine(engine);
+ss = bnet.nnodes_per_slice;
+
+CPDpot = cell(1,ss);
+for n=1:ss
+  fam = family(bnet.dag, n, 1);
+  e = bnet.equiv_class(n, 1);
+  CPDpot{n} = convert_to_pot(bnet.CPD{e}, engine.pot_type, fam(:), ev);
+end       
+f.t = t;
+f.evidence = ev;
+
+pots = CPDpot;
+slice1 = 1:ss;
+CPDclqs = engine.clq_ass_to_node1(slice1);
+
+[f.clpot, f.seppot] =  init_pot(engine.jtree_engine1, CPDclqs, CPDpot, engine.pot_type, engine.observed1);
+[f.clpot, f.seppot] = collect_evidence(engine.jtree_engine1, f.clpot, f.seppot);
+for c=1:length(f.clpot)
+  [f.clpot{c}, ll(c)] = normalize_pot(f.clpot{c});
+end
+logscale = ll(engine.root1);
+
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/jtree_2TBN_inf_engine.m b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/jtree_2TBN_inf_engine.m
new file mode 100644
index 00000000..2d56445c
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/jtree_2TBN_inf_engine.m
@@ -0,0 +1,69 @@
+function engine = jtree_2TBN_inf_engine(bnet, varargin)
+% JTREE_ONLINE_INF_ENGINE Online Junction tree inference algorithm for DBNs.
+% engine = jtree_online_inf_engine(bnet, ...)
+%
+% The following optional arguments can be specified in the form of name/value pairs:
+% [default value in brackets]
+%
+% clusters - specifies variables that must be grouped in the 1.5 slice DBN
+%
+% The same nodes must be observed in every slice.
+%
+% This uses the forwards interface of slice t-1 plus all of slice t.
+% By contrast, jtree_dbn uses all of slice t-1 plus the backwards interface of slice t.
+% See my thesis for details.
+
+
+clusters = {};
+
+args = varargin;
+nargs = length(args);
+for i=1:2:length(args)
+  switch args{i},
+   case 'clusters', clusters = args{i+1};
+   otherwise, error(['unrecognized argument ' args{i}])
+  end
+end
+
+engine.maximize = 0;
+engine.evidence = [];
+engine.node_sizes = [];
+
+int = compute_fwd_interface(bnet.intra, bnet.inter);
+engine.interface = int;
+ss = length(bnet.intra);
+engine.nonint = mysetdiff(1:ss, int);
+onodes = bnet.observed;
+
+bnet15 = mk_slice_and_half_dbn(bnet, int);
+
+% use unconstrained elimination,
+% but force there to be a clique containing both interfaces
+clusters(end+1:end+2) = {int, int+ss};
+engine.jtree_engine = jtree_inf_engine(bnet15, 'clusters', clusters, 'root', int+ss);
+jtree_engine = struct(engine.jtree_engine); % violate object privacy
+
+engine.in_clq = clq_containing_nodes(engine.jtree_engine, int);
+engine.out_clq = clq_containing_nodes(engine.jtree_engine, int+ss);
+engine.clq_ass_to_node = jtree_engine.clq_ass_to_node;
+engine.root = jtree_engine.root_clq;
+
+% Also create an engine just for slice 1
+bnet1 = mk_bnet(bnet.intra1, bnet.node_sizes_slice, 'discrete', myintersect(bnet.dnodes,1:ss), ...
+		'equiv_class', bnet.equiv_class(:,1), 'observed', onodes);
+for i=1:max(bnet1.equiv_class)
+  bnet1.CPD{i} = bnet.CPD{i};
+end
+engine.jtree_engine1 = jtree_inf_engine(bnet1, 'clusters', {int}, 'root', int);
+jtree_engine1 = struct(engine.jtree_engine1); % violate object privacy
+engine.int_clq1 = clq_containing_nodes(engine.jtree_engine1, int);
+engine.clq_ass_to_node1 = jtree_engine1.clq_ass_to_node;
+engine.root1 = jtree_engine1.root_clq;
+
+engine.observed = [onodes onodes+ss];
+engine.observed1 = onodes;
+engine.pot_type = determine_pot_type(bnet, onodes);
+engine.slice_size = bnet.nnodes_per_slice;
+
+engine = class(engine, 'jtree_2TBN_inf_engine', inf_engine(bnet));
+
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/marginal_family.m b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/marginal_family.m
new file mode 100644
index 00000000..0b6e6186
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/marginal_family.m
@@ -0,0 +1,12 @@
+function m = marginal_family(engine, b, i, t, add_ev)
+% MARGINAL_FAMILY Compute the marginal on the specified family (jtree_2TBN)
+% marginal = marginal_family(engine, b, i, t, add_ev)
+
+bnet = bnet_from_engine(engine);
+if t==1
+  m = marginal_nodes(engine, b, family(bnet.dag, i), t, add_ev, 1);
+else
+  ss = length(bnet.intra);
+  fam = family(bnet.dag, i+ss);
+  m = marginal_nodes(engine, b, fam, t, add_ev, 1);
+end
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/marginal_nodes.m b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/marginal_nodes.m
new file mode 100644
index 00000000..e7ee2ae9
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/marginal_nodes.m
@@ -0,0 +1,32 @@
+function marginal = marginal_nodes(engine, b, nodes, t, add_ev, is_fam)
+% function marginal = marginal_nodes(engine, b, nodes, t, add_ev, is_fam) (jtree_2TBN)
+
+if nargin < 6, is_fam = 0; end
+ss = engine.slice_size;
+
+if ~is_fam & (t > 1) & all(nodes<=ss)
+  nodes = nodes + ss;
+end
+
+if t==1
+  c = clq_containing_nodes(engine.jtree_engine1, nodes, is_fam);
+else
+  c = clq_containing_nodes(engine.jtree_engine, nodes, is_fam);
+end
+if c == -1
+  error(['no clique contains ' nodes])
+end
+bigpot = b.clpot{c};
+pot = marginalize_pot(bigpot, nodes, engine.maximize);
+marginal = pot_to_marginal(pot);
+
+% we convert the domain to the unrolled numbering system
+% so that add_ev_to_dmarginal (maybe called in update_ess) extracts the right evidence.
+if t > 1
+  marginal.domain = nodes+(t-2)*engine.slice_size;
+end
+assert(~add_ev);
+
+
+
+
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/set_fields.m b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/set_fields.m
new file mode 100644
index 00000000..51df3b32
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@jtree_2TBN_inf_engine/set_fields.m
@@ -0,0 +1,16 @@
+function engine = set_fields(engine, varargin)
+% SET_FIELDS Set the fields for a generic engine
+% engine = set_fields(engine, name/value pairs)
+%
+% e.g., engine = set_fields(engine, 'maximize', 1)
+
+args = varargin;
+nargs = length(args);
+for i=1:2:nargs
+  switch args{i},
+   case 'maximize',
+     engine.maximize = args{i+1};
+     engine.jtree_engine = set_fields(engine.jtree_engine, 'maximize', args{i+1});
+     engine.jtree_engine1 = set_fields(engine.jtree_engine1, 'maximize', args{i+1});
+  end
+end