about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine
diff options
context:
space:
mode:
Diffstat (limited to 'sourcecodes/bnt-master/BNT/inference/online/@smoother_engine')
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/CVS/Entries8
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/bnet_from_engine.m5
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/enter_evidence.m21
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/find_mpe.m33
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/marginal_family.m6
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/marginal_nodes.m7
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/smoother_engine.m12
-rw-r--r--sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/update_engine.m5
10 files changed, 99 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/CVS/Entries b/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/CVS/Entries
new file mode 100644
index 00000000..d9c315a5
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/CVS/Entries
@@ -0,0 +1,8 @@
+/bnet_from_engine.m/1.1.1.1/Wed May 29 15:59:56 2002//
+/enter_evidence.m/1.1.1.1/Mon Jun 17 23:46:46 2002//
+/find_mpe.m/1.1.1.1/Mon Jun 17 23:50:16 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//
+/smoother_engine.m/1.1.1.1/Wed May 29 15:59:56 2002//
+/update_engine.m/1.1.1.1/Wed May 29 15:59:56 2002//
+D
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/CVS/Repository b/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/CVS/Repository
new file mode 100644
index 00000000..a10f8a08
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/inference/online/@smoother_engine
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/CVS/Root b/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/bnet_from_engine.m b/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/bnet_from_engine.m
new file mode 100644
index 00000000..b57ee5f4
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/bnet_from_engine.m
@@ -0,0 +1,5 @@
+function bnet = bnet_from_engine(engine)
+% BNET_FROM_ENGINE Return the bnet structure stored inside the engine (smoother_engine)
+% bnet = bnet_from_engine(engine)
+
+bnet = bnet_from_engine(engine.tbn_engine);
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/enter_evidence.m b/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/enter_evidence.m
new file mode 100644
index 00000000..299c2331
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/enter_evidence.m
@@ -0,0 +1,21 @@
+function [engine, LL] = enter_evidence(engine, ev)
+% ENTER_EVIDENCE Call the offline smoother
+% [engine, loglik] = enter_evidence(engine, evidence, ...)
+%
+% evidence{i,t} = [] if if X(i,t) is hidden, and otherwise contains its observed value (scalar or column vector)
+%
+
+T = size(ev, 2);
+f = cell(1,T);
+b = cell(1,T); % b{t}.clpot{c}
+ll = zeros(1,T);
+[f{1}, ll(1)] = fwd1(engine.tbn_engine, ev(:,1), 1);
+for t=2:T
+  [f{t}, ll(t)] = fwd(engine.tbn_engine, f{t-1}, ev(:,t), t);
+end
+LL = sum(ll);
+b{T} = backT(engine.tbn_engine, f{T}, T);
+for t=T-1:-1:1
+  b{t} = back(engine.tbn_engine, b{t+1}, f{t}, t);
+end
+engine.b = b;
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/find_mpe.m b/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/find_mpe.m
new file mode 100644
index 00000000..5415f120
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/find_mpe.m
@@ -0,0 +1,33 @@
+function mpe = find_mpe(engine, ev)
+% FIND_MPE Find the most probable explanation (Viterbi)
+% mpe = enter_evidence(engine, evidence, ...)
+%
+% evidence{i,t} = [] if if X(i,t) is hidden, and otherwise contains its observed value (scalar or column vector)
+%
+
+mpe = cell(size(ev));
+engine.tbn_engine = set_fields(engine.tbn_engine, 'maximize', 1);
+
+T = size(ev, 2);
+f = cell(1,T);
+b = cell(1,T); % b{t}.clpot{c}
+ll = zeros(1,T);
+[f{1}, ll(1)] = fwd1(engine.tbn_engine, ev(:,1), 1);
+for t=2:T
+  [f{t}, ll(t)] = fwd(engine.tbn_engine, f{t-1}, ev(:,t), t);
+end
+
+if T==1
+  [b{1}, mpe(:,1)] = backT_mpe(engine.tbn_engine, f{1}, ev(:,1), 1);
+else
+  [b{T}, mpe(:,T)] = backT_mpe(engine.tbn_engine, f{T}, ev(:,T-1:T), T);
+  for t=T-1:-1:2
+    [b{t}, mpe(:,t)] = back_mpe(engine.tbn_engine, b{t+1}, f{t}, ev(:,t-1:t), t);
+  end
+  t = 1;
+  [b{t}, mpe(:,t)] = back1_mpe(engine.tbn_engine, b{t+1}, f{t}, ev(:,1), t);
+end
+engine.b = b;
+  
+
+
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/marginal_family.m b/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/marginal_family.m
new file mode 100644
index 00000000..b7b0d7ec
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/marginal_family.m
@@ -0,0 +1,6 @@
+function marginal = marginal_family(engine, i, t, add_ev)
+% MARGINAL_FAMILY Compute the joint distribution on a set of family (smoother_engine)
+% function marginal = marginal_family(engine, i, t, add_ev)
+
+if nargin < 4, add_ev = 0; end
+marginal = marginal_family(engine.tbn_engine, engine.b{t}, i, t, add_ev);
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/marginal_nodes.m b/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/marginal_nodes.m
new file mode 100644
index 00000000..e8574c53
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/marginal_nodes.m
@@ -0,0 +1,7 @@
+function marginal = marginal_nodes(engine, nodes, t, add_ev)
+% MARGINAL_NODES Compute the joint distribution on a set of nodes (smoother_engine)
+% function marginal = marginal_nodes(engine, nodes, t, add_ev)
+
+if nargin < 4, add_ev = 0; end
+
+marginal = marginal_nodes(engine.tbn_engine, engine.b{t}, nodes, t, add_ev);
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/smoother_engine.m b/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/smoother_engine.m
new file mode 100644
index 00000000..adf7ede8
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/smoother_engine.m
@@ -0,0 +1,12 @@
+function engine = smoother_engine(tbn_engine)
+% SMOOTHER_ENGINE Create an engine which does offline (fixed-interval) smoothing in O(T) space/time
+% function engine = smoother_engine(tbn_engine)
+%
+% tbn_engine is any 2TBN inference engine which supports the following methods:
+% fwd, fwd1, back, backT, back, marginal_nodes and marginal_family.
+
+engine.tbn_engine = tbn_engine;
+engine.b = []; % space to store smoothed messages
+engine = class(engine, 'smoother_engine');
+%engine = class(engine, 'smoother_engine', inf_engine(bnet_from_engine(tbn_engine)));
+
diff --git a/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/update_engine.m b/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/update_engine.m
new file mode 100644
index 00000000..ffe0661e
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/inference/online/@smoother_engine/update_engine.m
@@ -0,0 +1,5 @@
+function engine = update_engine(engine, newCPDs)
+% UPDATE_ENGINE Update the engine to take into account the new parameters (smoother_engine).
+% engine = update_engine(engine, newCPDs)
+
+engine.tbn_engine = update_engine(engine.tbn_engine, newCPDs);