about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/examples/dynamic
diff options
context:
space:
mode:
Diffstat (limited to 'sourcecodes/bnt-master/BNT/examples/dynamic')
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/CVS/Entries38
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/CVS/Entries.Log3
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/CVS/Entries9
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/CVS/Entries.Log5
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/CVS/Entries6
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/Old/CVS/Entries2
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/Old/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/Old/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/Old/mk_map_hhmm.m156
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/disp_map_hhmm.m13
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/learn_map.m40
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/mk_map_hhmm.m181
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/mk_rnd_map_hhmm.m73
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/sample_from_map.m41
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/CVS/Entries6
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/Old/CVS/Entries2
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/Old/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/Old/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/Old/mgram2.m191
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/letter2num.m12
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/mgram1.m116
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/mgram2.m200
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/mgram3.m235
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/num2letter.m10
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/CVS/Entries5
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/fixed_args_mk_motif_hhmm.m99
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/learn_motif_hhmm.m75
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/mk_motif_hhmm.m137
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/sample_motif_hhmm.m10
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/CVS/Entries8
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/mk_abcd_hhmm.m109
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/mk_arrow_alpha_hhmm3.m86
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/mk_hhmm2.m111
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/mk_hhmm3.m181
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/mk_hhmm3_args.m165
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/motif_hhmm.m95
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/remove_hhmm_end_state.m37
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/CVS/Entries14
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/CVS/Entries5
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/learn_square_hhmm.m294
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/mk_square_hhmm.m183
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/plot_square_hhmm.m32
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/sample_square_hhmm.m160
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/get_square_data.m70
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/hhmm_inference.m13
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/is_F2_true_D3.m12
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/learn_square_hhmm_cts.m152
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/learn_square_hhmm_discrete.m171
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/mk_square_hhmm.m180
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/plot_square_hhmm.m27
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/sample_square_hhmm_cts.m20
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/sample_square_hhmm_discrete.m20
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/square4.matbin0 -> 34672 bytes
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/square4_cases.matbin0 -> 156432 bytes
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/test_square_fig.m1310
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/test_square_fig.matbin0 -> 5304 bytes
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/abcd_hhmm.m97
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/add_hhmm_end_state.m34
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/hhmm_jtree_clqs.m143
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/mk_hhmm.m258
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/mk_hhmm_topo.m76
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/mk_hhmm_topo_F1.m65
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/pretty_print_hhmm_parse.m67
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/remove_hhmm_end_state.m41
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/Old/CVS/Entries8
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/Old/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/Old/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/Old/chmm1.m40
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/Old/cmp_inference.m75
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/Old/kalman1.m127
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/Old/old.water1.m48
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/Old/online1.m59
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/Old/online2.m33
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/Old/scg_dbn.m70
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/CVS/Entries7
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/CVS/Entries5
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/offline_loopy_slam.m231
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/paskin1.m238
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/skf_data_assoc_gmux2.m155
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/slam_kf.m172
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/mk_gmux_robot_dbn.m85
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/mk_linear_slam.m164
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/slam_kf.m78
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/slam_offline_loopy.m59
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/slam_partial_kf.m107
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/slam_stationary_loopy.m155
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/arhmm1.m42
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/bat1.m44
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/bkff1.m23
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/chmm1.m41
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/cmp_inference_dbn.m100
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/cmp_learning_dbn.m89
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/cmp_online_inference.m97
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/dhmm1.m66
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/ehmm1.m24
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/fhmm_infer.m324
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/filter_test1.m24
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/ghmm1.m64
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/ho1.m156
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/jtree_clq_test.m150
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/jtree_clq_test2.m23
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/kalman1.m66
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/kjaerulff1.m55
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/loopy_dbn1.m24
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/mhmm1.m85
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/mildew1.m30
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/mk_bat_dbn.m63
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/mk_chmm.m103
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/mk_collage_from_clqs.m44
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/mk_fhmm.m58
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/mk_mildew_dbn.m31
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/mk_orig_bat_dbn.m198
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/mk_orig_water_dbn.m121
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/mk_ps_from_clqs.m44
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/mk_uffe_dbn.m14
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/mk_water_dbn.m68
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/orig_water1.m28
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/reveal1.m73
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/scg_dbn.m39
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/skf_data_assoc_gmux.m139
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/viterbi1.m47
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/water1.m20
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/water2.m22
143 files changed, 10482 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/CVS/Entries b/sourcecodes/bnt-master/BNT/examples/dynamic/CVS/Entries
new file mode 100644
index 00000000..6f98ef27
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/CVS/Entries
@@ -0,0 +1,38 @@
+/arhmm1.m/1.1.1.1/Thu Nov 14 01:03:34 2002//
+/bat1.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/bkff1.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/chmm1.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/cmp_inference_dbn.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/cmp_learning_dbn.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/cmp_online_inference.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/dhmm1.m/1.1.1.1/Sun May  4 22:23:18 2003//
+/ehmm1.m/1.1.1.1/Sat Jan 18 22:16:24 2003//
+/fhmm_infer.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/filter_test1.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/ghmm1.m/1.1.1.1/Sun May  4 22:23:32 2003//
+/ho1.m/1.1.1.1/Fri Mar 28 17:22:36 2003//
+/jtree_clq_test.m/1.1.1.1/Sat Jan 18 22:16:38 2003//
+/jtree_clq_test2.m/1.1.1.1/Thu Oct 10 23:45:12 2002//
+/kalman1.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/kjaerulff1.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/loopy_dbn1.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/mhmm1.m/1.1.1.1/Sun May  4 22:23:40 2003//
+/mildew1.m/1.1.1.1/Thu Jun 20 20:30:24 2002//
+/mk_bat_dbn.m/1.1.1.1/Mon Jun  7 19:07:18 2004//
+/mk_chmm.m/1.1.1.1/Tue May 11 19:23:14 2004//
+/mk_collage_from_clqs.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/mk_fhmm.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/mk_mildew_dbn.m/1.1.1.1/Thu Oct 10 23:14:36 2002//
+/mk_orig_bat_dbn.m/1.1.1.1/Wed Feb  4 23:53:06 2004//
+/mk_orig_water_dbn.m/1.1.1.1/Sat Jan 31 02:57:52 2004//
+/mk_ps_from_clqs.m/1.1.1.1/Wed Oct  9 20:36:56 2002//
+/mk_uffe_dbn.m/1.1.1.1/Thu Oct 10 23:14:54 2002//
+/mk_water_dbn.m/1.1.1.1/Tue May 11 18:45:38 2004//
+/orig_water1.m/1.1.1.1/Mon Nov 22 22:41:42 2004//
+/reveal1.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/scg_dbn.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/skf_data_assoc_gmux.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/viterbi1.m/1.1.1.1/Tue May 13 14:35:40 2003//
+/water1.m/1.1.1.1/Thu Nov 14 20:07:56 2002//
+/water2.m/1.1.1.1/Thu Nov 14 20:33:42 2002//
+D
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/CVS/Entries.Log b/sourcecodes/bnt-master/BNT/examples/dynamic/CVS/Entries.Log
new file mode 100644
index 00000000..0634c982
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/CVS/Entries.Log
@@ -0,0 +1,3 @@
+A D/HHMM////
+A D/Old////
+A D/SLAM////
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/CVS/Repository b/sourcecodes/bnt-master/BNT/examples/dynamic/CVS/Repository
new file mode 100644
index 00000000..587019a2
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/examples/dynamic
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/CVS/Root b/sourcecodes/bnt-master/BNT/examples/dynamic/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/CVS/Entries b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/CVS/Entries
new file mode 100644
index 00000000..6c5b3923
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/CVS/Entries
@@ -0,0 +1,9 @@
+/abcd_hhmm.m/1.1.1.1/Sat Sep 21 21:37:54 2002//
+/add_hhmm_end_state.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/hhmm_jtree_clqs.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/mk_hhmm.m/1.1.1.1/Sat Sep 21 20:58:06 2002//
+/mk_hhmm_topo.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/mk_hhmm_topo_F1.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/pretty_print_hhmm_parse.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/remove_hhmm_end_state.m/1.1.1.1/Mon Dec 16 19:16:50 2002//
+D
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/CVS/Entries.Log b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/CVS/Entries.Log
new file mode 100644
index 00000000..1b0fe64f
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/CVS/Entries.Log
@@ -0,0 +1,5 @@
+A D/Map////
+A D/Mgram////
+A D/Motif////
+A D/Old////
+A D/Square////
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/CVS/Repository b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/CVS/Repository
new file mode 100644
index 00000000..2ba8b9e6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/examples/dynamic/HHMM
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/CVS/Root b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/CVS/Entries b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/CVS/Entries
new file mode 100644
index 00000000..dc32f52b
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/CVS/Entries
@@ -0,0 +1,6 @@
+/disp_map_hhmm.m/1.1.1.1/Tue Sep 24 22:45:56 2002//
+/learn_map.m/1.1.1.1/Sat Jan 11 18:48:46 2003//
+/mk_map_hhmm.m/1.1.1.1/Tue Sep 24 10:49:52 2002//
+/mk_rnd_map_hhmm.m/1.1.1.1/Tue Sep 24 22:13:48 2002//
+/sample_from_map.m/1.1.1.1/Tue Sep 24 13:02:30 2002//
+D/Old////
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/CVS/Repository b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/CVS/Repository
new file mode 100644
index 00000000..66b47bbc
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/examples/dynamic/HHMM/Map
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/CVS/Root b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/Old/CVS/Entries b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/Old/CVS/Entries
new file mode 100644
index 00000000..6079d451
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/Old/CVS/Entries
@@ -0,0 +1,2 @@
+/mk_map_hhmm.m/1.1.1.1/Tue Sep 24 07:02:44 2002//
+D
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/Old/CVS/Repository b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/Old/CVS/Repository
new file mode 100644
index 00000000..354057a9
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/Old/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/examples/dynamic/HHMM/Map/Old
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/Old/CVS/Root b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/Old/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/Old/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/Old/mk_map_hhmm.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/Old/mk_map_hhmm.m
new file mode 100644
index 00000000..7b646745
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/Old/mk_map_hhmm.m
@@ -0,0 +1,156 @@
+function bnet = mk_map_hhmm(varargin)
+
+% p is the prob of a successful move (defines the reliability of motors)
+p = 1;
+num_obs_nodes = 1;
+
+for i=1:2:length(varargin)
+  switch varargin{i},
+   case 'p', p = varargin{i+1};
+   case 'numobs', num_obs_node = varargin{i+1};
+  end
+end
+
+
+q = 1-p;
+
+% assign numbers to the nodes in topological order
+U = 1; A = 2; C = 3; F = 4; O = 5;
+
+% create graph structure
+
+ss = 5; % slice size
+intra = zeros(ss,ss);
+intra(U,F)=1;
+intra(A,[C F O])=1;
+intra(C,[F O])=1;
+
+inter = zeros(ss,ss);
+inter(U,[A C])=1;
+inter(A,[A C])=1;
+inter(F,[A C])=1;
+inter(C,C)=1;
+
+% node sizes
+ns = zeros(1,ss);
+ns(U) = 2; % left/right
+ns(A) = 2;
+ns(C) = 3;
+ns(F) = 2;
+ns(O) = 5; % we will assign each state a unique symbol
+l = 1; r = 2; % left/right
+L = 1; R = 2;
+
+% Make the DBN
+bnet = mk_dbn(intra, inter, ns, 'observed', O);
+eclass = bnet.equiv_class;
+
+
+
+% Define CPDs for slice 1
+% We clamp all of them, i.e., do not try to learn them.
+
+% uniform probs over actions (the input could be chosen from a policy)
+bnet.CPD{eclass(U,1)} = tabular_CPD(bnet, U, 'CPT', mk_stochastic(ones(ns(U),1)), ...
+				    'adjustable', 0);
+
+% uniform probs over starting abstract state
+bnet.CPD{eclass(A,1)} = tabular_CPD(bnet, A, 'CPT', mk_stochastic(ones(ns(A),1)), ...
+				    'adjustable', 0);
+
+% Uniform probs over starting concrete state, modulo the fact
+% that corridor 2 is only of length 2.
+CPT = zeros(ns(A), ns(C)); % CPT(i,j) = P(C starts in j | A=i)
+CPT(1, :) = [1/3 1/3 1/3];
+CPT(2, :) = [1/2 1/2 0];
+bnet.CPD{eclass(C,1)} = tabular_CPD(bnet, C, 'CPT', CPT, 'adjustable', 0);
+
+% Termination probs
+CPT = zeros(ns(U), ns(A), ns(C), ns(F));
+CPT(r,1,1,:) = [1 0];
+CPT(r,1,2,:) = [1 0];
+CPT(r,1,3,:) = [q p];
+CPT(r,2,1,:) = [1 0];
+CPT(r,2,2,:) = [q p];
+CPT(l,1,1,:) = [q p];
+CPT(l,1,2,:) = [1 0];
+CPT(l,1,3,:) = [1 0];
+CPT(l,2,1,:) = [q p];
+CPT(l,2,2,:) = [1 0];
+
+bnet.CPD{eclass(F,1)} = tabular_CPD(bnet, F, 'CPT', CPT);
+
+
+% Assign each state a unique observation
+CPT = zeros(ns(A), ns(C), ns(O));
+CPT(1,1,1)=1; 
+CPT(1,2,2)=1;
+CPT(1,3,3)=1;
+CPT(2,1,4)=1;
+CPT(2,2,5)=1;
+%CPT(2,3,:) undefined
+
+bnet.CPD{eclass(O,1)} = tabular_CPD(bnet, O, 'CPT', CPT);
+
+
+% Define the CPDs for slice 2
+
+% Abstract
+
+% Since the top level never resets, the starting distribution is irrelevant:
+% A2 will be determined by sampling from transmat(A1,:).
+% But the code requires we specify it anyway; we make it all 0s, a dummy value.
+startprob = zeros(ns(U), ns(A));
+
+transmat = zeros(ns(U), ns(A), ns(A));
+transmat(R,1,:) = [q p];
+transmat(R,2,:) = [0 1];
+transmat(L,1,:) = [1 0];
+transmat(L,2,:) = [p q];
+
+% Qps are the parents we condition the parameters on, in this case just
+% the past action.
+bnet.CPD{eclass(A,2)} = hhmm2Q_CPD(bnet, A+ss, 'Fbelow', F, ...
+				  'startprob', startprob, 'transprob', transmat);
+
+
+
+% Concrete
+
+transmat = zeros(ns(C), ns(U), ns(A), ns(C));
+transmat(1,r,1,:) = [q p 0.0];
+transmat(2,r,1,:) = [0.0 q p];
+transmat(3,r,1,:) = [0.0 0.0 1.0];
+transmat(1,r,2,:) = [q p 0.0];
+transmat(2,r,2,:) = [0.0 1.0 0.0];
+%
+transmat(1,l,1,:) = [1.0 0.0 0.0];
+transmat(2,l,1,:) = [p q 0.0];
+transmat(3,l,1,:) = [0.0 p q];
+transmat(1,l,2,:) = [1.0 0.0 0.0];
+transmat(2,l,2,:) = [p q 0.0];
+
+% Add a new dimension for A(t-1), by copying old vals,
+% so the matrix is the same size as startprob
+
+
+transmat = reshape(transmat, [ns(C) ns(U) ns(A) 1 ns(C)]);
+transmat = repmat(transmat, [1 1 1 ns(A) 1]);
+
+% startprob(C(t-1), U(t-1), A(t-1), A(t), C(t))
+startprob = zeros(ns(C), ns(U), ns(A), ns(A), ns(C));
+startprob(1,L,1,1,:) = [1.0 0.0 0.0];
+startprob(3,R,1,2,:) = [1.0 0.0 0.0];
+startprob(3,R,1,1,:) = [0.0 0.0 1.0];
+% 
+startprob(1,L,2,1,:) = [0.0 0.0 010];
+startprob(2,L,2,1,:) = [1.0 0.0 0.0];
+startprob(2,R,2,2,:) = [0.0 1.0 0.0];
+
+% want transmat(U,A,C,At,Ct), ie. in topo order
+transmat = permute(transmat, [2 3 1 4 5]);
+startprob  = permute(startprob, [2 3 1 4 5]);
+bnet.CPD{eclass(C,2)} = hhmm2Q_CPD(bnet, C+ss, 'Fself', F, ...
+				  'startprob', startprob, 'transprob', transmat);
+
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/disp_map_hhmm.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/disp_map_hhmm.m
new file mode 100644
index 00000000..0aadf2bb
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/disp_map_hhmm.m
@@ -0,0 +1,13 @@
+function disp_map_hhmm(bnet)
+
+eclass = bnet.equiv_class;
+U = 1; A = 2; C = 3; F = 4;
+
+S = struct(bnet.CPD{eclass(A,2)});
+disp('abstract trans')
+dispcpt(S.transprob)
+
+S = struct(bnet.CPD{eclass(C,2)});
+disp('concrete trans for go left') % UAC AC
+dispcpt(squeeze(S.transprob(1,:,:,:,:)))
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/learn_map.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/learn_map.m
new file mode 100644
index 00000000..ac36586a
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/learn_map.m
@@ -0,0 +1,40 @@
+seed = 1;
+rand('state', seed);
+randn('state', seed);
+
+obs_model = 'unique';  % each cell has a unique label (essentially fully observable)
+%obs_model = 'four'; % each cell generates 4 observations, NESW
+
+% Generate the true network, and a randomization of it
+realnet = mk_map_hhmm('p', 0.9, 'obs_model', obs_model);
+rndnet = mk_rnd_map_hhmm('obs_model', obs_model);
+eclass = realnet.equiv_class;
+U = 1; A = 2; C = 3; F = 4; onodes = 5;
+
+ss = realnet.nnodes_per_slice;
+T = 100;
+evidence = sample_dbn(realnet, 'length', T);
+ev = cell(ss,T);
+ev(onodes,:) = evidence(onodes,:);
+
+infeng = jtree_dbn_inf_engine(rndnet);
+
+if 0
+% suppose we do not observe the final finish node, but only know 
+% it is more likely to be on that off
+ev2 = ev;
+infeng = enter_evidence(infeng, ev2, 'soft_evidence_nodes', [F T], 'soft_evidence',  {[0.3 0.7]'});
+end
+
+
+learnednet = learn_params_dbn_em(infeng, {evidence}, 'max_iter', 5);
+
+disp('real model')
+disp_map_hhmm(realnet)
+
+disp('learned model')
+disp_map_hhmm(learnednet)
+
+disp('rnd model')
+disp_map_hhmm(rndnet)
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/mk_map_hhmm.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/mk_map_hhmm.m
new file mode 100644
index 00000000..7b077ddb
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/mk_map_hhmm.m
@@ -0,0 +1,181 @@
+function bnet = mk_map_hhmm(varargin)
+
+% p is the prob of a successful move (defines the reliability of motors)
+p = 1;
+obs_model = 'unique';
+
+for i=1:2:length(varargin)
+  switch varargin{i},
+   case 'p', p = varargin{i+1};
+   case 'obs_model', obs_model = varargin{i+1};
+  end
+end
+
+
+q = 1-p;
+unique_obs = strcmp(obs_model, 'unique');
+
+% assign numbers to the nodes in topological order
+U = 1; A = 2; C = 3; F = 4;
+if unique_obs
+  onodes = 5;
+else
+  N = 5; E = 6; S = 7; W = 8; % north, east, south, west
+  onodes = [N E S W];
+end
+
+% create graph structure
+
+ss = 4 + length(onodes); % slice size
+intra = zeros(ss,ss);
+intra(U,F)=1;
+intra(A,[C F onodes])=1;
+intra(C,[F onodes])=1;
+
+inter = zeros(ss,ss);
+inter(U,[A C])=1;
+inter(A,[A C])=1;
+inter(F,[A C])=1;
+inter(C,C)=1;
+
+% node sizes
+ns = zeros(1,ss);
+ns(U) = 2; % left/right
+ns(A) = 2;
+ns(C) = 3;
+ns(F) = 2;
+if unique_obs
+  ns(onodes) = 5; % we will assign each state a unique symbol
+else
+  ns(onodes) = 2;
+end
+l = 1; r = 2; % left/right
+L = 1; R = 2;
+
+% Make the DBN
+bnet = mk_dbn(intra, inter, ns, 'observed', onodes);
+eclass = bnet.equiv_class;
+
+
+
+% Define CPDs for slice 1
+% We clamp all the CPDs that are not tied,
+% since we cannot learn them from a single sequence.
+
+% uniform probs over actions (the input could be chosen from a policy)
+bnet.CPD{eclass(U,1)} = tabular_CPD(bnet, U, 'CPT', mk_stochastic(ones(ns(U),1)), ...
+				    'adjustable', 0);
+
+% uniform probs over starting abstract state
+bnet.CPD{eclass(A,1)} = tabular_CPD(bnet, A, 'CPT', mk_stochastic(ones(ns(A),1)), ...
+				    'adjustable', 0);
+
+% Uniform probs over starting concrete state, modulo the fact
+% that corridor 2 is only of length 2.
+CPT = zeros(ns(A), ns(C)); % CPT(i,j) = P(C starts in j | A=i)
+CPT(1, :) = [1/3 1/3 1/3];
+CPT(2, :) = [1/2 1/2 0];
+bnet.CPD{eclass(C,1)} = tabular_CPD(bnet, C, 'CPT', CPT, 'adjustable', 0);
+
+% Termination probs
+CPT = zeros(ns(U), ns(A), ns(C), ns(F));
+CPT(r,1,1,:) = [1 0];
+CPT(r,1,2,:) = [1 0];
+CPT(r,1,3,:) = [q p];
+CPT(r,2,1,:) = [1 0];
+CPT(r,2,2,:) = [q p];
+CPT(l,1,1,:) = [q p];
+CPT(l,1,2,:) = [1 0];
+CPT(l,1,3,:) = [1 0];
+CPT(l,2,1,:) = [q p];
+CPT(l,2,2,:) = [1 0];
+
+bnet.CPD{eclass(F,1)} = tabular_CPD(bnet, F, 'CPT', CPT);
+
+
+% Observation model
+if unique_obs
+  CPT = zeros(ns(A), ns(C), 5);
+  CPT(1,1,1)=1;  % Theo state 4
+  CPT(1,2,2)=1;  % Theo state 5
+  CPT(1,3,3)=1; % Theo state 6
+  CPT(2,1,4)=1; % Theo state 9
+  CPT(2,2,5)=1; % Theo state 10
+  %CPT(2,3,:) undefined
+  O = onodes(1);
+  bnet.CPD{eclass(O,1)} = tabular_CPD(bnet, O, 'CPT', CPT);
+else
+  % north/east/south/west can see wall (1) or opening (2)
+  CPT = zeros(ns(A), ns(C), 2);
+  CPT(:,:,1) = q;
+  CPT(:,:,2) = p;
+  bnet.CPD{eclass(W,1)} = tabular_CPD(bnet, W, 'CPT', CPT);
+  bnet.CPD{eclass(E,1)} = tabular_CPD(bnet, E, 'CPT', CPT);
+  CPT = zeros(ns(A), ns(C), 2);
+  CPT(:,:,1) = p;
+  CPT(:,:,2) = q;
+  bnet.CPD{eclass(S,1)} = tabular_CPD(bnet, S, 'CPT', CPT);
+  bnet.CPD{eclass(N,1)} = tabular_CPD(bnet, N, 'CPT', CPT);
+end
+
+% Define the CPDs for slice 2
+
+% Abstract
+
+% Since the top level never resets, the starting distribution is irrelevant:
+% A2 will be determined by sampling from transmat(A1,:).
+% But the code requires we specify it anyway; we make it all 0s, a dummy value.
+startprob = zeros(ns(U), ns(A));
+
+transmat = zeros(ns(U), ns(A), ns(A));
+transmat(R,1,:) = [q p];
+transmat(R,2,:) = [0 1];
+transmat(L,1,:) = [1 0];
+transmat(L,2,:) = [p q];
+
+% Qps are the parents we condition the parameters on, in this case just
+% the past action.
+bnet.CPD{eclass(A,2)} = hhmm2Q_CPD(bnet, A+ss, 'Fbelow', F, ...
+				  'startprob', startprob, 'transprob', transmat);
+
+
+
+% Concrete
+
+transmat = zeros(ns(C), ns(U), ns(A), ns(C));
+transmat(1,r,1,:) = [q p 0.0];
+transmat(2,r,1,:) = [0.0 q p];
+transmat(3,r,1,:) = [0.0 0.0 1.0];
+transmat(1,r,2,:) = [q p 0.0];
+transmat(2,r,2,:) = [0.0 1.0 0.0];
+%
+transmat(1,l,1,:) = [1.0 0.0 0.0];
+transmat(2,l,1,:) = [p q 0.0];
+transmat(3,l,1,:) = [0.0 p q];
+transmat(1,l,2,:) = [1.0 0.0 0.0];
+transmat(2,l,2,:) = [p q 0.0];
+
+% Add a new dimension for A(t-1), by copying old vals,
+% so the matrix is the same size as startprob
+
+
+transmat = reshape(transmat, [ns(C) ns(U) ns(A) 1 ns(C)]);
+transmat = repmat(transmat, [1 1 1 ns(A) 1]);
+
+% startprob(C(t-1), U(t-1), A(t-1), A(t), C(t))
+startprob = zeros(ns(C), ns(U), ns(A), ns(A), ns(C));
+startprob(1,L,1,1,:) = [1.0 0.0 0.0];
+startprob(3,R,1,2,:) = [1.0 0.0 0.0];
+startprob(3,R,1,1,:) = [0.0 0.0 1.0];
+% 
+startprob(1,L,2,1,:) = [0.0 0.0 010];
+startprob(2,L,2,1,:) = [1.0 0.0 0.0];
+startprob(2,R,2,2,:) = [0.0 1.0 0.0];
+
+% want transmat(U,A,C,At,Ct), ie. in topo order
+transmat = permute(transmat, [2 3 1 4 5]);
+startprob  = permute(startprob, [2 3 1 4 5]);
+bnet.CPD{eclass(C,2)} = hhmm2Q_CPD(bnet, C+ss, 'Fself', F, ...
+				  'startprob', startprob, 'transprob', transmat);
+
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/mk_rnd_map_hhmm.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/mk_rnd_map_hhmm.m
new file mode 100644
index 00000000..76b06fc7
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/mk_rnd_map_hhmm.m
@@ -0,0 +1,73 @@
+function bnet = mk_rnd_map_hhmm(varargin)
+
+% We copy the deterministic structure of the real HHMM,
+% but randomize the probabilities of the adjustable CPDs.
+% The key trick is that 0s in the real HHMM remain 0
+% even when multiplied by a randon number.
+
+obs_model = 'unique';
+
+for i=1:2:length(varargin)
+  switch varargin{i},
+   case 'obs_model', obs_model = varargin{i+1};
+  end
+end
+
+
+unique_obs = strcmp(obs_model, 'unique');
+
+psuccess = 0.9;
+% must be less than 1, so that pfail > 0
+% otherwise we copy too many 0s
+bnet = mk_map_hhmm('p', psuccess, 'obs_model', obs_model);
+ns = bnet.node_sizes;
+ss = bnet.nnodes_per_slice;
+
+U = 1; A = 2; C = 3; F = 4;
+%unique_obs = (bnet.nnodes_per_slice == 5);
+if unique_obs
+  onodes = 5;
+else
+  north = 5; east = 6; south = 7; west = 8;
+  onodes = [north east south west];
+end
+
+eclass = bnet.equiv_class;
+S=struct(bnet.CPD{eclass(F,1)});
+CPT = mk_stochastic(rand(size(S.CPT)) .* S.CPT);
+bnet.CPD{eclass(F,1)} = tabular_CPD(bnet, F, 'CPT', CPT);
+
+
+% Observation model
+if unique_obs
+  CPT = zeros(ns(A), ns(C), 5);
+  CPT(1,1,1)=1;  % Theo state 4
+  CPT(1,2,2)=1;  % Theo state 5
+  CPT(1,3,3)=1; % Theo state 6
+  CPT(2,1,4)=1; % Theo state 9
+  CPT(2,2,5)=1; % Theo state 10
+  %CPT(2,3,:) undefined
+  O = onodes(1);
+  bnet.CPD{eclass(O,1)} = tabular_CPD(bnet, O, 'CPT', CPT);
+else
+  for i=[north east south west]
+    CPT = mk_stochastic(rand(ns(A), ns(C), 2));
+    bnet.CPD{eclass(i,1)} = tabular_CPD(bnet, i, 'CPT', CPT);
+  end
+end
+
+% Define the CPDs for slice 2
+
+startprob = zeros(ns(U), ns(A));
+S = struct(bnet.CPD{eclass(A,2)});
+transprob = mk_stochastic(rand(size(S.transprob)) .* S.transprob);
+bnet.CPD{eclass(A,2)} = hhmm2Q_CPD(bnet, A+ss, 'Fbelow', F, ...
+				  'startprob', startprob, 'transprob', transprob);
+
+S = struct(bnet.CPD{eclass(C,2)});
+transprob = mk_stochastic(rand(size(S.transprob)) .* S.transprob);
+startprob = mk_stochastic(rand(size(S.startprob)) .* S.startprob);
+bnet.CPD{eclass(C,2)} = hhmm2Q_CPD(bnet, C+ss, 'Fself', F, ...
+				  'startprob', startprob, 'transprob', transprob);
+
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/sample_from_map.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/sample_from_map.m
new file mode 100644
index 00000000..816b741e
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/sample_from_map.m
@@ -0,0 +1,41 @@
+if 0
+% Generate some sample paths
+
+bnet = mk_map_hhmm('p', 1);
+% assign numbers to the nodes in topological order
+U = 1; A = 2; C = 3; F = 4; O = 5;
+
+
+seed = 0;
+rand('state', seed);
+randn('state', seed);
+
+% control policy = sweep right then left
+T = 10;
+ss = 5;
+ev = cell(ss, T);
+ev(U,:) = num2cell([R*ones(1,5) L*ones(1,5)]);
+
+% fix initial conditions to be in left most state
+ev{A,1} = 1; 
+ev{C,1} = 1; 
+evidence = sample_dbn(bnet, 'length', T, 'evidence', ev)
+
+
+% Now do same but with noisy actuators
+
+bnet = mk_map_hhmm('p', 0.8);
+evidence = sample_dbn(bnet, 'length', T, 'evidence', ev)
+
+end
+
+% Now do same but with 4 observations per slice
+
+bnet = mk_map_hhmm('p', 0.8, 'obs_model', 'four');
+ss = bnet.nnodes_per_slice;
+
+ev = cell(ss, T);
+ev(U,:) = num2cell([R*ones(1,5) L*ones(1,5)]);
+ev{A,1} = 1; 
+ev{C,1} = 1; 
+evidence = sample_dbn(bnet, 'length', T, 'evidence', ev)
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/CVS/Entries b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/CVS/Entries
new file mode 100644
index 00000000..c4379581
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/CVS/Entries
@@ -0,0 +1,6 @@
+/letter2num.m/1.1.1.1/Fri Nov 22 23:10:20 2002//
+/mgram1.m/1.1.1.1/Fri Nov 22 23:59:00 2002//
+/mgram2.m/1.1.1.1/Tue Nov 26 22:04:24 2002//
+/mgram3.m/1.1.1.1/Tue Nov 26 22:14:10 2002//
+/num2letter.m/1.1.1.1/Fri Nov 22 23:07:40 2002//
+D/Old////
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/CVS/Repository b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/CVS/Repository
new file mode 100644
index 00000000..5ede715e
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/examples/dynamic/HHMM/Mgram
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/CVS/Root b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/Old/CVS/Entries b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/Old/CVS/Entries
new file mode 100644
index 00000000..07b688e2
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/Old/CVS/Entries
@@ -0,0 +1,2 @@
+/mgram2.m/1.1.1.1/Sat Nov 23 00:44:34 2002//
+D
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/Old/CVS/Repository b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/Old/CVS/Repository
new file mode 100644
index 00000000..ba3ae6df
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/Old/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/examples/dynamic/HHMM/Mgram/Old
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/Old/CVS/Root b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/Old/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/Old/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/Old/mgram2.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/Old/mgram2.m
new file mode 100644
index 00000000..719a3167
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/Old/mgram2.m
@@ -0,0 +1,191 @@
+% like mgram1, except we use a durational HMM instead of an HHMM2
+
+past = 0;
+
+words = {'the', 't', 'h', 'e'};
+data = 'the';
+nwords = length(words);
+word_len = zeros(1, nwords);
+word_prob = normalise(ones(1,nwords));
+word_logprob = log(word_prob);
+for wi=1:nwords
+  word_len(wi)=length(words{wi});
+end
+D = max(word_len);
+
+
+alphasize = 26*2;
+data = letter2num(data);
+T = length(data);
+
+% node numbers
+W = 1; % top level state = word id
+L = 2; % bottom level state = letter position within word
+F = 3;
+O = 4;
+
+ss = 4;
+intra = zeros(ss,ss);
+intra(W,[F L O])=1;
+intra(L,[O F])=1;
+
+inter = zeros(ss,ss);
+inter(W,W)=1;
+inter(L,L)=1;
+inter(F,[W L O])=1;
+
+% node sizes
+ns = zeros(1,ss);
+ns(W) = nwords;
+ns(L) = D;
+ns(F) = 2;
+ns(O) = alphasize;
+ns2 = [ns ns];
+
+% Make the DBN
+bnet = mk_dbn(intra, inter, ns, 'observed', O);
+eclass = bnet.equiv_class;
+
+% uniform start distrib over words, uniform trans mat
+Wstart = normalise(ones(1,nwords));
+Wtrans = mk_stochastic(ones(nwords,nwords));
+
+% always start in state d = length(word) for each bottom level HMM
+Lstart = zeros(nwords, D);
+for i=1:nwords
+  l = length(words{i});
+  Lstart(i,l)=1;
+end
+
+% make downcounters
+RLtrans = mk_rightleft_transmat(D, 0); % 0 self loop prob
+Ltrans = repmat(RLtrans, [1 1 nwords]);
+
+% Finish when downcoutner = 1
+Fprob = zeros(nwords, D, 2);
+Fprob(:,1,2)=1;
+Fprob(:,2:end,1)=1;
+
+
+% Define CPDs for slice 
+bnet.CPD{eclass(W,1)} = tabular_CPD(bnet, W, 'CPT', Wstart);
+bnet.CPD{eclass(L,1)} = tabular_CPD(bnet, L, 'CPT', Lstart);
+bnet.CPD{eclass(F,1)} = tabular_CPD(bnet, F, 'CPT', Fprob);
+
+
+% Define CPDs for slice 2
+bnet.CPD{eclass(W,2)} = hhmmQ_CPD(bnet, W+ss, 'Fbelow', F, 'startprob', Wstart,  'transprob', Wtrans);
+bnet.CPD{eclass(L,2)} = hhmmQ_CPD(bnet, L+ss, 'Fself', F, 'Qps', W+ss, 'startprob', Lstart, 'transprob', Ltrans);
+
+
+if 0
+% To test it is generating correctly, we create an artificial
+% observation process that capitalizes at the start of a new segment
+% Oprob(Ft-1,Qt,Dt,Yt)
+Oprob = zeros(2,nwords,D,alphasize);
+Oprob(1,1,3,letter2num('t'),1)=1;
+Oprob(1,1,2,letter2num('h'),1)=1;
+Oprob(1,1,1,letter2num('e'),1)=1;
+Oprob(2,1,3,letter2num('T'),1)=1;
+Oprob(2,1,2,letter2num('H'),1)=1;
+Oprob(2,1,1,letter2num('E'),1)=1;
+Oprob(1,2,1,letter2num('a'),1)=1;
+Oprob(2,2,1,letter2num('A'),1)=1;
+Oprob(1,3,1,letter2num('b'),1)=1;
+Oprob(2,3,1,letter2num('B'),1)=1;
+Oprob(1,4,1,letter2num('c'),1)=1;
+Oprob(2,4,1,letter2num('C'),1)=1;
+
+% Oprob1(Qt,Dt,Yt)
+Oprob1 = zeros(nwords,D,alphasize);
+Oprob1(1,3,letter2num('t'),1)=1;
+Oprob1(1,2,letter2num('h'),1)=1;
+Oprob1(1,1,letter2num('e'),1)=1;
+Oprob1(2,1,letter2num('a'),1)=1;
+Oprob1(3,1,letter2num('b'),1)=1;
+Oprob1(4,1,letter2num('c'),1)=1;
+
+bnet.CPD{eclass(O,2)} = tabular_CPD(bnet, O+ss, 'CPT', Oprob);
+bnet.CPD{eclass(O,1)} = tabular_CPD(bnet, O, 'CPT', Oprob1);
+
+evidence = cell(ss,T);
+%evidence{W,1}=1;
+sample = cell2num(sample_dbn(bnet, 'length', T, 'evidence', evidence));
+str = num2letter(sample(4,:))
+end
+
+
+
+
+[log_obslik, obslik, match] = mk_mgram_obslik(lower(data), words, word_len, word_prob);
+% obslik(j,t,d)
+softCPDpot = cell(ss,T);
+ens = ns;
+ens(O)=1;
+ens2 = [ens ens];
+for t=2:T
+  dom = [F W+ss L+ss O+ss];
+  % tab(Ft-1, Q2, Dt)
+  tab = ones(2, nwords, D);
+  if past
+    tab(1,:,:)=1; % if haven't finished previous word, likelihood is 1
+    tab(2,:,:) = squeeze(obslik(:,t,:)); % otherwise likelihood of this segment
+  else
+    for d=1:max(1,min(D,T+1-t))
+      tab(2,:,d) = squeeze(obslik(:,t+d-1,d));
+    end
+  end
+  softCPDpot{O,t} = dpot(dom, ens2(dom), tab);
+end
+t = 1;
+dom = [W L O];
+% tab(Q2, Dt)
+tab = ones(nwords, D);
+if past
+  tab = squeeze(obslik(:,t,:));
+else
+  for d=1:min(D,T-t)
+    tab(:,d) = squeeze(obslik(:,t+d-1,d));
+  end
+end
+softCPDpot{O,t} = dpot(dom, ens(dom), tab);
+
+
+%bnet.observed = [];
+% uniformative observations
+%bnet.CPD{eclass(O,2)} = tabular_CPD(bnet, O+ss, 'CPT', mk_stochastic(ones(2,nwords,D,alphasize)));
+%bnet.CPD{eclass(O,1)} = tabular_CPD(bnet, O, 'CPT', mk_stochastic(ones(nwords,D,alphasize)));
+
+engine = jtree_dbn_inf_engine(bnet);
+evidence = cell(ss,T);
+% we add dummy data to O to force its effective size to be 1.
+% The actual values have already been incorporated into softCPDpot 
+evidence(O,:) = num2cell(ones(1,T));
+[engine, ll_dbn] = enter_evidence(engine, evidence, 'softCPDpot', softCPDpot);
+
+
+%evidence(F,:) = num2cell(2*ones(1,T));
+%[engine, ll_dbn] = enter_evidence(engine, evidence);
+
+
+gamma = zeros(nwords, T);
+for t=1:T
+  m = marginal_nodes(engine, [W F], t);
+  gamma(:,t) = m.T(:,2);
+end
+
+gamma
+
+xidbn = zeros(nwords, nwords);
+for t=1:T-1
+  m = marginal_nodes(engine, [W F W+ss], t);
+  xidbn = xidbn + squeeze(m.T(:,2,:));
+end
+
+% thee
+% xidbn(1,4)  = 0.9412  the->e
+% (2,3)=0.0588 t->h
+% (3,4)=0.0588 h-e
+% (4,4)=0.0588 e-e
+
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/letter2num.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/letter2num.m
new file mode 100644
index 00000000..f4e3f1d9
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/letter2num.m
@@ -0,0 +1,12 @@
+function n = letter2num(l)
+
+% map a-z to 1:26 and A-Z to 27:52
+punct_code = [32:47 58:64 91:96 123:126];
+digits_code = 48:57;
+upper_code = 65:90;
+lower_code = 97:122;
+
+c = double(l);
+n = c-96;
+ndx = find(n <= 0); % upper case
+n(ndx) = c(ndx)  - 64 + 26;
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/mgram1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/mgram1.m
new file mode 100644
index 00000000..52ca472e
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/mgram1.m
@@ -0,0 +1,116 @@
+% a multigram is a degenerate 2HHMM where the bottom level HMMs emit deterministic strings
+% and the the top level abstract states are independent of each other
+% cf. HSMM/test_mgram2 
+
+words = {'the', 't', 'h', 'e'};
+data = 'the';
+nwords = length(words);
+word_len = zeros(1, nwords);
+word_prob = normalise(ones(1,nwords));
+word_logprob = log(word_prob);
+for wi=1:nwords
+  word_len(wi)=length(words{wi});
+end
+D = max(word_len);
+
+alphasize = 26;
+data = letter2num(data);
+T = length(data);
+
+% node numbers
+W = 1; % top level state = word id
+L = 2; % bottom level state = letter position within word
+F = 3;
+O = 4;
+
+ss = 4;
+intra = zeros(ss,ss);
+intra(W,[F L O])=1;
+intra(L,[O F])=1;
+
+inter = zeros(ss,ss);
+inter(W,W)=1;
+inter(L,L)=1;
+inter(F,[W L])=1;
+
+% node sizes
+ns = zeros(1,ss);
+ns(W) = nwords;
+ns(L) = D;
+ns(F) = 2;
+ns(O) = alphasize;
+
+
+% Make the DBN
+bnet = mk_dbn(intra, inter, ns, 'observed', O);
+eclass = bnet.equiv_class;
+
+
+
+% uniform start distrib over words, uniform trans mat
+Wstart = normalise(ones(1,nwords));
+Wtrans = mk_stochastic(ones(nwords,nwords));
+
+% always start in state 1 for each bottom level HMM
+delta1_start = zeros(1, D);
+delta1_start(1) = 1;
+Lstart = repmat(delta1_start, nwords, 1);
+LRtrans = mk_leftright_transmat(D, 0); % 0 self loop prob
+Ltrans = repmat(LRtrans, [1 1 nwords]);
+
+% Finish in the last letter of each word
+Fprob = zeros(nwords, D, 2);
+Fprob(:,:,1)=1;
+for i=1:nwords
+  Fprob(i,length(words{i}),2)=1;
+  Fprob(i,length(words{i}),1)=0;
+end
+
+% Each state uniquely emits a letter
+Oprob = zeros(nwords, D, alphasize);
+for i=1:nwords
+  for l=1:length(words{i})
+    a = double(words{i}(l))-96;
+    Oprob(i,l,a)=1;
+  end
+end
+
+
+% Define CPDs for slice 
+bnet.CPD{eclass(W,1)} = tabular_CPD(bnet, W, 'CPT', Wstart);
+bnet.CPD{eclass(L,1)} = tabular_CPD(bnet, L, 'CPT', Lstart);
+bnet.CPD{eclass(F,1)} = tabular_CPD(bnet, F, 'CPT', Fprob);
+bnet.CPD{eclass(O,1)} = tabular_CPD(bnet, O, 'CPT', Oprob);
+
+% Define CPDs for slice 2
+bnet.CPD{eclass(W,2)} = hhmmQ_CPD(bnet, W+ss, 'Fbelow', F, 'startprob', Wstart,  'transprob', Wtrans);
+bnet.CPD{eclass(L,2)} = hhmmQ_CPD(bnet, L+ss, 'Fself', F, 'Qps', W+ss, 'startprob', Lstart, 'transprob', Ltrans);
+
+evidence = cell(ss,T);
+evidence{W,1}=1;
+sample = cell2num(sample_dbn(bnet, 'length', T, 'evidence', evidence));
+str = lower(sample(4,:))
+
+engine = jtree_dbn_inf_engine(bnet);
+evidence = cell(ss,T);
+evidence(O,:) = num2cell(data);
+[engine, ll_dbn] = enter_evidence(engine, evidence);
+
+gamma = zeros(nwords, T);
+for t=1:T
+  m = marginal_nodes(engine, [W F], t);
+  gamma(:,t) = m.T(:,2);
+end
+gamma
+
+xidbn = zeros(nwords, nwords);
+for t=1:T-1
+  m = marginal_nodes(engine, [W F W+ss], t);
+  xidbn = xidbn + squeeze(m.T(:,2,:));
+end
+
+% thee
+% xidbn(1,4)  = 0.9412  the->e
+% (2,3)=0.0588 t->h
+% (3,4)=0.0588 h-e
+% (4,4)=0.0588 e-e
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/mgram2.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/mgram2.m
new file mode 100644
index 00000000..c61f855a
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/mgram2.m
@@ -0,0 +1,200 @@
+% Like a durational HMM, except we use soft evidence on the observed nodes.
+% Should give the same results as HSMM/test_mgram2.
+
+past = 1;
+% If past=1, P(Yt|Qt=j,Dt=d) = P(y_{t-d+1:t}|j)
+% If past=0, P(Yt|Qt=j,Dt=d) = P(y_{t:t+d-1}|j) - future evidence
+
+words = {'the', 't', 'h', 'e'};
+data = 'the';
+nwords = length(words);
+word_len = zeros(1, nwords);
+word_prob = normalise(ones(1,nwords));
+word_logprob = log(word_prob);
+for wi=1:nwords
+  word_len(wi)=length(words{wi});
+end
+D = max(word_len);
+
+
+alphasize = 26*2;
+data = letter2num(data);
+T = length(data);
+
+% node numbers
+W = 1; % top level state = word id
+L = 2; % bottom level state = letter position within word
+F = 3;
+O = 4;
+
+ss = 4;
+intra = zeros(ss,ss);
+intra(W,[F L O])=1;
+intra(L,[O F])=1;
+
+inter = zeros(ss,ss);
+inter(W,W)=1;
+inter(L,L)=1;
+inter(F,[W L O])=1;
+
+% node sizes
+ns = zeros(1,ss);
+ns(W) = nwords;
+ns(L) = D;
+ns(F) = 2;
+ns(O) = alphasize;
+ns2 = [ns ns];
+
+% Make the DBN
+bnet = mk_dbn(intra, inter, ns, 'observed', O);
+eclass = bnet.equiv_class;
+
+% uniform start distrib over words, uniform trans mat
+Wstart = normalise(ones(1,nwords));
+Wtrans = mk_stochastic(ones(nwords,nwords));
+%Wtrans = ones(nwords,nwords);
+
+% always start in state d = length(word) for each bottom level HMM
+Lstart = zeros(nwords, D);
+for i=1:nwords
+  l = length(words{i});
+  Lstart(i,l)=1;
+end
+
+% make downcounters
+RLtrans = mk_rightleft_transmat(D, 0); % 0 self loop prob
+Ltrans = repmat(RLtrans, [1 1 nwords]);
+
+% Finish when downcoutner = 1
+Fprob = zeros(nwords, D, 2);
+Fprob(:,1,2)=1;
+Fprob(:,2:end,1)=1;
+
+
+% Define CPDs for slice 1
+bnet.CPD{eclass(W,1)} = tabular_CPD(bnet, W, 'CPT', Wstart);
+bnet.CPD{eclass(L,1)} = tabular_CPD(bnet, L, 'CPT', Lstart);
+bnet.CPD{eclass(F,1)} = tabular_CPD(bnet, F, 'CPT', Fprob);
+
+
+% Define CPDs for slice 2
+bnet.CPD{eclass(W,2)} = hhmmQ_CPD(bnet, W+ss, 'Fbelow', F, 'startprob', Wstart,  'transprob', Wtrans);
+bnet.CPD{eclass(L,2)} = hhmmQ_CPD(bnet, L+ss, 'Fself', F, 'Qps', W+ss, 'startprob', Lstart, 'transprob', Ltrans);
+
+
+if 0
+% To test it is generating correctly, we create an artificial
+% observation process that capitalizes at the start of a new segment
+% Oprob(Ft-1,Qt,Dt,Yt)
+Oprob = zeros(2,nwords,D,alphasize);
+Oprob(1,1,3,letter2num('t'),1)=1;
+Oprob(1,1,2,letter2num('h'),1)=1;
+Oprob(1,1,1,letter2num('e'),1)=1;
+Oprob(2,1,3,letter2num('T'),1)=1;
+Oprob(2,1,2,letter2num('H'),1)=1;
+Oprob(2,1,1,letter2num('E'),1)=1;
+Oprob(1,2,1,letter2num('a'),1)=1;
+Oprob(2,2,1,letter2num('A'),1)=1;
+Oprob(1,3,1,letter2num('b'),1)=1;
+Oprob(2,3,1,letter2num('B'),1)=1;
+Oprob(1,4,1,letter2num('c'),1)=1;
+Oprob(2,4,1,letter2num('C'),1)=1;
+
+% Oprob1(Qt,Dt,Yt)
+Oprob1 = zeros(nwords,D,alphasize);
+Oprob1(1,3,letter2num('t'),1)=1;
+Oprob1(1,2,letter2num('h'),1)=1;
+Oprob1(1,1,letter2num('e'),1)=1;
+Oprob1(2,1,letter2num('a'),1)=1;
+Oprob1(3,1,letter2num('b'),1)=1;
+Oprob1(4,1,letter2num('c'),1)=1;
+
+bnet.CPD{eclass(O,2)} = tabular_CPD(bnet, O+ss, 'CPT', Oprob);
+bnet.CPD{eclass(O,1)} = tabular_CPD(bnet, O, 'CPT', Oprob1);
+
+evidence = cell(ss,T);
+%evidence{W,1}=1;
+sample = cell2num(sample_dbn(bnet, 'length', T, 'evidence', evidence));
+str = num2letter(sample(4,:))
+end
+
+
+if 1
+
+[log_obslik, obslik, match] = mk_mgram_obslik(lower(data), words, word_len, word_prob);
+% obslik(j,t,d)
+softCPDpot = cell(ss,T);
+ens = ns;
+ens(O)=1;
+ens2 = [ens ens];
+for t=2:T
+  dom = [F W+ss L+ss O+ss];
+  % tab(Ft-1, Q2, Dt)
+  tab = ones(2, nwords, D);
+  if past
+    tab(1,:,:)=1; % if haven't finished previous word, likelihood is 1
+    %tab(2,:,:) = squeeze(obslik(:,t,:)); % otherwise likelihood of this segment
+    for d=1:min(t,D)
+      tab(2,:,d) = squeeze(obslik(:,t,d));
+    end
+  else
+    for d=1:max(1,min(D,T+1-t))
+      tab(2,:,d) = squeeze(obslik(:,t+d-1,d));
+    end
+  end
+  softCPDpot{O,t} = dpot(dom, ens2(dom), tab);
+end
+t = 1;
+dom = [W L O];
+% tab(Q2, Dt)
+tab = ones(nwords, D);
+if past
+  %tab = squeeze(obslik(:,t,:));
+  tab(:,1) = squeeze(obslik(:,t,1));
+else
+  for d=1:min(D,T-t)
+    tab(:,d) = squeeze(obslik(:,t+d-1,d));
+  end
+end
+softCPDpot{O,t} = dpot(dom, ens(dom), tab);
+
+
+%bnet.observed = [];
+% uniformative observations
+%bnet.CPD{eclass(O,2)} = tabular_CPD(bnet, O+ss, 'CPT', mk_stochastic(ones(2,nwords,D,alphasize)));
+%bnet.CPD{eclass(O,1)} = tabular_CPD(bnet, O, 'CPT', mk_stochastic(ones(nwords,D,alphasize)));
+
+engine = jtree_dbn_inf_engine(bnet);
+evidence = cell(ss,T);
+% we add dummy data to O to force its effective size to be 1.
+% The actual values have already been incorporated into softCPDpot 
+evidence(O,:) = num2cell(ones(1,T));
+[engine, ll_dbn] = enter_evidence(engine, evidence, 'softCPDpot', softCPDpot);
+
+
+%evidence(F,:) = num2cell(2*ones(1,T));
+%[engine, ll_dbn] = enter_evidence(engine, evidence);
+
+
+gamma = zeros(nwords, T);
+for t=1:T
+  m = marginal_nodes(engine, [W F], t);
+  gamma(:,t) = m.T(:,2);
+end
+
+gamma
+
+xidbn = zeros(nwords, nwords);
+for t=1:T-1
+  m = marginal_nodes(engine, [W F W+ss], t);
+  xidbn = xidbn + squeeze(m.T(:,2,:));
+end
+
+% thee
+% xidbn(1,4)  = 0.9412  the->e
+% (2,3)=0.0588 t->h
+% (3,4)=0.0588 h-e
+% (4,4)=0.0588 e-e
+
+
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/mgram3.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/mgram3.m
new file mode 100644
index 00000000..49228584
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/mgram3.m
@@ -0,0 +1,235 @@
+% like mgram2, except we unroll the DBN so we can use smaller
+% state spaces for the early duration nodes:
+% the state spaces are D1 in {1}, D2 in {1,2}
+
+past = 1;
+
+words = {'the', 't', 'h', 'e'};
+data = 'the';
+nwords = length(words);
+word_len = zeros(1, nwords);
+word_prob = normalise(ones(1,nwords));
+word_logprob = log(word_prob);
+for wi=1:nwords
+  word_len(wi)=length(words{wi});
+end
+D = max(word_len);
+
+
+alphasize = 26*2;
+data = letter2num(data);
+T = length(data);
+
+% node numbers
+W = 1; % top level state = word id
+L = 2; % bottom level state = letter position within word
+F = 3;
+O = 4;
+
+ss = 4;
+intra = zeros(ss,ss);
+intra(W,[F L O])=1;
+intra(L,[O F])=1;
+
+inter = zeros(ss,ss);
+inter(W,W)=1;
+inter(L,L)=1;
+inter(F,[W L O])=1;
+
+T = 3;
+dag = unroll_dbn_topology(intra, inter, T);
+
+% node sizes
+ns = zeros(1,ss);
+ns(W) = nwords;
+ns(L) = D;
+ns(F) = 2;
+ns(O) = alphasize;
+ns = repmat(ns(:), [1 T]);
+for d=1:D
+  ns(d,L)=d; % max duration
+end
+ns = ns(:);
+
+% Equiv class in brackets for D=3
+% The Lt's are not tied until t>=D, since they have different sizes.
+% W1 and W2 are not tied since they have different parent sets.
+
+% W1 (1)  W2 (5) W3 (5) W4 (5)
+% L1 (2)  L2 (6) L3 (7) L4 (7)
+% F1 (3)  F2 (3) F3 (4) F3 (4)
+% O1 (4)  O2 (4) O2 (4) O4 (4)
+
+% Since we are not learning, we can dispense with tying
+
+% Make the bnet
+Wnodes = unroll_set(W, ss, T);
+Lnodes = unroll_set(L, ss, T);
+Fnodes = unroll_set(F, ss, T);
+Onodes = unroll_set(O, ss, T);
+
+bnet = mk_bnet(dag, ns);
+eclass = bnet.equiv_class;
+
+% uniform start distrib over words, uniform trans mat
+Wstart = normalise(ones(1,nwords));
+Wtrans = mk_stochastic(ones(nwords,nwords));
+bnet.CPD{eclass(Wnodes(1))} = tabular_CPD(bnet, Wnodes(1), 'CPT', Wstart);
+for t=2:T
+bnet.CPD{eclass(Wnodes(t))} = hhmmQ_CPD(bnet, Wnodes(t), 'Fbelow', Fnodes(t-1), ...
+					'startprob', Wstart,  'transprob', Wtrans);
+end
+
+% always start in state d = length(word) for each bottom level HMM
+% and then count down
+% make downcounters
+RLtrans = mk_rightleft_transmat(D, 0); % 0 self loop prob
+Ltrans = repmat(RLtrans, [1 1 nwords]);
+
+for t=1:T
+  Lstart = zeros(nwords, min(t,D));
+  for i=1:nwords
+    l = length(words{i});
+    Lstart(i,l)=1;
+    if d==1
+      bnet.CPD{eclass(Lnodes(1))} = tabular_CPD(bnet, Lnodes(1), 'CPT', Lstart);
+    else
+      bnet.CPD{eclass(Lnodes(t))} = hhmmQ_CPD(bnet, Lnodes(t), 'Fself', Fnodes(t-1), 'Qps', Wnodes(t), ...
+					      'startprob', Lstart, 'transprob', Ltrans);
+    end
+  end
+end
+
+
+% Finish when downcoutner = 1
+Fprob = zeros(nwords, D, 2);
+Fprob(:,1,2)=1;
+Fprob(:,2:end,1)=1;
+
+
+% Define CPDs for slice 
+bnet.CPD{eclass(W,1)} = tabular_CPD(bnet, W, 'CPT', Wstart);
+bnet.CPD{eclass(L,1)} = tabular_CPD(bnet, L, 'CPT', Lstart);
+bnet.CPD{eclass(F,1)} = tabular_CPD(bnet, F, 'CPT', Fprob);
+
+
+% Define CPDs for slice 2
+bnet.CPD{eclass(W,2)} = hhmmQ_CPD(bnet, W+ss, 'Fbelow', F, 'startprob', Wstart,  'transprob', Wtrans);
+bnet.CPD{eclass(L,2)} = hhmmQ_CPD(bnet, L+ss, 'Fself', F, 'Qps', W+ss, 'startprob', Lstart, 'transprob', Ltrans);
+
+
+if 0
+% To test it is generating correctly, we create an artificial
+% observation process that capitalizes at the start of a new segment
+% Oprob(Ft-1,Qt,Dt,Yt)
+Oprob = zeros(2,nwords,D,alphasize);
+Oprob(1,1,3,letter2num('t'),1)=1;
+Oprob(1,1,2,letter2num('h'),1)=1;
+Oprob(1,1,1,letter2num('e'),1)=1;
+Oprob(2,1,3,letter2num('T'),1)=1;
+Oprob(2,1,2,letter2num('H'),1)=1;
+Oprob(2,1,1,letter2num('E'),1)=1;
+Oprob(1,2,1,letter2num('a'),1)=1;
+Oprob(2,2,1,letter2num('A'),1)=1;
+Oprob(1,3,1,letter2num('b'),1)=1;
+Oprob(2,3,1,letter2num('B'),1)=1;
+Oprob(1,4,1,letter2num('c'),1)=1;
+Oprob(2,4,1,letter2num('C'),1)=1;
+
+% Oprob1(Qt,Dt,Yt)
+Oprob1 = zeros(nwords,D,alphasize);
+Oprob1(1,3,letter2num('t'),1)=1;
+Oprob1(1,2,letter2num('h'),1)=1;
+Oprob1(1,1,letter2num('e'),1)=1;
+Oprob1(2,1,letter2num('a'),1)=1;
+Oprob1(3,1,letter2num('b'),1)=1;
+Oprob1(4,1,letter2num('c'),1)=1;
+
+bnet.CPD{eclass(O,2)} = tabular_CPD(bnet, O+ss, 'CPT', Oprob);
+bnet.CPD{eclass(O,1)} = tabular_CPD(bnet, O, 'CPT', Oprob1);
+
+evidence = cell(ss,T);
+%evidence{W,1}=1;
+sample = cell2num(sample_dbn(bnet, 'length', T, 'evidence', evidence));
+str = num2letter(sample(4,:))
+end
+
+
+
+
+[log_obslik, obslik, match] = mk_mgram_obslik(lower(data), words, word_len, word_prob);
+% obslik(j,t,d)
+softCPDpot = cell(ss,T);
+ens = ns;
+ens(O)=1;
+ens2 = [ens ens];
+for t=2:T
+  dom = [F W+ss L+ss O+ss];
+  % tab(Ft-1, Q2, Dt)
+  tab = ones(2, nwords, D);
+  if past
+    tab(1,:,:)=1; % if haven't finished previous word, likelihood is 1
+    %tab(2,:,:) = squeeze(obslik(:,t,:)); % otherwise likelihood of this segment
+    for d=1:min(t,D)
+      tab(2,:,d) = squeeze(obslik(:,t,d));
+    end
+  else
+    for d=1:max(1,min(D,T+1-t))
+      tab(2,:,d) = squeeze(obslik(:,t+d-1,d));
+    end
+  end
+  softCPDpot{O,t} = dpot(dom, ens2(dom), tab);
+end
+t = 1;
+dom = [W L O];
+% tab(Q2, Dt)
+tab = ones(nwords, D);
+if past
+  %tab = squeeze(obslik(:,t,:));
+  tab(:,1) = squeeze(obslik(:,t,1));
+else
+  for d=1:min(D,T-t)
+    tab(:,d) = squeeze(obslik(:,t+d-1,d));
+  end
+end
+softCPDpot{O,t} = dpot(dom, ens(dom), tab);
+
+
+%bnet.observed = [];
+% uniformative observations
+%bnet.CPD{eclass(O,2)} = tabular_CPD(bnet, O+ss, 'CPT', mk_stochastic(ones(2,nwords,D,alphasize)));
+%bnet.CPD{eclass(O,1)} = tabular_CPD(bnet, O, 'CPT', mk_stochastic(ones(nwords,D,alphasize)));
+
+engine = jtree_dbn_inf_engine(bnet);
+evidence = cell(ss,T);
+% we add dummy data to O to force its effective size to be 1.
+% The actual values have already been incorporated into softCPDpot 
+evidence(O,:) = num2cell(ones(1,T));
+[engine, ll_dbn] = enter_evidence(engine, evidence, 'softCPDpot', softCPDpot);
+
+
+%evidence(F,:) = num2cell(2*ones(1,T));
+%[engine, ll_dbn] = enter_evidence(engine, evidence);
+
+
+gamma = zeros(nwords, T);
+for t=1:T
+  m = marginal_nodes(engine, [W F], t);
+  gamma(:,t) = m.T(:,2);
+end
+
+gamma
+
+xidbn = zeros(nwords, nwords);
+for t=1:T-1
+  m = marginal_nodes(engine, [W F W+ss], t);
+  xidbn = xidbn + squeeze(m.T(:,2,:));
+end
+
+% thee
+% xidbn(1,4)  = 0.9412  the->e
+% (2,3)=0.0588 t->h
+% (3,4)=0.0588 h-e
+% (4,4)=0.0588 e-e
+
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/num2letter.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/num2letter.m
new file mode 100644
index 00000000..139b81fa
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Mgram/num2letter.m
@@ -0,0 +1,10 @@
+function l = num2letter(n)
+
+% map 1:26 to a-z and 27:52 to A-Z
+punct_code = [32:47 58:64 91:96 123:126];
+digits_code = 48:57;
+upper_code = 65:90;
+lower_code = 97:122;
+
+letters = [char(lower_code) char(upper_code)];
+l = letters(n);
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/CVS/Entries b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/CVS/Entries
new file mode 100644
index 00000000..93258c2a
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/CVS/Entries
@@ -0,0 +1,5 @@
+/fixed_args_mk_motif_hhmm.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/learn_motif_hhmm.m/1.1.1.1/Tue Jul  2 22:56:14 2002//
+/mk_motif_hhmm.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/sample_motif_hhmm.m/1.1.1.1/Wed May 29 15:59:54 2002//
+D
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/CVS/Repository b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/CVS/Repository
new file mode 100644
index 00000000..5062cfd4
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/examples/dynamic/HHMM/Motif
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/CVS/Root b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/fixed_args_mk_motif_hhmm.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/fixed_args_mk_motif_hhmm.m
new file mode 100644
index 00000000..ce4e288b
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/fixed_args_mk_motif_hhmm.m
@@ -0,0 +1,99 @@
+function bnet = fixed_args_mk_motif_hhmm(motif_length, motif_pattern, background_char)
+%
+% BNET = MK_MOTIF_HHMM(MOTIF_LENGTH)
+% Make the following HHMM
+%
+%    S2 <----------------------> S1
+%    |                           |
+%    |                           |
+%   M1 -> M2 -> M3 -> end        B1 -> end
+%
+% where Mi represents the i'th letter in the motif
+% and B is the background state.
+% Si chooses between running the motif or the background.
+% The Si and B states have self loops (not shown).
+%
+% The transition params are defined to respect the above topology.
+% The background is uniform; each motif state has a random obs. distribution.
+%
+% BNET = MK_MOTIF_HHMM(MOTIF_LENGTH, MOTIF_PATTERN)
+% In this case, we make the motif submodel deterministically
+% emit the motif pattern. 
+%
+% BNET = MK_MOTIF_HHMM(MOTIF_LENGTH, MOTIF_PATTERN, BACKGROUND_CHAR)
+% In this case, we make the background submodel
+% deterministically emit the specified character (to make the pattern
+% easier to see).
+
+if nargin < 2, motif_pattern = []; end
+if nargin < 3, background_char = []; end
+
+chars = ['a', 'c', 'g', 't'];
+Osize = length(chars);
+
+motif_length = length(motif_pattern);
+Qsize = [2 motif_length];
+Qnodes = 1:2;
+D = 2;
+transprob = cell(1,D);
+termprob = cell(1,D);
+startprob = cell(1,D);
+
+% startprob{d}(k,j), startprob{1}(1,j)
+% transprob{d}(i,k,j), transprob{1}(i,j)
+% termprob{d}(k,j)
+
+
+% LEVEL 1
+
+startprob{1} = zeros(1, 2);
+startprob{1} = [1 0]; % always start in the background model
+
+% When in the background state, we stay there with high prob
+% When in the motif state, we immediately return to the background state.
+transprob{1} = [0.8 0.2;
+		1.0 0.0];
+
+
+% LEVEL 2
+startprob{2} = 'leftstart'; % both submodels start in substate 1
+transprob{2} = zeros(motif_length, 2, motif_length);
+termprob{2} = zeros(2, motif_length);
+
+% In the background model, we only use state 1.
+transprob{2}(1,1,1) = 1; % self loop
+termprob{2}(1,1) = 0.2; % prob transition to end state
+
+% Motif model
+transprob{2}(:,2,:) = mk_leftright_transmat(motif_length, 0); % no self loops
+termprob{2}(2,end) = 1.0; % last state immediately terminates
+
+
+% OBS LEVEl
+
+obsprob = zeros([Qsize Osize]);
+if isempty(background_char)
+  % uniform background model
+  obsprob(1,1,:) = normalise(ones(Osize,1));
+else
+  % deterministic background model (easy to see!)
+  m = find(chars==background_char);
+  obsprob(1,1,m) = 1.0;
+end
+
+if gen_motif
+  % initialise with true motif (cheating)
+  for i=1:motif_length
+    m = find(chars == motif_pattern(i));
+    obsprob(2,i,m) = 1.0;
+  end
+else
+  obsprob(2,:,:) = mk_stochastic(ones(motif_length, Osize));
+end
+
+Oargs = {'CPT', obsprob};
+
+[bnet, Qnodes, Fnodes, Onode] = mk_hhmm('Qsizes', Qsize, 'Osize', Osize, 'discrete_obs', 1, ...
+	       'Oargs', Oargs, 'Ops', Qnodes(1:2), ...
+	       'startprob', startprob, 'transprob', transprob, 'termprob', termprob);
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/learn_motif_hhmm.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/learn_motif_hhmm.m
new file mode 100644
index 00000000..54553460
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/learn_motif_hhmm.m
@@ -0,0 +1,75 @@
+
+seed = 0;
+rand('state', seed);
+randn('state', seed);
+
+chars = ['a', 'c', 'g', 't'];
+motif = 'accca';
+motif_length = length(motif);
+motif_code = zeros(1, motif_length);
+for i=1:motif_length
+  motif_code(i) = find(chars == motif(i));
+end
+
+[bnet_init, Qnodes, Fnodes, Onode] = mk_motif_hhmm('motif_length', length(motif));
+%[bnet_init, Qnodes, Fnodes, Onode] = mk_motif_hhmm('motif_pattern', motif);
+ss = bnet_init.nnodes_per_slice;
+
+
+
+% We generate a training set by creating uniform sequences,
+% and inserting a single motif at a random location.
+ntrain = 100;
+T = 20;
+cases = cell(1, ntrain);
+
+if 1
+  % uniform background 
+  background_dist = normalise(ones(1, length(chars)));
+end
+if 0
+  % use a constant background
+  background_dist = zeros(1, length(chars));
+  m = find(chars=='t');
+  background_dist(m) = 1.0;
+end
+if 0
+  % use a background skewed away from the motif
+  p = 0.01; q = (1-(2*p))/2;
+  background_dist = [p p q q];
+end
+
+unif_pos = normalise(ones(1, T-length(motif)));
+cases = cell(1, ntrain);
+data = zeros(1,T);
+for i=1:ntrain
+  data = sample_discrete(background_dist, 1, T);
+  L = sample_discrete(unif_pos, 1, 1);
+  data(L:L+length(motif)-1) = motif_code;
+  cases{i} = cell(ss, T);
+  cases{i}(Onode,:) = num2cell(data);
+end
+disp('sample training cases')
+for i=1:5
+  chars(cell2num(cases{i}(Onode,:)))
+end
+
+engine_init = hmm_inf_engine(bnet_init);
+
+[bnet_learned, LL, engine_learned] = ...
+    learn_params_dbn_em(engine_init, cases, 'max_iter', 100, 'thresh', 1e-2);
+%			'anneal', 1, 'anneal_rate', 0.7);
+
+% extract the learned motif profile
+eclass = bnet_learned.equiv_class;
+CPDO=struct(bnet_learned.CPD{eclass(Onode,1)});
+fprintf('columns = chars, rows = states\n');
+profile_learned = squeeze(CPDO.CPT(2,:,:))
+[m,ndx] = max(profile_learned, [], 2);
+map_motif_learned = chars(ndx)
+back_learned = squeeze(CPDO.CPT(1,1,:))'
+%map_back_learned = chars(argmax(back_learned))
+
+CPDO_init = struct(bnet_init.CPD{eclass(Onode,1)});
+profile_init = squeeze(CPDO_init.CPT(2,:,:));
+back_init = squeeze(CPDO_init.CPT(1,1,:))';
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/mk_motif_hhmm.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/mk_motif_hhmm.m
new file mode 100644
index 00000000..32980397
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/mk_motif_hhmm.m
@@ -0,0 +1,137 @@
+function [bnet, Qnodes, Fnodes, Onode] = mk_motif_hhmm(varargin)
+% [bnet, Qnodes, Fnodes, Onode] = mk_motif_hhmm(...)
+%
+% Make the following HHMM
+%
+%    S2 <----------------------> S1
+%    |                           |
+%    |                           |
+%   M1 -> M2 -> M3 -> end        B1 -> end
+%
+% where Mi represents the i'th letter in the motif
+% and B is the background state.
+% Si chooses between running the motif or the background.
+% The Si and B states have self loops (not shown).
+%
+% The transition params are defined to respect the above topology.
+% The background is uniform; each motif state has a random obs. distribution.
+%
+% Optional params:
+% motif_length  - required, unless we specify motif_pattern
+% motif_pattern - if specified, we make the motif submodel deterministically
+%                  emit this pattern
+% background    - if specified, we make the background submodel
+%                  deterministically emit this (makes the motif easier to see!)
+
+
+args = varargin;
+nargs = length(args);
+
+% extract pattern, if any
+motif_pattern = [];
+for i=1:2:nargs
+  switch args{i},
+   case 'motif_pattern', motif_pattern = args{i+1}; 
+  end
+end
+
+% set defaults
+motif_length = length(motif_pattern);
+background_char = [];
+
+% get params
+for i=1:2:nargs
+  switch args{i},
+   case 'motif_length', motif_length = args{i+1}; 
+   case 'background', background_char = args{i+1};
+  end
+end
+
+
+chars = ['a', 'c', 'g', 't'];
+Osize = length(chars);
+
+Qsize = [2 motif_length];
+Qnodes = 1:2;
+D = 2;
+transprob = cell(1,D);
+termprob = cell(1,D);
+startprob = cell(1,D);
+
+% startprob{d}(k,j), startprob{1}(1,j)
+% transprob{d}(i,k,j), transprob{1}(i,j)
+% termprob{d}(k,j)
+
+
+% LEVEL 1
+
+startprob{1} = zeros(1, 2);
+startprob{1} = [1 0]; % always start in the background model
+
+% When in the background state, we stay there with high prob
+% When in the motif state, we immediately return to the background state.
+transprob{1} = [0.8 0.2;
+		1.0 0.0];
+
+
+% LEVEL 2
+startprob{2} = 'leftstart'; % both submodels start in substate 1
+transprob{2} = zeros(motif_length, 2, motif_length);
+termprob{2} = zeros(2, motif_length);
+
+% In the background model, we only use state 1.
+transprob{2}(1,1,1) = 1; % self loop
+termprob{2}(1,1) = 0.2; % prob transition to end state
+
+% Motif model
+transprob{2}(:,2,:) = mk_leftright_transmat(motif_length, 0); % no self loops
+termprob{2}(2,end) = 1.0; % last state immediately terminates
+
+
+% OBS LEVEl
+
+obsprob = zeros([Qsize Osize]);
+if isempty(background_char)
+  % uniform background model
+  %obsprob(1,1,:) = normalise(ones(Osize,1));
+  obsprob(1,1,:) = normalise(rand(Osize,1));
+else
+  % deterministic background model (easy to see!)
+  m = find(chars==background_char);
+  obsprob(1,1,m) = 1.0;
+end
+
+if ~isempty(motif_pattern)
+  % initialise with true motif (cheating)
+  for i=1:motif_length
+    m = find(chars == motif_pattern(i));
+    obsprob(2,i,m) = 1.0;
+  end
+else
+  obsprob(2,:,:) = mk_stochastic(rand(motif_length, Osize));
+end
+
+if 0
+  Oargs = {'CPT', obsprob};
+else
+  % We use a minent prior for the emission distribution for the states in the motif model
+  % (but not the background model). This encourages nearly deterministic distributions.
+  % We create an index matrix  (where M = motif length)
+  %  [2 1
+  %   2 2
+  %   ...
+  %   2 M]
+  % and then convert this to a list of integers, which
+  % specifies when to use the minent prior (Q1=2 specifies motif model).
+  M = motif_length;
+  ndx = [2*ones(M,1) (1:M)'];
+  pcases = subv2ind([2 motif_length], ndx);
+  Oargs = {'CPT', obsprob, 'prior_type', 'entropic', 'entropic_pcases', pcases};
+end
+
+
+
+[bnet, Qnodes, Fnodes, Onode] = mk_hhmm('Qsizes', Qsize, 'Osize', Osize, 'discrete_obs', 1, ...
+	       'Oargs', Oargs, 'Ops', Qnodes(1:2), ...
+	       'startprob', startprob, 'transprob', transprob, 'termprob', termprob);
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/sample_motif_hhmm.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/sample_motif_hhmm.m
new file mode 100644
index 00000000..b5822e10
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Motif/sample_motif_hhmm.m
@@ -0,0 +1,10 @@
+%bnet = mk_motif_hhmm('motif_pattern', 'acca', 'background', 't');
+bnet = mk_motif_hhmm('motif_pattern', 'accaggggga', 'background', []);
+
+chars = ['a', 'c', 'g', 't'];
+Tmax = 100;
+
+for seqi=1:5
+  evidence = cell2num(sample_dbn(bnet, 'length', Tmax));
+  chars(evidence(end,:))
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/CVS/Entries b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/CVS/Entries
new file mode 100644
index 00000000..6caae4a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/CVS/Entries
@@ -0,0 +1,8 @@
+/mk_abcd_hhmm.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/mk_arrow_alpha_hhmm3.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/mk_hhmm2.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/mk_hhmm3.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/mk_hhmm3_args.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/motif_hhmm.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/remove_hhmm_end_state.m/1.1.1.1/Wed May 29 15:59:54 2002//
+D
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/CVS/Repository b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/CVS/Repository
new file mode 100644
index 00000000..cc9acc63
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/examples/dynamic/HHMM/Old
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/CVS/Root b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/mk_abcd_hhmm.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/mk_abcd_hhmm.m
new file mode 100644
index 00000000..330bc304
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/mk_abcd_hhmm.m
@@ -0,0 +1,109 @@
+% Make the HHMM in Figure 1 of the NIPS'01 paper
+
+Qsize = [2 3 2];
+D = 3;
+
+% transprob{d}(i,k,j), transprob{1}(i,j)
+% termprob{d}(k,j), termprob{1}(1,j)
+% startprob{d}(k,j), startprob{1}(1,j)
+% obsprob(k, o) for discrete outputs
+    
+% LEVEL 1
+%       1 2 e
+A{1} = [0 0 1;
+	0 0 1];
+[transprob{1}, termprob{1}] = remove_hhmm_end_state(A{1});
+startprob{1} = [0.5 0.5];
+Q1args = {'startprob', startprob{1}, 'transprob', transprob{1}};
+
+% LEVEL 2
+A{2} = zeros(Qsize(2), Qsize(1), Qsize(2)+1);
+
+%              1 2 3 e
+A{2}(:,1,:) = [0 1 0 0
+	       0 0 1 0
+	       0 0 0 1];
+
+%              1 2 3 e
+A{2}(:,2,:) = [0 1 0 0
+	       0 0 1 0
+	       0 0 0 1];
+
+[transprob{2}, termprob{2}] = remove_hhmm_end_state(A{2});	       
+
+% always enter level 2 in state 1
+startprob{2} = [1 0 0
+		1 0 0];
+
+Q2args = {'startprob', startprob{2}, 'transprob', transprob{2}};
+F2args = {'CPT', termprob{2}};
+
+
+% LEVEL 3
+
+A{3} = zeros([Qsize(3) Qsize(1:2) Qsize(3)+1]);
+endstate = Qsize(3)+1;
+%    Qt-1(3) Qt(1) Qt(2) Qt(3)
+%                               1   2   e
+A{3}(1,      1,    1,    endstate) = 1.0;
+A{3}(:,      1,    2,    :) = [0.0 1.0 0.0
+            	               0.5 0.0 0.5];
+A{3}(1,      1,    3,    endstate) = 1.0;
+
+A{3}(1,      2,    1,    endstate) = 1.0;
+A{3}(:,      2,    2,    :) = [0.0 1.0 0.0
+            	               0.5 0.0 0.5];
+A{3}(1,      2,    3,    endstate) = 1.0;
+
+A{3} = reshape(A{3}, [Qsize(3) prod(Qsize(1:2)) Qsize(3)+1]);
+[transprob{3}, termprob{3}] = remove_hhmm_end_state(A{3});	       
+
+% define the vertical entry points to level 3
+startprob{3} = zeros(Qsize);
+%            Q1 Q2 Q3
+startprob{3}(1, 1, 1) = 1.0;
+startprob{3}(1, 2, 1) = 1.0;
+startprob{3}(1, 3, 1) = 1.0;
+
+startprob{3}(2, 1, 1) = 1.0;
+startprob{3}(2, 2, 1) = 1.0;
+startprob{3}(2, 3, 1) = 1.0;
+
+startprob{3} = reshape(startprob{3}, prod(Qsize(1:2)), Qsize(3));
+
+chars = ['a', 'b', 'c', 'd', 'x', 'y'];
+Osize = length(chars);
+
+obsprob = zeros([Qsize Osize]);
+%       1 2 3 O
+obsprob(1,1,1,find(chars == 'a')) =  1.0;
+
+obsprob(1,2,1,find(chars == 'x')) =  1.0;
+obsprob(1,2,2,find(chars == 'y')) =  1.0;
+
+obsprob(1,3,1,find(chars == 'b')) =  1.0;
+
+obsprob(2,1,1,find(chars == 'c')) =  1.0;
+
+obsprob(2,2,1,find(chars == 'x')) =  1.0;
+obsprob(2,2,2,find(chars == 'y')) =  1.0;
+
+obsprob(2,3,1,find(chars == 'd')) =  1.0;
+
+obsprob = reshape(obsprob, prod(Qsize), Osize);
+
+[intra, inter, Qnodes, Fnodes, Onode] = mk_hhmm_topo(D);
+
+hhmm.Qnodes = Qnodes;
+hhmm.Fnodes = Fnodes;
+hhmm.Onode = Onode;
+hhmm.D = D;
+hhmm.Qsize = Qsize;
+hhmm.Osize = Osize;
+hhmm.startprob = startprob;
+hhmm.transprob = transprob;
+hhmm.termprob = termprob;
+hhmm.obsprob = obsprob;
+hhmm.A = A;
+
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/mk_arrow_alpha_hhmm3.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/mk_arrow_alpha_hhmm3.m
new file mode 100644
index 00000000..ba1aa8cb
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/mk_arrow_alpha_hhmm3.m
@@ -0,0 +1,86 @@
+% Make the following HHMM
+%
+%     LH                  RH
+%    /                      \
+%   /                        \
+%  LR -> UD -> RL -> DU       RL -> UD -> LR -> DU
+%   \
+%    \
+%     Q1 -> Q2
+%
+% where level 1 is fully interconnected (not shown)
+% level 2 is left-right
+% and each model at level 3 is a 2 state LR shared HMM 
+
+Qsizes = [2 4 2];
+D = 3;
+
+% LEVEL 1
+
+startprob1 = 'ergodic';
+transprob1 = 'ergodic';
+
+
+% LEVEL 2
+
+startprob = zeros(2, 4);
+%        Q1  Q2
+startprob(1, 1) = 1;
+startprob(2, 3) = 1;
+
+transprob = zeros(2, 4, 4);
+transprob(1,:,:) = [0 1 0 0
+		    0 0 1 0
+		    0 0 0 1
+		    0 0 0 1];
+transprob(2,:,:) = [0 0 0 1
+		    1 0 0 0
+		    0 1 0 0
+		    0 0 0 1];
+
+Q2args = {'startprob', startprob, 'transprob', transprob};
+
+% always terminate in state 4 (default)
+% F2args
+
+% LEVEL 3
+
+% Defaults are fine: always start in state 1, left-right model, finish in state 2
+
+
+% OBS LEVEl
+
+chars = ['L', 'l', 'U', 'u', 'R', 'r', 'D', 'd'];
+Osize = length(chars);
+
+obsprob = zeros([4 2 Osize]);
+%       Q2 Q3 O
+obsprob(1, 1, find(chars == 'L')) =  1.0;
+obsprob(1, 2, find(chars == 'l')) =  1.0;
+
+obsprob(2, 1, find(chars == 'U')) =  1.0;
+obsprob(2, 2, find(chars == 'u')) =  1.0;
+
+obsprob(3, 1, find(chars == 'R')) =  1.0;
+obsprob(3, 2, find(chars == 'r')) =  1.0;
+
+obsprob(4, 1, find(chars == 'D')) =  1.0;
+obsprob(4, 2, find(chars == 'd')) =  1.0;
+
+Oargs = {'CPT', obsprob};
+
+
+bnet = mk_hhmm3('Qsizes', Qsizes, 'Osize', Osize', 'discrete_obs', 1, 'Oargs', Oargs, 'Q1args', Q1args, 'Q2args', Q2args);
+
+T = 20;
+usecell = 0;
+evidence = sample_dbn(bnet, T, usecell);      
+%chars(evidence(end,:))
+
+Q1 = 1; Q2 = 2; Q3 = 3; F3 = 4; F2 = 5; obs = 6;
+Qnodes = [Q1 Q2 Q3]; Fnodes = [F2 F3];
+
+pretty_print_hhmm_parse(evidence, Qnodes, Fnodes, obs, chars);
+
+eclass = bnet.equiv_class;
+S=struct(bnet.CPD{eclass(Q2,2)})
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/mk_hhmm2.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/mk_hhmm2.m
new file mode 100644
index 00000000..032015ba
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/mk_hhmm2.m
@@ -0,0 +1,111 @@
+function bnet = mk_hhmm2(varargin)
+% MK_HHMM2 Make a 2 level Hierarchical HMM
+% bnet = mk_hhmm2(...)
+%
+% 2-layer hierarchical HMM  (node numbers in parens)
+%
+%   Q1(1) ---------> Q1(5)
+% /  | \            / |
+% |  |  v          /  |
+% |  |  F2(3) --- /   |
+% |  |  ^         \   |
+% |  | /           \  |
+% |  v              \ v
+% |  Q2(2)--------> Q2 (6)
+% |  |    
+% \  | 
+%  v v    
+%   O(4)
+%
+%
+% Optional arguments [default]
+%
+% discrete_obs - 1 means O is tabular_CPD, 0 means O is gaussian_CPD [0]
+% obsCPT       - CPT(o,q1,q2) params for O ['rnd']
+% mu           - mu(:,q1,q2) params for O [ [] ]
+% Sigma        - Sigma(:,q1,q2) params for O [ [] ]
+%
+% F2toQ1       - 1 if Q2 is an hhmm_CPD, 0 if F2 -> Q2 arc is absent, so level 2 never resets [1]
+% Q1args        - arguments to be passed to the constructors for Q1(t=2) [ {} ]
+% Q2args        - arguments to be passed to the constructors for Q2(t=2) [ {} ]
+%
+% F2 only turns on (wp 0.5) when Q2 enters its final state.
+% Q1 (slice 1) is clamped to be uniform.
+% Q2 (slice 1) is clamped to always start in state 1.
+
+[os nmodels nstates] = size(mu);
+
+ss = 4;
+Q1 = 1; Q2 = 2; F2 = 3; obs = 4;
+Qnodes = [Q1 Q2];
+names = {'Q1', 'Q2', 'F2', 'obs'};
+intra = zeros(ss);
+intra(Q1, [Q2 F2 obs]) = 1;
+intra(Q2, [F2 obs]) = 1;
+
+inter = zeros(ss);
+inter(Q1,Q1) = 1;
+inter(F2,Q1) = 1;
+if F2toQ2
+  inter(F2,Q2)=1;
+end
+inter(Q2,Q2) = 1;
+
+ns = zeros(1,ss);
+
+ns(Q1) = nmodels;
+ns(Q2) = nstates;
+ns(F2) = 2;
+ns(obs) = os;
+
+dnodes = [Q1 Q2 F2];
+if discrete_obs
+  dnodes = [dnodes obs];
+end
+onodes = [obs];
+
+bnet = mk_dbn(intra, inter, ns, 'observed', onodes, 'discrete', dnodes, 'names', names);
+eclass = bnet.equiv_class;
+
+% SLICE 1
+
+% We clamp untied nodes in the first slice, since their params can't be estimated
+% from just one sequence
+
+% uniform prior on initial model
+CPT = normalise(ones(1,nmodels));
+bnet.CPD{eclass(Q1,1)} = tabular_CPD(bnet, Q1, 'CPT', CPT, 'adjustable', 0);
+
+% each model always starts in state 1
+CPT = zeros(ns(Q1), ns(Q2));
+CPT(:, 1) = 1.0;
+bnet.CPD{eclass(Q2,1)} = tabular_CPD(bnet, Q2, 'CPT', CPT, 'adjustable', 0);
+
+% Termination probability
+CPT = zeros(ns(Q1), ns(Q2), 2);
+if 1
+  % Each model can only terminate in its final state.
+  % 0 params will remain 0 during EM, thus enforcing this constraint.
+  CPT(:, :, 1) = 1.0; % all states turn F off ...
+  p = 0.5;
+  CPT(:, ns(Q2), 2) = p; % except the last one
+  CPT(:, ns(Q2), 1) = 1-p;
+end
+bnet.CPD{eclass(F2,1)}  = tabular_CPD(bnet, F2, 'CPT', CPT);
+
+if discrete_obs
+  bnet.CPD{eclass(obs,1)} = tabular_CPD(bnet, obs, obs_args{:});
+else
+  bnet.CPD{eclass(obs,1)} = gaussian_CPD(bnet, obs, obs_args{:});
+end
+
+% SLICE 2
+
+
+bnet.CPD{eclass(Q1,2)} = hhmm_CPD(bnet, Q1+ss, Qnodes, 1, D, 'args', Q1args);
+
+if F2toQ2
+  bnet.CPD{eclass(Q2,2)} = hhmmQD_CPD(bnet, Q2+ss, Qnodes, 2, D, Q2args{:});
+else
+  bnet.CPD{eclass(Q2,2)} = tabular_CPD(bnet, Q2+ss, Q2args{:});
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/mk_hhmm3.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/mk_hhmm3.m
new file mode 100644
index 00000000..5b2cd6aa
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/mk_hhmm3.m
@@ -0,0 +1,181 @@
+function bnet = mk_hhmm3(varargin)
+% MK_HHMM3 Make a 3 level Hierarchical HMM
+% bnet = mk_hhmm3(...)
+%
+% 3-layer hierarchical HMM where level 1 only connects to level 2, not 3 or obs.
+% This enforces sub-models (which differ only in their Q1 index) to be shared.
+% Also, we enforce the fact that each model always starts in its initial state
+% and only finishes in its final state. However, the prob. of finishing (as opposed to
+% self-transitioning to the final state) can be learned.
+% The fact that we always finish from the same state means we do not need to condition
+% F(i) on Q(i-1), since finishing prob is indep of calling context.
+%
+% The DBN is the same as Fig 10 in my tech report.
+%
+%   Q1 ---------->  Q1
+%   |              / |
+%   |             /  |
+%   |  F2 -------    |
+%   |  ^         \   |
+%   | /|          \  |
+%   v  |           v v
+%   Q2-| -------->   Q2
+%  /|  |             ^
+% / |  |            /|
+% | |  F3 ---------/ |
+% | |  ^           \ |
+% | v /              v
+% | Q3 ----------->  Q3
+% |  |    
+% \  | 
+%  v v    
+%   O
+%
+%
+% Optional arguments in name/value format [default]
+%
+% Qsizes      - sizes at each level [ none ]
+% Osize       - size of O node [ none ]
+% discrete_obs - 1 means O is tabular_CPD, 0 means O is gaussian_CPD [0]
+% Oargs       - cell array of args to pass to the O CPD  [ {} ]
+% transprob1  - transprob1(i,j) = P(Q1(t)=j|Q1(t-1)=i)  ['ergodic']
+% startprob1  - startprob1(j) = P(Q1(t)=j)  ['leftstart']
+% transprob2  - transprob2(i,k,j) = P(Q2(t)=j|Q2(t-1)=i,Q1(t)=k)  ['leftright']
+% startprob2  - startprob2(k,j) = P(Q2(t)=j|Q1(t)=k)  ['leftstart']
+% termprob2   - termprob2(j,f) = P(F2(t)=f|Q2(t)=j)  ['rightstop']
+% transprob3  - transprob3(i,k,j) = P(Q3(t)=j|Q3(t-1)=i,Q2(t)=k)  ['leftright']
+% startprob3  - startprob3(k,j) = P(Q3(t)=j|Q2(t)=k)  ['leftstart']
+% termprob3   - termprob3(j,f) = P(F3(t)=f|Q3(t)=j)  ['rightstop']
+%
+% leftstart means the model always starts in state 1.
+% rightstop means the model always finished in its last state (Qsize(d)).
+%
+% Q1:Q3 in slice 1 are of type tabular_CPD
+% Q1:Q3 in slice 2 are of type hhmmQ_CPD.
+% F2 is of type hhmmF_CPD, F3 is of type tabular_CPD.
+
+ss = 6; D = 3;
+Q1 = 1; Q2 = 2; Q3 = 3; F3 = 4; F2 = 5; obs = 6;
+Qnodes = [Q1 Q2 Q3]; Fnodes = [F2 F3];
+names = {'Q1', 'Q2', 'Q3', 'F3', 'F2', 'obs'};
+
+intra = zeros(ss);
+intra(Q1, Q2) = 1;
+intra(Q2, [F2 Q3 obs]) = 1;
+intra(Q3, [F3 obs]) = 1;
+intra(F3, F2) = 1;
+
+inter = zeros(ss);
+inter(Q1,Q1) = 1;
+inter(Q2,Q2) = 1;
+inter(Q3,Q3) = 1;
+inter(F2,[Q1 Q2]) = 1;
+inter(F3,[Q2 Q3]) = 1;
+
+
+% get sizes of nodes
+args = varargin;
+nargs = length(args);
+Qsizes = [];
+Osize = 0;
+for i=1:2:nargs
+  switch args{i},
+   case 'Qsizes', Qsizes = args{i+1}; 
+   case 'Osize', Osize = args{i+1}; 
+  end
+end
+if isempty(Qsizes), error('must specify Qsizes'); end
+if Osize==0, error('must specify Osize'); end
+  
+% set default params
+discrete_obs = 0;
+Oargs = {};
+startprob1 = 'ergodic';
+startprob2 = 'leftstart';
+startprob3 = 'leftstart';
+transprob1 = 'ergodic';
+transprob2 = 'leftright';
+transprob3 = 'leftright';
+termprob2 = 'rightstop';
+termprob3 = 'rightstop';
+
+
+for i=1:2:nargs
+  switch args{i},
+   case 'discrete_obs', discrete_obs = args{i+1}; 
+   case 'Oargs',        Oargs = args{i+1};
+   case 'Q1args',       Q1args = args{i+1};
+   case 'Q2args',       Q2args = args{i+1};
+   case 'Q3args',       Q3args = args{i+1};
+   case 'F2args',       F2args = args{i+1};
+   case 'F3args',       F3args = args{i+1};
+  end
+end
+
+
+ns = zeros(1,ss);
+ns(Qnodes) = Qsizes;
+ns(obs) = Osize;
+ns(Fnodes) = 2;
+
+dnodes = [Qnodes Fnodes];
+if discrete_obs
+  dnodes = [dnodes obs];
+end
+onodes = [obs];
+
+bnet = mk_dbn(intra, inter, ns, 'observed', onodes, 'discrete', dnodes, 'names', names);
+eclass = bnet.equiv_class;
+
+if strcmp(startprob1, 'ergodic')
+  startprob1 = normalise(ones(1,ns(Q1)));
+end
+if strcmp(startprob2, 'leftstart')
+  startprob2 = zeros(ns(Q1), ns(Q2));
+  starpbrob2(:, 1) = 1.0;
+end
+if strcmp(startprob3, 'leftstart')
+  startprob3 = zeros(ns(Q2), ns(Q3));
+  starpbrob3(:, 1) = 1.0;
+end
+
+if strcmp(termprob2, 'rightstop')
+  p = 0.9;
+  termprob2 = zeros(Qsize(2),2);
+  termprob2(:, 2) = p; 
+  termprob2(:, 1) = 1-p; 
+  termprob2(1:(Qsize(2)-1), 1) = 1; 
+end
+if strcmp(termprob3, 'rightstop')
+  p = 0.9;
+  termprob3 = zeros(Qsize(3),2);
+  termprob3(:, 2) = p; 
+  termprob3(:, 1) = 1-p; 
+  termprob3(1:(Qsize(3)-1), 1) = 1; 
+end
+
+
+% SLICE 1
+
+% We clamp untied nodes in the first slice, since their params can't be estimated
+% from just one sequence
+
+bnet.CPD{eclass(Q1,1)} = tabular_CPD(bnet, Q1, 'CPT', startprob1, 'adjustable', 0);
+bnet.CPD{eclass(Q2,1)} = tabular_CPD(bnet, Q2, 'CPT', startprob2, 'adjustable', 0);
+bnet.CPD{eclass(Q3,1)} = tabular_CPD(bnet, Q3, 'CPT', startprob3, 'adjustable', 0);
+
+bnet.CPD{eclass(F2,1)}  = hhmmF_CPD(bnet, F2, Qnodes, 2, D, 'termprob', termprob2);
+bnet.CPD{eclass(F3,1)}  = tabular_CPD(bnet, F3, 'CPT', termprob3);
+
+if discrete_obs
+  bnet.CPD{eclass(obs,1)} = tabular_CPD(bnet, obs, Oargs{:});
+else
+  bnet.CPD{eclass(obs,1)} = gaussian_CPD(bnet, obs, Oargs{:});
+end
+
+% SLICE 2
+
+bnet.CPD{eclass(Q1,2)} = hhmmQ_CPD(bnet, Q1+ss, Qnodes, 1, D, 'transprob', transprob1, 'startprob', startprob1);
+bnet.CPD{eclass(Q2,2)} = hhmmQ_CPD(bnet, Q2+ss, Qnodes, 2, D, 'transprob', transprob2, 'startprob', startprob2);
+bnet.CPD{eclass(Q3,2)} = hhmmQ_CPD(bnet, Q3+ss, Qnodes, 3, D, 'transprob', transprob3, 'startprob', startprob3);
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/mk_hhmm3_args.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/mk_hhmm3_args.m
new file mode 100644
index 00000000..bc3ec886
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/mk_hhmm3_args.m
@@ -0,0 +1,165 @@
+function bnet = mk_hhmm3(varargin)
+% MK_HHMM3 Make a 3 level Hierarchical HMM
+% bnet = mk_hhmm3(...)
+%
+% 3-layer hierarchical HMM where level 1 only connects to level 2, not 3 or obs.
+% This enforces sub-models (which differ only in their Q1 index) to be shared.
+% Also, we enforce the fact that each model always starts in its initial state
+% and only finishes in its final state. However, the prob. of finishing (as opposed to
+% self-transitioning to the final state) can be learned.
+% The fact that we always finish from the same state means we do not need to condition
+% F(i) on Q(i-1), since finishing prob is indep of calling context.
+%
+% The DBN is the same as Fig 10 in my tech report.
+%
+%   Q1 ---------->  Q1
+%   |              / |
+%   |             /  |
+%   |  F2 -------    |
+%   |  ^         \   |
+%   | /|          \  |
+%   v  |           v v
+%   Q2-| -------->   Q2
+%  /|  |             ^
+% / |  |            /|
+% | |  F3 ---------/ |
+% | |  ^           \ |
+% | v /              v
+% | Q3 ----------->  Q3
+% |  |    
+% \  | 
+%  v v    
+%   O
+%
+% Q1 (slice 1) is clamped to be uniform.
+% Q2 (slice 1) is clamped to always start in state 1.
+% Q3 (slice 1) is clamped to always start in state 1.
+% F3 by default will only finish if Q3 is in its last state (F3 is a tabular_CPD)
+% F2 by default gets the default hhmmF_CPD params.
+% Q1:Q3 (slice 2) by default gets the default hhmmQ_CPD params.
+% O by default gets the default tabular/Gaussian params.
+%
+% Optional arguments in name/value format [default]
+%
+% Qsizes      - sizes at each level [ none ]
+% Osize       - size of O node [ none ]
+% discrete_obs - 1 means O is tabular_CPD, 0 means O is gaussian_CPD [0]
+% Oargs       - cell array of args to pass to the O CPD  [ {} ]
+% Q1args      - args to be passed to constructor for Q1 (slice 2) [ {} ]
+% Q2args      - args to be passed to constructor for Q2 (slice 2) [ {} ]
+% Q3args      - args to be passed to constructor for Q3 (slice 2) [ {} ]
+% F2args       - args to be passed to constructor for F2 [ {} ]
+% F3args       - args to be passed to constructor for F3 [ {'CPT', finish in last Q3 state} ]
+%
+
+ss = 6; D = 3;
+Q1 = 1; Q2 = 2; Q3 = 3; F3 = 4; F2 = 5; obs = 6;
+Qnodes = [Q1 Q2 Q3]; Fnodes = [F2 F3];
+names = {'Q1', 'Q2', 'Q3', 'F3', 'F2', 'obs'};
+
+intra = zeros(ss);
+intra(Q1, Q2) = 1;
+intra(Q2, [F2 Q3 obs]) = 1;
+intra(Q3, [F3 obs]) = 1;
+intra(F3, F2) = 1;
+
+inter = zeros(ss);
+inter(Q1,Q1) = 1;
+inter(Q2,Q2) = 1;
+inter(Q3,Q3) = 1;
+inter(F2,[Q1 Q2]) = 1;
+inter(F3,[Q2 Q3]) = 1;
+
+
+% get sizes of nodes
+args = varargin;
+nargs = length(args);
+Qsizes = [];
+Osize = 0;
+for i=1:2:nargs
+  switch args{i},
+   case 'Qsizes', Qsizes = args{i+1}; 
+   case 'Osize', Osize = args{i+1}; 
+  end
+end
+if isempty(Qsizes), error('must specify Qsizes'); end
+if Osize==0, error('must specify Osize'); end
+  
+% set default params
+discrete_obs = 0;
+Oargs = {};
+Q1args = {};
+Q2args = {};
+Q3args = {};
+F2args = {};
+
+% P(Q3, F3)
+CPT = zeros(Qsizes(3), 2);
+% Each model can only terminate in its final state.
+% 0 params will remain 0 during EM, thus enforcing this constraint.
+CPT(:, 1) = 1.0; % all states turn F off ...
+p = 0.5;
+CPT(Qsizes(3), 2) = p; % except the last one
+CPT(Qsizes(3), 1) = 1-p;
+F3args = {'CPT', CPT};
+
+for i=1:2:nargs
+  switch args{i},
+   case 'discrete_obs', discrete_obs = args{i+1}; 
+   case 'Oargs',        Oargs = args{i+1};
+   case 'Q1args',       Q1args = args{i+1};
+   case 'Q2args',       Q2args = args{i+1};
+   case 'Q3args',       Q3args = args{i+1};
+   case 'F2args',       F2args = args{i+1};
+   case 'F3args',       F3args = args{i+1};
+  end
+end
+
+ns = zeros(1,ss);
+ns(Qnodes) = Qsizes;
+ns(obs) = Osize;
+ns(Fnodes) = 2;
+
+dnodes = [Qnodes Fnodes];
+if discrete_obs
+  dnodes = [dnodes obs];
+end
+onodes = [obs];
+
+bnet = mk_dbn(intra, inter, ns, 'observed', onodes, 'discrete', dnodes, 'names', names);
+eclass = bnet.equiv_class;
+
+% SLICE 1
+
+% We clamp untied nodes in the first slice, since their params can't be estimated
+% from just one sequence
+
+% uniform prior on initial model
+CPT = normalise(ones(1,ns(Q1)));
+bnet.CPD{eclass(Q1,1)} = tabular_CPD(bnet, Q1, 'CPT', CPT, 'adjustable', 0);
+
+% each model always starts in state 1
+CPT = zeros(ns(Q1), ns(Q2));
+CPT(:, 1) = 1.0;
+bnet.CPD{eclass(Q2,1)} = tabular_CPD(bnet, Q2, 'CPT', CPT, 'adjustable', 0);
+
+% each model always starts in state 1
+CPT = zeros(ns(Q2), ns(Q3));
+CPT(:, 1) = 1.0;
+bnet.CPD{eclass(Q3,1)} = tabular_CPD(bnet, Q3, 'CPT', CPT, 'adjustable', 0);
+
+bnet.CPD{eclass(F2,1)}  = hhmmF_CPD(bnet, F2, Qnodes, 2, D, F2args{:});
+
+bnet.CPD{eclass(F3,1)}  = tabular_CPD(bnet, F3, F3args{:});
+
+if discrete_obs
+  bnet.CPD{eclass(obs,1)} = tabular_CPD(bnet, obs, Oargs{:});
+else
+  bnet.CPD{eclass(obs,1)} = gaussian_CPD(bnet, obs, Oargs{:});
+end
+
+% SLICE 2
+
+bnet.CPD{eclass(Q1,2)} = hhmmQ_CPD(bnet, Q1+ss, Qnodes, 1, D, Q1args{:});
+bnet.CPD{eclass(Q2,2)} = hhmmQ_CPD(bnet, Q2+ss, Qnodes, 2, D, Q2args{:});
+bnet.CPD{eclass(Q3,2)} = hhmmQ_CPD(bnet, Q3+ss, Qnodes, 3, D, Q3args{:});
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/motif_hhmm.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/motif_hhmm.m
new file mode 100644
index 00000000..10144b58
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/motif_hhmm.m
@@ -0,0 +1,95 @@
+% Make the following HHMM
+%
+%    S1 <----------------------> S2
+%    |                           |
+%    |                           |
+%   M1 -> M2 -> M3 -> end        B1 -> end
+%
+% where Mi represents the i'th letter in the motif
+% and B is the background state.
+% Si chooses between running the motif or the background.
+% The Si and B states have self loops (not shown).
+
+if 0
+seed = 0;
+rand('state', seed);
+randn('state', seed);
+end
+
+chars = ['a', 'c', 'g', 't'];
+Osize = length(chars);
+
+motif_pattern = 'acca';
+motif_length = length(motif_pattern);
+Qsize = [2 motif_length];
+Qnodes = 1:2;
+D = 2;
+transprob = cell(1,D);
+termprob = cell(1,D);
+startprob = cell(1,D);
+
+% startprob{d}(k,j), startprob{1}(1,j)
+% transprob{d}(i,k,j), transprob{1}(i,j)
+% termprob{d}(k,j)
+
+
+% LEVEL 1
+
+startprob{1} = zeros(1, 2);
+startprob{1} = [1 0]; % always start in the background model
+
+% When in the background state, we stay there with high prob
+% When in the motif state, we immediately return to the background state.
+transprob{1} = [0.8 0.2;
+		1.0 0.0];
+
+
+% LEVEL 2
+startprob{2} = 'leftstart'; % both submodels start in substate 1
+transprob{2} = zeros(motif_length, 2, motif_length);
+termprob{2} = zeros(2, motif_length);
+
+% In the background model, we only use state 1.
+transprob{2}(1,1,1) = 1; % self loop
+termprob{2}(1,1) = 0.2; % prob transition to end state
+
+% Motif model
+transprob{2}(:,2,:) = mk_leftright_transmat(motif_length, 0);
+termprob{2}(2,end) = 1.0; % last state immediately terminates
+
+
+% OBS LEVEl
+
+obsprob = zeros([Qsize Osize]);
+if 0
+  % uniform background model
+  obsprob(1,1,:) = normalise(ones(Osize,1));
+else
+  % deterministic background model (easy to see!)
+  m = find(chars=='t');
+  obsprob(1,1,m) = 1.0;
+end
+if 1
+  % initialise with true motif (cheating)
+  for i=1:motif_length
+    m = find(chars == motif_pattern(i));
+    obsprob(2,i,m) = 1.0;
+  end
+end
+
+Oargs = {'CPT', obsprob};
+
+[bnet, Qnodes, Fnodes, Onode] = mk_hhmm('Qsizes', Qsize, 'Osize', Osize, 'discrete_obs', 1, ...
+	       'Oargs', Oargs, 'Ops', Qnodes(1:2), ...
+	       'startprob', startprob, 'transprob', transprob, 'termprob', termprob);
+
+
+Tmax = 20;
+usecell = 0;
+
+for seqi=1:5
+  evidence = sample_dbn(bnet, Tmax, usecell);
+  chars(evidence(end,:))
+  %T = size(evidence, 2)
+  %pretty_print_hhmm_parse(evidence, Qnodes, Fnodes, Onode, chars);
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/remove_hhmm_end_state.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/remove_hhmm_end_state.m
new file mode 100644
index 00000000..2bf10d72
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Old/remove_hhmm_end_state.m
@@ -0,0 +1,37 @@
+function [transprob, termprob] = remove_hhmm_end_state(A)
+% REMOVE_END_STATE Infer transition and termination probabilities from automaton with an end state
+% [transprob, termprob] = remove_end_state(A)
+% A(i,k,j) = Pr( i->j | Qps=k), where i in 1:Q, j in 1:(Q+1), and Q+1 is the end state
+
+if ndims(A)==2 % top level
+  Q = size(A,1);
+  transprob = A(:,1:Q);
+  termprob = A(:,Q+1)';
+  
+  % rescale
+  for i=1:Q
+    for j=1:Q
+      denom = (1-termprob(i));
+      denom = denom + (denom==0)*eps;
+      transprob(i,j) = transprob(i,j) / denom;
+    end
+  end    
+else
+  Q = size(A,1);
+  Qk = size(A,2);
+  transprob = A(:, :, 1:Q);
+  termprob = A(:,:,Q+1)';
+
+  % rescale
+  for k=1:Qk
+    for i=1:Q
+      for j=1:Q
+	denom = (1-termprob(k,i));
+	denom = denom + (denom==0)*eps;
+	transprob(i,k,j) = transprob(i,k,j) / denom;
+      end
+    end    
+  end
+  
+end
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/CVS/Entries b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/CVS/Entries
new file mode 100644
index 00000000..fdee19ae
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/CVS/Entries
@@ -0,0 +1,14 @@
+/get_square_data.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/hhmm_inference.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/is_F2_true_D3.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/learn_square_hhmm_cts.m/1.1.1.1/Thu Jun 20 00:19:22 2002//
+/learn_square_hhmm_discrete.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/mk_square_hhmm.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/plot_square_hhmm.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/sample_square_hhmm_cts.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/sample_square_hhmm_discrete.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/square4.mat/1.1.1.1/Wed May 29 15:59:54 2002//
+/square4_cases.mat/1.1.1.1/Wed May 29 15:59:54 2002//
+/test_square_fig.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/test_square_fig.mat/1.1.1.1/Wed May 29 15:59:54 2002//
+D/Old////
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/CVS/Repository b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/CVS/Repository
new file mode 100644
index 00000000..e926a0d5
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/examples/dynamic/HHMM/Square
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/CVS/Root b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/CVS/Entries b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/CVS/Entries
new file mode 100644
index 00000000..6d415d0d
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/CVS/Entries
@@ -0,0 +1,5 @@
+/learn_square_hhmm.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/mk_square_hhmm.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/plot_square_hhmm.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/sample_square_hhmm.m/1.1.1.1/Wed May 29 15:59:54 2002//
+D
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/CVS/Repository b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/CVS/Repository
new file mode 100644
index 00000000..47df1a8c
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/examples/dynamic/HHMM/Square/Old
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/CVS/Root b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/learn_square_hhmm.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/learn_square_hhmm.m
new file mode 100644
index 00000000..695ae047
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/learn_square_hhmm.m
@@ -0,0 +1,294 @@
+% Learn a 3 level HHMM similar to mk_square_hhmm
+
+% Because startprob should be shared for t=1:T,
+% but in the DBN is shared for t=2:T, we train using a single long sequence.
+
+discrete_obs = 0;
+supervised = 1;
+obs_finalF2 = 0;
+% It is not possible to observe F2 if we learn
+% because the update_ess method for hhmmF_CPD and hhmmQ_CPD assume
+% the F nodes are always hidden (for speed).
+% However, for generating, we might want to set the final F2=true
+% to force all subroutines to finish.
+
+ss = 6;
+Q1 = 1; Q2 = 2; Q3 = 3; F3 = 4; F2 = 5; Onode = 6;
+Qnodes = [Q1 Q2 Q3]; Fnodes = [F2 F3];
+
+seed = 1;
+rand('state', seed);
+randn('state', seed);
+
+if discrete_obs
+  Qsizes = [2 4 2];
+else
+  Qsizes = [2 4 1];
+end
+
+D = 3;
+Qnodes = 1:D;
+startprob = cell(1,D);
+transprob = cell(1,D);
+termprob = cell(1,D);
+
+startprob{1} = 'unif';
+transprob{1} = 'unif';
+
+% In the unsupervised case, it is essential that we break symmetry
+% in the initial param estimates.
+%startprob{2} = 'unif';
+%transprob{2} = 'unif';
+%termprob{2} = 'unif';
+startprob{2} = 'rnd';
+transprob{2} = 'rnd';
+termprob{2} = 'rnd';
+
+leftright = 0;
+if leftright
+  % Initialise base-level models as left-right.
+  % If we initialise with delta functions,
+  % they will remain delat funcitons after learning
+  startprob{3} = 'leftstart';
+  transprob{3}  = 'leftright';
+  termprob{3} = 'rightstop';
+else
+  % If we want to be able to run a base-level model backwards...
+  startprob{3} = 'rnd';
+  transprob{3}  = 'rnd';
+  termprob{3} = 'rnd';
+end
+
+if discrete_obs
+  % Initialise observations of lowest level primitives in a way which we can interpret
+  chars = ['L', 'l', 'U', 'u', 'R', 'r', 'D', 'd'];
+  L=find(chars=='L'); l=find(chars=='l');
+  U=find(chars=='U'); u=find(chars=='u');
+  R=find(chars=='R'); r=find(chars=='r');
+  D=find(chars=='D'); d=find(chars=='d');
+  Osize = length(chars);
+  
+  p = 0.9;
+  obsprob = (1-p)*ones([4 2 Osize]);
+  %       Q2 Q3 O
+  obsprob(1, 1, L) =  p;
+  obsprob(1, 2, l) =  p;
+  obsprob(2, 1, U) =  p;
+  obsprob(2, 2, u) =  p;
+  obsprob(3, 1, R) =  p;
+  obsprob(3, 2, r) =  p;
+  obsprob(4, 1, D) =  p;
+  obsprob(4, 2, d) =  p;
+  obsprob = mk_stochastic(obsprob);
+  Oargs = {'CPT', obsprob};
+
+else
+  % Initialise means of lowest level primitives in a way which we can interpret
+  % These means are little vectors in the east, south, west, north directions.
+  % (left-right=east, up-down=south, right-left=west, down-up=north)
+  Osize = 2;
+  mu = zeros(2, Qsizes(2), Qsizes(3));
+  noise = 0;
+  scale = 3;
+  for q3=1:Qsizes(3)
+    mu(:, 1, q3) = scale*[1;0] + noise*rand(2,1);
+  end
+  for q3=1:Qsizes(3)
+    mu(:, 2, q3) = scale*[0;-1] + noise*rand(2,1);
+  end
+  for q3=1:Qsizes(3)
+    mu(:, 3, q3) = scale*[-1;0] + noise*rand(2,1);
+  end
+  for q3=1:Qsizes(3)
+    mu(:, 4, q3) = scale*[0;1] + noise*rand(2,1);
+  end
+  Sigma = repmat(reshape(scale*eye(2), [2 2 1 1 ]), [1 1 Qsizes(2) Qsizes(3)]);
+  Oargs = {'mean', mu, 'cov', Sigma, 'cov_type', 'diag'};
+end
+
+bnet = mk_hhmm('Qsizes', Qsizes, 'Osize', Osize', 'discrete_obs', discrete_obs,...
+	       'Oargs', Oargs, 'Ops', Qnodes(2:3), ...
+	       'startprob', startprob, 'transprob', transprob, 'termprob', termprob);
+
+if supervised
+  bnet.observed = [Q1 Q2 Onode];
+else
+  bnet.observed = [Onode];
+end
+
+if obs_finalF2
+  engine = jtree_dbn_inf_engine(bnet);
+  % can't use ndx version because sometimes F2 is hidden, sometimes observed
+  error('can''t observe F when learning')
+else
+  if supervised
+    engine = jtree_ndx_dbn_inf_engine(bnet);
+  else
+    engine = jtree_hmm_inf_engine(bnet);
+  end
+end
+  
+if discrete_obs
+  % generate some synthetic data (easier to debug)
+  cases = {};
+
+  T = 8;
+  ev = cell(ss, T);
+  ev(Onode,:) = num2cell([L l U u R r D d]);
+  if supervised
+    ev(Q1,:) = num2cell(1*ones(1,T));
+    ev(Q2,:) = num2cell( [1 1 2 2 3 3 4 4]);
+  end
+  cases{1} = ev;
+  cases{3} = ev;
+    
+  T  = 8;
+  ev = cell(ss, T);
+  if leftright % base model is left-right
+    ev(Onode,:) = num2cell([R r U u L l D d]);
+  else
+    ev(Onode,:) = num2cell([r R u U l L d D]);
+  end
+  if supervised
+    ev(Q1,:) = num2cell(2*ones(1,T));
+    ev(Q2,:) = num2cell( [3 3 2 2 1 1 4 4]);
+  end
+    
+  cases{2} = ev;
+  cases{4} = ev;
+
+  if obs_finalF2
+    for i=1:length(cases)
+      T = size(cases{i},2);
+      cases{i}(F2,T)={2}; % force F2 to be finished at end of seq
+    end
+  end
+
+  if 0
+    ev = cases{4};
+    engine2 = enter_evidence(engine2, ev);
+    T = size(ev,2);
+    for t=1:T
+      m=marginal_family(engine2, F2, t);
+      fprintf('t=%d\n', t);
+      reshape(m.T, [2 2])
+    end
+  end
+  
+  %  [bnet2, LL] = learn_params_dbn_em(engine, cases, 'max_iter', 10);
+  long_seq = cat(2, cases{:});
+  [bnet2, LL, engine2] = learn_params_dbn_em(engine, {long_seq}, 'max_iter', 200);
+  
+  % figure out which subsequence each model is responsible for
+  mpe = calc_mpe_dbn(engine2, long_seq);
+  pretty_print_hhmm_parse(mpe, Qnodes, Fnodes, Onode, chars);
+
+else
+  load 'square4_cases' % cases{seq}{i,t} for i=1:ss 
+  %plot_square_hhmm(cases{1})
+  %long_seq = cat(2, cases{:});
+  train_cases = cases(1:2);
+  long_seq = cat(2, train_cases{:});
+  if ~supervised
+    T = size(long_seq,2);
+    for t=1:T
+      long_seq{Q1,t} = [];
+      long_seq{Q2,t} = [];
+    end
+  end
+  [bnet2, LL, engine2] = learn_params_dbn_em(engine, {long_seq}, 'max_iter', 100);
+
+  CPDO=struct(bnet2.CPD{eclass(Onode,1)});
+  mu = CPDO.mean;
+  Sigma = CPDO.cov;
+  CPDO_full = CPDO;
+  
+  % force diagonal covs after training
+  for k=1:size(Sigma,3)
+    Sigma(:,:,k) = diag(diag(Sigma(:,:,k)));
+  end
+  bnet2.CPD{6} = set_fields(bnet.CPD{6}, 'cov', Sigma);
+  
+  if 0
+  % visualize each model by concatenating means for each model for nsteps in a row
+  nsteps = 5;
+  ev = cell(ss, nsteps*prod(Qsizes(2:3)));
+  t = 1;
+  for q2=1:Qsizes(2)
+    for q3=1:Qsizes(3)
+      for i=1:nsteps
+	ev{Onode,t} = mu(:,q2,q3);
+	ev{Q2,t} = q2;
+	t = t + 1;
+      end
+    end
+  end
+  plot_square_hhmm(ev)      
+  end
+
+  % bnet3 is the same as the learned model, except we will use it in testing mode
+  if supervised
+    bnet3 = bnet2;
+    bnet3.observed = [Onode];
+    engine3 = hmm_inf_engine(bnet3);
+    %engine3 = jtree_ndx_dbn_inf_engine(bnet3);
+  else
+    bnet3 = bnet2;
+    engine3 = engine2;
+  end
+  
+  if 0
+  % segment whole sequence
+  mpe = calc_mpe_dbn(engine3, long_seq);
+  pretty_print_hhmm_parse(mpe, Qnodes, Fnodes, Onode, []);
+  end
+  
+  % segment each sequence
+  test_cases = cases(3:4);
+  for i=1:2
+    ev = test_cases{i};
+    T = size(ev, 2);
+    for t=1:T
+      ev{Q1,t} = [];
+      ev{Q2,t} = [];
+    end
+    mpe = calc_mpe_dbn(engine3, ev);
+    subplot(1,2,i)
+    plot_square_hhmm(mpe)      
+    %pretty_print_hhmm_parse(mpe, Qnodes, Fnodes, Onode, []);
+    q1s = cell2num(mpe(Q1,:));
+    h = hist(q1s, 1:Qsizes(1));
+    map_q1 = argmax(h);
+    str = sprintf('test seq %d is of type %d\n', i, map_q1);
+    title(str)
+  end
+
+end
+
+if 0
+% Estimate gotten by couting transitions in the labelled data
+% Note that a self transition shouldnt count if F2=off.
+Q2ev = cell2num(ev(Q2,:));
+Q2a = Q2ev(1:end-1);
+Q2b = Q2ev(2:end);
+counts = compute_counts([Q2a; Q2b], [4 4]);
+end
+
+eclass = bnet2.equiv_class;
+CPDQ1=struct(bnet2.CPD{eclass(Q1,2)});
+CPDQ2=struct(bnet2.CPD{eclass(Q2,2)});
+CPDQ3=struct(bnet2.CPD{eclass(Q3,2)});
+CPDF2=struct(bnet2.CPD{eclass(F2,1)});
+CPDF3=struct(bnet2.CPD{eclass(F3,1)});
+
+
+A=add_hhmm_end_state(CPDQ2.transprob, CPDF2.termprob(:,:,2));
+squeeze(A(:,1,:))
+squeeze(A(:,2,:))
+CPDQ2.startprob
+ 
+if 0
+S=struct(CPDF2.sub_CPD_term);
+S.nsamples
+reshape(S.counts, [2 4 2])
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/mk_square_hhmm.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/mk_square_hhmm.m
new file mode 100644
index 00000000..608b6784
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/mk_square_hhmm.m
@@ -0,0 +1,183 @@
+function bnet = mk_square_hhmm(discrete_obs, true_params, topright)
+
+% Make a 3 level  HHMM described by the following grammar
+%
+% Square -> CLK | CCK % clockwise or counterclockwise
+% CLK -> LR UD RL DU start on top left (1 2 3 4)
+% CCK -> RL UD LR DU  if start at top right (3 2 1 4)
+% CCK -> UD LR DU RL if start at top left (2 1 4 3)
+%
+% LR = left-right, UD = up-down, RL = right-left, DU = down-up
+% LR, UD, RL, DU are sub HMMs.
+%
+% For discrete observations, the subHMMs are 2-state left-right.
+% LR emits L then l, etc.
+%
+% For cts observations, the subHMMs are 1 state.
+% LR emits a vector in the -> direction, with a little noise.
+% Since there is no constraint that we remain in the LR state as long as the RL state,
+% the sides of the square might have different lengths,
+% so the result is not really a square!
+%
+% If true_params = 0, we use random parameters at the top 2 levels
+% (ready for learning). At the bottom level, we use noisy versions
+% of the "true" observations.
+%
+% If topright=1, counter-clockwise starts at top right, not top left
+% This example was inspired by Ivanov and Bobick.
+
+if nargin < 3, topright = 1; end
+
+if 1 % discrete_obs
+  Qsizes = [2 4 2];
+else
+  Qsizes = [2 4 1];
+end
+
+D = 3;
+Qnodes = 1:D;
+startprob = cell(1,D);
+transprob = cell(1,D);
+termprob = cell(1,D);
+
+% LEVEL 1
+
+startprob{1} = 'unif';
+transprob{1} = 'unif';
+
+% LEVEL 2
+
+if true_params
+  startprob{2} = zeros(2, 4);
+  startprob{2}(1, :) = [1 0 0 0];
+  if topright
+    startprob{2}(2, :) = [0 0 1 0];
+  else
+    startprob{2}(2, :) = [0 1 0 0];
+  end
+  
+  transprob{2} = zeros(4, 2, 4);
+  
+  transprob{2}(:,1,:) = [0 1 0 0
+		    0 0 1 0
+		    0 0 0 1
+		    0 0 0 1]; % 4->e
+  if topright
+    transprob{2}(:,2,:) = [0 0 0 1
+		    1 0 0 0
+		    0 1 0 0
+		    0 0 0 1]; % 4->e
+  else
+    transprob{2}(:,2,:) = [0 0 0 1
+		    1 0 0 0
+		    0 0 1 0 % 3->e
+		    0 0 1 0];
+  end
+  
+  %termprob{2} = 'rightstop';
+  termprob{2} = zeros(2,4,2);
+  pfin = 0.8;
+  termprob{2}(1,:,2) = [0 0 0 pfin]; % finish in state 4 (DU)
+  termprob{2}(1,:,1) = 1 - [0 0 0 pfin];
+  if topright
+    termprob{2}(2,:,2) = [0 0 0 pfin];
+    termprob{2}(2,:,1) = 1 - [0 0 0 pfin];
+  else
+    termprob{2}(2,:,2) = [0 0 pfin 0];  % finish in state 3 (RL)
+    termprob{2}(2,:,1) = 1 - [0 0 pfin 0];
+  end
+else
+  % In the unsupervised case, it is essential that we break symmetry
+  % in the initial param estimates.
+  %startprob{2} = 'unif';
+  %transprob{2} = 'unif';
+  %termprob{2} = 'unif';
+  startprob{2} = 'rnd';
+  transprob{2} = 'rnd';
+  termprob{2} = 'rnd';
+end
+
+% LEVEL 3
+
+if 1 |  true_params
+  startprob{3} = 'leftstart';
+  transprob{3}  = 'leftright';
+  termprob{3} = 'rightstop';
+else
+  % If we want to be able to run a base-level model backwards...
+  startprob{3} = 'rnd';
+  transprob{3}  = 'rnd';
+  termprob{3} = 'rnd';
+end
+ 
+
+% OBS LEVEl
+
+if discrete_obs
+  % Initialise observations of lowest level primitives in a way which we can interpret
+  chars = ['L', 'l', 'U', 'u', 'R', 'r', 'D', 'd'];
+  L=find(chars=='L'); l=find(chars=='l');
+  U=find(chars=='U'); u=find(chars=='u');
+  R=find(chars=='R'); r=find(chars=='r');
+  D=find(chars=='D'); d=find(chars=='d');
+  Osize = length(chars);
+  
+  if true_params
+    p = 1; % makes each state fully observed
+  else
+    p = 0.9;
+  end
+  
+  obsprob = (1-p)*ones([4 2 Osize]);
+  %       Q2 Q3 O
+  obsprob(1, 1, L) =  p;
+  obsprob(1, 2, l) =  p;
+  obsprob(2, 1, U) =  p;
+  obsprob(2, 2, u) =  p;
+  obsprob(3, 1, R) =  p;
+  obsprob(3, 2, r) =  p;
+  obsprob(4, 1, D) =  p;
+  obsprob(4, 2, d) =  p;
+  obsprob = mk_stochastic(obsprob);
+  Oargs = {'CPT', obsprob};
+else
+  % Initialise means of lowest level primitives in a way which we can interpret
+  % These means are little vectors in the east, south, west, north directions.
+  % (left-right=east, up-down=south, right-left=west, down-up=north)
+  Osize = 2;
+  mu = zeros(2, Qsizes(2), Qsizes(3));
+  scale = 3;
+  if true_params
+    noise = 0;
+  else
+    noise = 0.5*scale;
+  end
+  for q3=1:Qsizes(3)
+    mu(:, 1, q3) = scale*[1;0] + noise*rand(2,1);
+  end
+  for q3=1:Qsizes(3)
+    mu(:, 2, q3) = scale*[0;-1] + noise*rand(2,1);
+  end
+  for q3=1:Qsizes(3)
+    mu(:, 3, q3) = scale*[-1;0] + noise*rand(2,1);
+  end
+  for q3=1:Qsizes(3)
+    mu(:, 4, q3) = scale*[0;1] + noise*rand(2,1);
+  end
+  Sigma = repmat(reshape(scale*eye(2), [2 2 1 1 ]), [1 1 Qsizes(2) Qsizes(3)]);
+  Oargs = {'mean', mu, 'cov', Sigma, 'cov_type', 'diag'};
+end
+
+if discrete_obs
+  selfprob = 0.5;
+else
+  selfprob = 0.95;
+  % If less than this, it won't look like a square
+  % because it doesn't spend enough time in each state
+  % Unfortunately, the variance on durations (lengths of each side)
+  % is very large
+end
+bnet = mk_hhmm('Qsizes', Qsizes, 'Osize', Osize', 'discrete_obs', discrete_obs, ...
+	       'Oargs', Oargs, 'Ops', Qnodes(2:3), 'selfprob', selfprob, ...
+	       'startprob', startprob, 'transprob', transprob, 'termprob', termprob);
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/plot_square_hhmm.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/plot_square_hhmm.m
new file mode 100644
index 00000000..e6701e45
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/plot_square_hhmm.m
@@ -0,0 +1,32 @@
+function plot_square_hhmm(ev)
+% Plot the square shape implicit in the evidence.
+% ev{i,t} is the value of node i in slice t.
+% The observed node contains a velocity (delta increment), which is converted
+% into a position.
+% The Q2 node specifies which model is used; each segment is color-coded
+% in the order red, green, blue, black.
+
+Q1 = 1; Q2 = 2; Q3 = 3; F3 = 4; F2 = 5; Onode = 6;
+
+delta = cell2num(ev(Onode,:)); % delta(:,t)
+Q2label = cell2num(ev(Q2,:)); 
+
+T = size(delta, 2);
+pos = zeros(2,T+1);
+clf
+hold on
+cols = {'r', 'g', 'b', 'k'};
+boundary = 0;
+coli = 1;
+for t=2:T+1
+  pos(:,t) = pos(:,t-1) + delta(:,t-1);
+  plot(pos(1,t), pos(2,t), sprintf('%c.', cols{coli}));
+  if t < T
+    boundary = (Q2label(t) ~= Q2label(t-1));
+  end
+  if boundary
+    coli = coli + 1;
+    coli = mod(coli-1, length(cols)) + 1;
+  end
+end
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/sample_square_hhmm.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/sample_square_hhmm.m
new file mode 100644
index 00000000..a0f9007e
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/Old/sample_square_hhmm.m
@@ -0,0 +1,160 @@
+
+seed = 0;
+rand('state', seed);
+randn('state', seed);
+
+discrete_obs = 1;
+topright = 0;
+
+Qsizes = [2 4 2];
+D = 3;
+Qnodes = 1:D;
+startprob = cell(1,D);
+transprob = cell(1,D);
+termprob = cell(1,D);
+
+% LEVEL 1
+
+startprob{1} = 'ergodic';
+transprob{1} = 'ergodic';
+
+% LEVEL 2
+
+startprob{2} = zeros(2, 4);
+startprob{2}(1, :) = [1 0 0 0];
+if topright
+  startprob{2}(2, :) = [0 0 1 0];
+else
+  startprob{2}(2, :) = [0 1 0 0];
+end
+
+transprob{2} = zeros(4, 2, 4);
+
+transprob{2}(:,1,:) = [0 1 0 0
+		       0 0 1 0
+		       0 0 0 1
+		       0 0 0 1]; % 4->e
+if topright
+  transprob{2}(:,2,:) = [0 0 0 1
+		    1 0 0 0
+		    0 1 0 0
+		    0 0 0 1]; % 4->e
+else
+  transprob{2}(:,2,:) = [0 0 0 1
+		    1 0 0 0
+		    0 0 1 0 % 3->e
+		    0 0 1 0];
+end
+
+%termprob{2} = 'rightstop';
+termprob{2} = zeros(2,4,2);
+pfin = 0.8;
+termprob{2}(1,:,2) = [0 0 0 pfin]; % finish in state 4 (DU)
+termprob{2}(1,:,1) = 1 - [0 0 0 pfin];
+if topright
+  termprob{2}(2,:,2) = [0 0 0 pfin];
+  termprob{2}(2,:,1) = 1 - [0 0 0 pfin];
+else
+  termprob{2}(2,:,2) = [0 0 pfin 0];  % finish in state 3 (RL)
+  termprob{2}(2,:,1) = 1 - [0 0 pfin 0];
+end
+
+% LEVEL 3
+
+startprob{3} = 'leftstart';
+transprob{3}  = 'leftright';
+termprob{3} = 'rightstop';
+
+
+% OBS LEVEl
+
+if discrete_obs
+  chars = ['L', 'l', 'U', 'u', 'R', 'r', 'D', 'd'];
+  L=find(chars=='L'); l=find(chars=='l');
+  U=find(chars=='U'); u=find(chars=='u');
+  R=find(chars=='R'); r=find(chars=='r');
+  D=find(chars=='D'); d=find(chars=='d');
+  Osize = length(chars);
+  
+  obsprob = zeros([4 2 Osize]);
+  %       Q2 Q3 O
+  obsprob(1, 1, L) =  1.0;
+  obsprob(1, 2, l) =  1.0;
+  obsprob(2, 1, U) =  1.0;
+  obsprob(2, 2, u) =  1.0;
+  obsprob(3, 1, R) =  1.0;
+  obsprob(3, 2, r) =  1.0;
+  obsprob(4, 1, D) =  1.0;
+  obsprob(4, 2, d) =  1.0;
+  
+  Oargs = {'CPT', obsprob};
+else
+  Osize = 2;
+  mu = zeros(2, 4, 2);
+  noise = 0;
+  scale = 10;
+  for q3=1:2
+    mu(:, 1, q3) = scale*[1;0] + noise*rand(2,1);
+  end
+  for q3=1:2
+    mu(:, 2, q3) = scale*[0;-1] + noise*rand(2,1);
+  end
+  for q3=1:2
+    mu(:, 3, q3) = scale*[-1;0] + noise*rand(2,1);
+  end
+  for q3=1:2
+    mu(:, 4, q3) = scale*[0;1] + noise*rand(2,1);
+  end
+  Sigma = repmat(reshape(0.01*eye(2), [2 2 1 1 ]), [1 1 4 2]);
+  Oargs = {'mean', mu, 'cov', Sigma};
+end
+
+bnet = mk_hhmm('Qsizes', Qsizes, 'Osize', Osize', 'discrete_obs', discrete_obs, ...
+	       'Oargs', Oargs, 'Ops', Qnodes(2:3), ...
+	       'startprob', startprob, 'transprob', transprob, 'termprob', termprob);
+
+if discrete_obs
+  Tmax = 30;
+else
+  Tmax = 200;
+end
+usecell = ~discrete_obs;
+Q1 = 1; Q2 = 2; Q3 = 3; F3 = 4; F2 = 5; Onode = 6;
+Qnodes = [Q1 Q2 Q3]; Fnodes = [F2 F3];
+
+for seqi=1:3
+  evidence = sample_dbn(bnet, Tmax, usecell, 'stop_sampling_F2');      
+  T = size(evidence, 2)
+  if discrete_obs
+    pretty_print_hhmm_parse(evidence, Qnodes, Fnodes, Onode, chars);
+  else
+    pos = zeros(2,T+1);
+    delta = cell2num(evidence(Onode,:));
+    clf
+    hold on
+    cols = {'r', 'g', 'k', 'b'};
+    boundary = cell2num(evidence(F3,:))-1;
+    coli = 1;
+    for t=2:T+1
+      pos(:,t) = pos(:,t-1) + delta(:,t-1);
+      plot(pos(1,t), pos(2,t), sprintf('%c.', cols{coli}));
+      if boundary(t-1)
+	coli = coli + 1;
+	coli = mod(coli-1, length(cols)) + 1;
+      end
+    end
+    %plot(pos(1,:), pos(2,:), '.')
+    %pretty_print_hhmm_parse(evidence, Qnodes, Fnodes, Onode, []);
+    pause
+  end
+end
+
+eclass = bnet.equiv_class;
+S=struct(bnet.CPD{eclass(Q2,2)});
+
+
+
+
+
+
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/get_square_data.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/get_square_data.m
new file mode 100644
index 00000000..9790221c
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/get_square_data.m
@@ -0,0 +1,70 @@
+% Let the user draw a square with the mouse,
+% and then click on the corners to do a manual segmentation
+
+ss = 6;
+Q1 = 1; Q2 = 2; Q3 = 3; obsvel = 6;
+CLOCKWISE = 1; ANTICLOCK = 2;
+LR = 1; UD = 2; RL = 3; DU = 4;
+
+% repeat this block manually incrementing the sequence number
+% and setting ori.
+% (since I don't know how to call getmouse as a call-return function).
+seq = 4;
+%ori = CLOCKWISE
+ori = ANTICLOCK;
+clear xpos ypos
+getmouse
+% end block
+
+% manual segmentation with the mouse
+startseg(1) = 1;
+for i=2:4
+  fprintf('click on start of segment %d\n', i);
+  [x,y] = ginput(1);
+  plot(x,y,'ro')
+  d = dist2([xpos; ypos]', [x y]);
+  startseg(i) = argmin(d);
+end
+
+% plot corners in green 
+%ti = first point in (i+1)st segment
+t1 = startseg(1); t2 = startseg(2); t3 = startseg(3); t4 = startseg(4); 
+plot(xpos(t2), ypos(t2), 'g*')
+plot(xpos(t3), ypos(t3), 'g*')
+plot(xpos(t4), ypos(t4), 'g*')
+
+
+xvel = xpos(2:end) - xpos(1:end-1);
+yvel = ypos(2:end) - ypos(1:end-1);
+speed = [xvel(:)'; yvel(:)'];
+pos_data{seq} = [xpos(:)'; ypos(:)'];
+vel_data{seq} = [xvel(:)'; yvel(:)'];
+T = length(xvel);
+Q1label{seq} = num2cell(repmat(ori, 1, T));
+Q2label{seq} = zeros(1, T);
+if ori == CLOCKWISE
+  Q2label{seq}(t1:t2) = LR;
+  Q2label{seq}(t2+1:t3) = UD;
+  Q2label{seq}(t3+1:t4) = RL;
+  Q2label{seq}(t4+1:T) = DU;
+else
+  Q2label{seq}(t1:t2) = RL;
+  Q2label{seq}(t2+1:t3) = UD;
+  Q2label{seq}(t3+1:t4) = LR;
+  Q2label{seq}(t4+1:T) = DU;
+end
+
+% pos_data{seq}(:,t), vel_data{seq}(:,t) Q1label{seq}(t) Q2label{seq}(t)
+save 'square4' pos_data vel_data Q1label Q2label
+
+nseq = 4;
+cases = cell(1,nseq);
+for seq=1:nseq
+  T = size(vel_data{seq},2);
+  ev = cell(ss,T);
+  ev(obsvel,:) = num2cell(vel_data{seq},1);
+  ev(Q1,:) = Q1label{seq};
+  ev(Q2,:) = num2cell(Q2label{seq});
+  cases{seq} = ev;
+end
+save 'square4_cases' cases 
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/hhmm_inference.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/hhmm_inference.m
new file mode 100644
index 00000000..c3bc8441
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/hhmm_inference.m
@@ -0,0 +1,13 @@
+bnet = mk_square_hhmm(1, 1);
+
+engine = {};
+engine{end+1} = hmm_inf_engine(bnet);
+engine{end+1} = smoother_engine(jtree_2TBN_inf_engine(bnet));
+
+exact = 1:length(engine);
+filter = 0;
+single = 0;
+maximize = 0;
+T = 4;
+
+[err, inf_time, engine] = cmp_inference(bnet, engine, exact, T, filter, single, maximize);
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/is_F2_true_D3.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/is_F2_true_D3.m
new file mode 100644
index 00000000..38d0b6e8
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/is_F2_true_D3.m
@@ -0,0 +1,12 @@
+function stop = is_F2_true_D3(vals)
+% function stop = is_F2_true_D3(vals)
+% 
+% If vals(F2)=2 then level 2 has finished, so we return stop=1
+% to stop sample_dbn. Otherwise we return stop=0.
+% We assume this is for a D=3 level HHMM.
+
+Q1 = 1; Q2 = 2; Q3 = 3; F3 = 4; F2 = 5; Onode = 6;
+stop = 0;
+if (iscell(vals) & vals{F2}==2) | (~iscell(vals) & vals(F2)==2)
+  stop = 1;
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/learn_square_hhmm_cts.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/learn_square_hhmm_cts.m
new file mode 100644
index 00000000..77bdaec3
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/learn_square_hhmm_cts.m
@@ -0,0 +1,152 @@
+% Try to learn a 3 level HHMM similar to mk_square_hhmm
+% from hand-drawn squares.
+
+% Because startprob should be shared for t=1:T,
+% but in the DBN is shared for t=2:T, we train using a single long sequence.
+
+discrete_obs = 0;
+supervised = 1;
+obs_finalF2 = 0;
+% It is not possible to observe F2 if we learn
+% because the update_ess method for hhmmF_CPD and hhmmQ_CPD assume
+% the F nodes are always hidden (for speed).
+% However, for generating, we might want to set the final F2=true
+% to force all subroutines to finish.
+
+seed = 1;
+rand('state', seed);
+randn('state', seed);
+
+bnet = mk_square_hhmm(discrete_obs, 0);
+ 
+ss = 6;
+Q1 = 1; Q2 = 2; Q3 = 3; F3 = 4; F2 = 5; Onode = 6;
+Qnodes = [Q1 Q2 Q3]; Fnodes = [F2 F3];
+Qsizes = [2 4 1];
+  
+if supervised
+  bnet.observed = [Q1 Q2 Onode];
+else
+  bnet.observed = [Onode];
+end
+
+if obs_finalF2
+  engine = jtree_dbn_inf_engine(bnet);
+  % can't use ndx version because sometimes F2 is hidden, sometimes observed
+  error('can''t observe F when learning')
+else
+  if supervised
+    engine = jtree_ndx_dbn_inf_engine(bnet);
+  else
+    engine = jtree_hmm_inf_engine(bnet);
+  end
+end
+
+load 'square4_cases' % cases{seq}{i,t} for i=1:ss 
+%plot_square_hhmm(cases{1})
+%long_seq = cat(2, cases{:});
+train_cases = cases(1:2);
+long_seq = cat(2, train_cases{:});
+if ~supervised
+  T = size(long_seq,2);
+  for t=1:T
+    long_seq{Q1,t} = [];
+    long_seq{Q2,t} = [];
+  end
+end
+[bnet2, LL, engine2] = learn_params_dbn_em(engine, {long_seq}, 'max_iter', 2);
+
+eclass = bnet2.equiv_class;
+CPDO=struct(bnet2.CPD{eclass(Onode,1)});
+mu = CPDO.mean;
+Sigma = CPDO.cov;
+CPDO_full = CPDO;
+
+% force diagonal covs after training
+for k=1:size(Sigma,3)
+  Sigma(:,:,k) = diag(diag(Sigma(:,:,k)));
+end
+bnet2.CPD{6} = set_fields(bnet.CPD{6}, 'cov', Sigma);
+
+if 0
+  % visualize each model by concatenating means for each model for nsteps in a row
+  nsteps = 5;
+  ev = cell(ss, nsteps*prod(Qsizes(2:3)));
+  t = 1;
+  for q2=1:Qsizes(2)
+    for q3=1:Qsizes(3)
+      for i=1:nsteps
+	ev{Onode,t} = mu(:,q2,q3);
+	ev{Q2,t} = q2;
+	t = t + 1;
+      end
+    end
+  end
+  plot_square_hhmm(ev)      
+end
+
+% bnet3 is the same as the learned model, except we will use it in testing mode
+if supervised
+  bnet3 = bnet2;
+  bnet3.observed = [Onode];
+  engine3 = hmm_inf_engine(bnet3);
+  %engine3 = jtree_ndx_dbn_inf_engine(bnet3);
+else
+  bnet3 = bnet2;
+  engine3 = engine2;
+end
+
+if 0
+  % segment whole sequence
+  mpe = calc_mpe_dbn(engine3, long_seq);
+  pretty_print_hhmm_parse(mpe, Qnodes, Fnodes, Onode, []);
+end
+
+% segment each sequence
+test_cases = cases(3:4);
+for i=1:2
+  ev = test_cases{i};
+  T = size(ev, 2);
+  for t=1:T
+    ev{Q1,t} = [];
+    ev{Q2,t} = [];
+  end
+  %mpe = calc_mpe_dbn(engine3, ev);
+  mpe = find_mpe(engine3, ev)
+  subplot(1,2,i)
+  plot_square_hhmm(mpe)      
+  %pretty_print_hhmm_parse(mpe, Qnodes, Fnodes, Onode, []);
+  q1s = cell2num(mpe(Q1,:));
+  h = hist(q1s, 1:Qsizes(1));
+  map_q1 = argmax(h);
+  str = sprintf('test seq %d is of type %d\n', i, map_q1);
+  title(str)
+end
+
+
+if 0
+% Estimate gotten by couting transitions in the labelled data
+% Note that a self transition shouldnt count if F2=off.
+Q2ev = cell2num(ev(Q2,:));
+Q2a = Q2ev(1:end-1);
+Q2b = Q2ev(2:end);
+counts = compute_counts([Q2a; Q2b], [4 4]);
+end
+
+eclass = bnet2.equiv_class;
+CPDQ1=struct(bnet2.CPD{eclass(Q1,2)});
+CPDQ2=struct(bnet2.CPD{eclass(Q2,2)});
+CPDQ3=struct(bnet2.CPD{eclass(Q3,2)});
+CPDF2=struct(bnet2.CPD{eclass(F2,1)});
+CPDF3=struct(bnet2.CPD{eclass(F3,1)});
+
+
+A=add_hhmm_end_state(CPDQ2.transprob, CPDF2.termprob(:,:,2));
+squeeze(A(:,1,:));
+CPDQ2.startprob;
+ 
+if 0
+S=struct(CPDF2.sub_CPD_term);
+S.nsamples
+reshape(S.counts, [2 4 2])
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/learn_square_hhmm_discrete.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/learn_square_hhmm_discrete.m
new file mode 100644
index 00000000..3110ae5e
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/learn_square_hhmm_discrete.m
@@ -0,0 +1,171 @@
+% Try to learn a 3 level HHMM similar to mk_square_hhmm
+% from synthetic discrete sequences
+
+
+discrete_obs = 1;
+supervised = 0;
+obs_finalF2 = 0;
+
+seed = 1;
+rand('state', seed);
+randn('state', seed);
+
+bnet_init = mk_square_hhmm(discrete_obs, 0);
+
+ss = 6;
+Q1 = 1; Q2 = 2; Q3 = 3; F3 = 4; F2 = 5; Onode = 6;
+Qnodes = [Q1 Q2 Q3]; Fnodes = [F2 F3];
+
+if supervised
+  bnet_init.observed = [Q1 Q2 Onode];
+else
+  bnet_init.observed = [Onode];
+end
+
+if obs_finalF2
+  engine_init = jtree_dbn_inf_engine(bnet_init);
+  % can't use ndx version because sometimes F2 is hidden, sometimes observed
+  error('can''t observe F when learning')
+  % It is not possible to observe F2 if we learn
+  % because the update_ess method for hhmmF_CPD and hhmmQ_CPD assume
+  % the F nodes are always hidden (for speed).
+  % However, for generating, we might want to set the final F2=true
+  % to force all subroutines to finish.
+else
+  if supervised
+    engine_init = jtree_ndx_dbn_inf_engine(bnet_init);
+  else
+    engine_init = hmm_inf_engine(bnet_init);
+  end
+end
+  
+% generate some synthetic data (easier to debug)
+chars = ['L', 'l', 'U', 'u', 'R', 'r', 'D', 'd'];
+L=find(chars=='L'); l=find(chars=='l');
+U=find(chars=='U'); u=find(chars=='u');
+R=find(chars=='R'); r=find(chars=='r');
+D=find(chars=='D'); d=find(chars=='d');
+
+cases = {};
+
+T = 8;
+ev = cell(ss, T);
+ev(Onode,:) = num2cell([L l U u R r D d]);
+if supervised
+  ev(Q1,:) = num2cell(1*ones(1,T));
+  ev(Q2,:) = num2cell( [1 1 2 2 3 3 4 4]);
+end
+cases{1} = ev;
+cases{3} = ev;
+
+T  = 8;
+ev = cell(ss, T);
+%we start with R then r, even though we are running the model 'backwards'!
+ev(Onode,:) = num2cell([R r U u L l D d]);
+
+if supervised
+  ev(Q1,:) = num2cell(2*ones(1,T));
+  ev(Q2,:) = num2cell( [3 3 2 2 1 1 4 4]);
+end
+
+cases{2} = ev;
+cases{4} = ev;
+
+if obs_finalF2
+  for i=1:length(cases)
+    T = size(cases{i},2);
+    cases{i}(F2,T)={2}; % force F2 to be finished at end of seq
+  end
+end
+
+
+% startprob should be shared for t=1:T,
+% but in the DBN it is shared for t=2:T,
+% so we train using a single long sequence.
+long_seq = cat(2, cases{:});
+[bnet_learned, LL, engine_learned] = ...
+    learn_params_dbn_em(engine_init, {long_seq}, 'max_iter', 200);
+
+% figure out which subsequence each model is responsible for
+mpe = calc_mpe_dbn(engine_learned, long_seq);
+pretty_print_hhmm_parse(mpe, Qnodes, Fnodes, Onode, chars);
+
+
+% The "true" segmentation of the training sequence  is
+% Q1: 1                 2
+% O:  L l U u R r D d | R r U u L l D d | etc.
+% 
+% When we learn in a supervised fashion, we recover the "truth".
+
+% When we learn in an unsupervised fashion with seed=1, we get
+% Q1: 2                       1
+% O:  L l U u R r D d  R r | U u L l D d | etc.
+%
+% This means for model 1:
+% starts in state 2
+% transitions 2->1, 1->4, 4->e, 3->2
+%
+% For model 2,
+% starts in state 1
+% transitions 1->2, 2->3, 3->4 or e, 4->3
+
+% examine the params
+eclass = bnet_learned.equiv_class;
+CPDQ1=struct(bnet_learned.CPD{eclass(Q1,2)});
+CPDQ2=struct(bnet_learned.CPD{eclass(Q2,2)});
+CPDQ3=struct(bnet_learned.CPD{eclass(Q3,2)});
+CPDF2=struct(bnet_learned.CPD{eclass(F2,1)});
+CPDF3=struct(bnet_learned.CPD{eclass(F3,1)});
+CPDO=struct(bnet_learned.CPD{eclass(Onode,1)});
+
+A_learned =add_hhmm_end_state(CPDQ2.transprob, CPDF2.termprob(:,:,2));
+squeeze(A_learned(:,1,:))
+squeeze(A_learned(:,2,:))
+
+
+% Does the "true" model have higher likelihood than the learned one?
+% i.e., Does the unsupervised method learn the wrong model because
+% we have the wrong cost fn, or because of local minima?
+
+bnet_true = mk_square_hhmm(discrete_obs,1);
+
+% examine the params
+eclass = bnet_learned.equiv_class;
+CPDQ1_true=struct(bnet_true.CPD{eclass(Q1,2)});
+CPDQ2_true=struct(bnet_true.CPD{eclass(Q2,2)});
+CPDQ3_true=struct(bnet_true.CPD{eclass(Q3,2)});
+CPDF2_true=struct(bnet_true.CPD{eclass(F2,1)});
+CPDF3_true=struct(bnet_true.CPD{eclass(F3,1)});
+
+A_true =add_hhmm_end_state(CPDQ2_true.transprob, CPDF2_true.termprob(:,:,2));
+squeeze(A_true(:,1,:))
+
+
+if supervised
+  engine_true = jtree_ndx_dbn_inf_engine(bnet_true);
+else
+  engine_true = hmm_inf_engine(bnet_true);
+end
+
+%[engine_learned, ll_learned] = enter_evidence(engine_learned, long_seq);
+%[engine_true, ll_true] = enter_evidence(engine_true, long_seq);
+[engine_learned, ll_learned] = enter_evidence(engine_learned, cases{2});
+[engine_true, ll_true] = enter_evidence(engine_true, cases{2});
+ll_learned
+ll_true
+
+
+% remove concatentation artefacts
+ll_learned = 0;
+ll_true = 0;
+for m=1:length(cases)
+  [engine_learned, ll_learned_tmp] = enter_evidence(engine_learned, cases{m});
+  [engine_true, ll_true_tmp] = enter_evidence(engine_true, cases{m});
+  ll_learned = ll_learned + ll_learned_tmp;
+  ll_true = ll_true + ll_true_tmp;
+end
+ll_learned
+ll_true
+
+% In both cases, ll_learned >> ll_true
+% which shows we are using the wrong cost function!
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/mk_square_hhmm.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/mk_square_hhmm.m
new file mode 100644
index 00000000..41cfc539
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/mk_square_hhmm.m
@@ -0,0 +1,180 @@
+function bnet = mk_square_hhmm(discrete_obs, true_params, topright)
+
+% Make a 3 level  HHMM described by the following grammar
+%
+% Square -> CLK | CCK % clockwise or counterclockwise
+% CLK -> LR UD RL DU start on top left (1 2 3 4)
+% CCK -> RL UD LR DU  if start at top right (3 2 1 4)
+% CCK -> UD LR DU RL if start at top left (2 1 4 3)
+%
+% LR = left-right, UD = up-down, RL = right-left, DU = down-up
+% LR, UD, RL, DU are sub HMMs.
+%
+% For discrete observations, the subHMMs are 2-state left-right.
+% LR emits L then l, etc.
+%
+% For cts observations, the subHMMs are 1 state.
+% LR emits a vector in the -> direction, with a little noise.
+% Since there is no constraint that we remain in the LR state as long as the RL state,
+% the sides of the square might have different lengths,
+% so the result is not really a square!
+%
+% If true_params = 0, we use random parameters at the top 2 levels
+% (ready for learning). At the bottom level, we use noisy versions
+% of the "true" observations.
+%
+% If topright=1, counter-clockwise starts at top right, not top left
+% This example was inspired by Ivanov and Bobick.
+
+if nargin < 3, topright = 1; end
+
+if 1 % discrete_obs
+  Qsizes = [2 4 2];
+else
+  Qsizes = [2 4 1];
+end
+
+D = 3;
+Qnodes = 1:D;
+startprob = cell(1,D);
+transprob = cell(1,D);
+termprob = cell(1,D);
+
+% LEVEL 1
+
+startprob{1} = 'unif';
+transprob{1} = 'unif';
+
+% LEVEL 2
+
+if true_params
+  startprob{2} = zeros(2, 4);
+  startprob{2}(1, :) = [1 0 0 0];
+  if topright
+    startprob{2}(2, :) = [0 0 1 0];
+  else
+    startprob{2}(2, :) = [0 1 0 0];
+  end
+  
+  transprob{2} = zeros(4, 2, 4);
+  
+  transprob{2}(:,1,:) = [0 1 0 0
+		    0 0 1 0
+		    0 0 0 1
+		    0 0 0 1]; % 4->e
+  if topright
+    transprob{2}(:,2,:) = [0 0 0 1
+		    1 0 0 0
+		    0 1 0 0
+		    0 0 0 1]; % 4->e
+  else
+    transprob{2}(:,2,:) = [0 0 0 1
+		    1 0 0 0
+		    0 0 1 0 % 3->e
+		    0 0 1 0];
+  end
+  
+  %termprob{2} = 'rightstop';
+  termprob{2} = zeros(2,4);
+  pfin = 0.8;
+  termprob{2}(1,:) = [0 0 0 pfin]; % finish in state 4 (DU)
+  if topright
+    termprob{2}(2,:) = [0 0 0 pfin];
+  else
+    termprob{2}(2,:) = [0 0 pfin 0];  % finish in state 3 (RL)
+  end
+else
+  % In the unsupervised case, it is essential that we break symmetry
+  % in the initial param estimates.
+  %startprob{2} = 'unif';
+  %transprob{2} = 'unif';
+  %termprob{2} = 'unif';
+  startprob{2} = 'rnd';
+  transprob{2} = 'rnd';
+  termprob{2} = 'rnd';
+end
+
+% LEVEL 3
+
+if 1 |  true_params
+  startprob{3} = 'leftstart';
+  transprob{3}  = 'leftright';
+  termprob{3} = 'rightstop';
+else
+  % If we want to be able to run a base-level model backwards...
+  startprob{3} = 'rnd';
+  transprob{3}  = 'rnd';
+  termprob{3} = 'rnd';
+end
+ 
+
+% OBS LEVEl
+
+if discrete_obs
+  % Initialise observations of lowest level primitives in a way which we can interpret
+  chars = ['L', 'l', 'U', 'u', 'R', 'r', 'D', 'd'];
+  L=find(chars=='L'); l=find(chars=='l');
+  U=find(chars=='U'); u=find(chars=='u');
+  R=find(chars=='R'); r=find(chars=='r');
+  D=find(chars=='D'); d=find(chars=='d');
+  Osize = length(chars);
+  
+  if true_params
+    p = 1; % makes each state fully observed
+  else
+    p = 0.9;
+  end
+  
+  obsprob = (1-p)*ones([4 2 Osize]);
+  %       Q2 Q3 O
+  obsprob(1, 1, L) =  p;
+  obsprob(1, 2, l) =  p;
+  obsprob(2, 1, U) =  p;
+  obsprob(2, 2, u) =  p;
+  obsprob(3, 1, R) =  p;
+  obsprob(3, 2, r) =  p;
+  obsprob(4, 1, D) =  p;
+  obsprob(4, 2, d) =  p;
+  obsprob = mk_stochastic(obsprob);
+  Oargs = {'CPT', obsprob};
+else
+  % Initialise means of lowest level primitives in a way which we can interpret
+  % These means are little vectors in the east, south, west, north directions.
+  % (left-right=east, up-down=south, right-left=west, down-up=north)
+  Osize = 2;
+  mu = zeros(2, Qsizes(2), Qsizes(3));
+  scale = 3;
+  if true_params
+    noise = 0;
+  else
+    noise = 0.5*scale;
+  end
+  for q3=1:Qsizes(3)
+    mu(:, 1, q3) = scale*[1;0] + noise*rand(2,1);
+  end
+  for q3=1:Qsizes(3)
+    mu(:, 2, q3) = scale*[0;-1] + noise*rand(2,1);
+  end
+  for q3=1:Qsizes(3)
+    mu(:, 3, q3) = scale*[-1;0] + noise*rand(2,1);
+  end
+  for q3=1:Qsizes(3)
+    mu(:, 4, q3) = scale*[0;1] + noise*rand(2,1);
+  end
+  Sigma = repmat(reshape(scale*eye(2), [2 2 1 1 ]), [1 1 Qsizes(2) Qsizes(3)]);
+  Oargs = {'mean', mu, 'cov', Sigma, 'cov_type', 'diag'};
+end
+
+if discrete_obs
+  selfprob = 0.5;
+else
+  selfprob = 0.95;
+  % If less than this, it won't look like a square
+  % because it doesn't spend enough time in each state
+  % Unfortunately, the variance on durations (lengths of each side)
+  % is very large
+end
+bnet = mk_hhmm('Qsizes', Qsizes, 'Osize', Osize', 'discrete_obs', discrete_obs, ...
+	       'Oargs', Oargs, 'Ops', Qnodes(2:3), 'selfprob', selfprob, ...
+	       'startprob', startprob, 'transprob', transprob, 'termprob', termprob);
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/plot_square_hhmm.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/plot_square_hhmm.m
new file mode 100644
index 00000000..e61e5669
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/plot_square_hhmm.m
@@ -0,0 +1,27 @@
+function plot_square_hhmm(ev)
+% Plot the square shape implicit in the evidence.
+% ev{i,t} is the value of node i in slice t.
+% The observed node contains a velocity (delta increment), which is converted
+% into a position.
+% The Q2 node specifies which model is used, and hence which color
+% to use: 1=red, 2=green, 3=blue, 4=black.
+
+Q1 = 1; Q2 = 2; Q3 = 3; F3 = 4; F2 = 5; Onode = 6;
+
+delta = cell2num(ev(Onode,:)); % delta(:,t)
+Q2label = cell2num(ev(Q2,:)); 
+
+T = size(delta, 2);
+pos = zeros(2,T+1);
+hold on
+cols = {'r', 'g', 'b', 'k'};
+for t=2:T+1
+  pos(:,t) = pos(:,t-1) + delta(:,t-1);
+  plot(pos(1,t), pos(2,t), sprintf('%c.', cols{Q2label(t-1)}));
+  if (t==2)
+    text(pos(1,t-1),pos(2,t-1),sprintf('%d',t))
+  elseif (mod(t,20)==0)
+    text(pos(1,t),pos(2,t),sprintf('%d',t))
+  end
+end
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/sample_square_hhmm_cts.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/sample_square_hhmm_cts.m
new file mode 100644
index 00000000..3ab2abb5
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/sample_square_hhmm_cts.m
@@ -0,0 +1,20 @@
+% Generate samples from the HHMM with the true params.
+
+seed = 1;
+rand('state', seed);
+randn('state', seed);
+
+discrete_obs = 0;
+
+bnet = mk_square_hhmm(discrete_obs, 1);
+Q1 = 1; Q2 = 2; Q3 = 3; F3 = 4; F2 = 5; Onode = 6;
+Qnodes = [Q1 Q2 Q3]; Fnodes = [F2 F3];
+
+for seqi=1:1
+  evidence = sample_dbn(bnet, 'stop_test', 'is_F2_true_D3');      
+  clf
+  plot_square_hhmm(evidence);
+  %pretty_print_hhmm_parse(evidence, Qnodes, Fnodes, Onode, []);
+  fprintf('sequence %d has length %d; press key to continue\n', seqi, size(evidence,2))
+  pause
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/sample_square_hhmm_discrete.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/sample_square_hhmm_discrete.m
new file mode 100644
index 00000000..20279899
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/sample_square_hhmm_discrete.m
@@ -0,0 +1,20 @@
+% Generate samples from the HHMM with the true params.
+
+seed = 0;
+rand('state', seed);
+randn('state', seed);
+
+discrete_obs = 1;
+
+bnet = mk_square_hhmm(discrete_obs, 1);
+
+Tmax = 30;
+Q1 = 1; Q2 = 2; Q3 = 3; F3 = 4; F2 = 5; Onode = 6;
+Qnodes = [Q1 Q2 Q3]; Fnodes = [F2 F3];
+chars = ['L', 'l', 'U', 'u', 'R', 'r', 'D', 'd'];
+  
+for seqi=1:3
+  evidence = cell2num(sample_dbn(bnet, 'stop_test', 'is_F2_true_D3'));
+  T = size(evidence, 2)
+  pretty_print_hhmm_parse(evidence, Qnodes, Fnodes, Onode, chars);
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/square4.mat b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/square4.mat
new file mode 100644
index 00000000..cda0585b
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/square4.mat
Binary files differdiff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/square4_cases.mat b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/square4_cases.mat
new file mode 100644
index 00000000..788c3239
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/square4_cases.mat
Binary files differdiff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/test_square_fig.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/test_square_fig.m
new file mode 100644
index 00000000..e983af14
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/test_square_fig.m
@@ -0,0 +1,1310 @@
+function fig = test_square_fig()
+% This is the machine-generated representation of a Handle Graphics object
+% and its children.  Note that handle values may change when these objects
+% are re-created. This may cause problems with any callbacks written to
+% depend on the value of the handle at the time the object was saved.
+%
+% To reopen this object, just type the name of the M-file at the MATLAB
+% prompt. The M-file and its associated MAT-file must be on your path.
+
+load test_square_fig
+
+h0 = figure('Color',[0.8 0.8 0.8], ...
+	'Colormap',mat0, ...
+	'PointerShapeCData',mat1, ...
+	'Position',[540 374 476 292]);
+h1 = axes('Parent',h0, ...
+	'CameraUpVector',[0 1 0], ...
+	'Color',[1 1 1], ...
+	'ColorOrder',mat2, ...
+	'NextPlot','add', ...
+	'Position',[0.13 0.11 0.3270231213872832 0.8149999999999998], ...
+	'XColor',[0 0 0], ...
+	'XLim',[-10 50], ...
+	'XLimMode','manual', ...
+	'YColor',[0 0 0], ...
+	'YLim',[-60 10], ...
+	'YLimMode','manual', ...
+	'ZColor',[0 0 0]);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',0.4608294930875587, ...
+	'YData',0.2923976608187218);
+h2 = text('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'String','2');
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',1.152073732718893, ...
+	'YData',0.2923976608187218);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',2.995391705069125, ...
+	'YData',0.8771929824561511);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',3.686635944700463, ...
+	'YData',0.8771929824561511);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',6.451612903225808, ...
+	'YData',0.8771929824561511);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',9.677419354838712, ...
+	'YData',1.461988304093566);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',10.36866359447005, ...
+	'YData',1.461988304093566);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',15.43778801843318, ...
+	'YData',2.046783625730996);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',17.51152073732719, ...
+	'YData',2.046783625730996);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',19.81566820276498, ...
+	'YData',2.046783625730996);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',20.50691244239631, ...
+	'YData',2.046783625730996);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',23.73271889400922, ...
+	'YData',2.046783625730996);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',25.57603686635945, ...
+	'YData',2.046783625730996);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',29.95391705069125, ...
+	'YData',2.046783625730996);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',31.79723502304147, ...
+	'YData',2.046783625730996);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',35.02304147465438, ...
+	'YData',2.046783625730996);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',35.71428571428572, ...
+	'YData',2.046783625730996);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',38.47926267281106, ...
+	'YData',1.461988304093566);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',40.3225806451613, ...
+	'YData',1.461988304093566);
+h2 = text('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'Position',[40.3225806451613 1.461988304093566 0], ...
+	'String','20');
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',42.62672811059908, ...
+	'YData',mat3);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',43.31797235023042, ...
+	'YData',mat4);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',43.31797235023042, ...
+	'YData',0.8771929824561511);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',43.54838709677419, ...
+	'YData',0);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',43.77880184331798, ...
+	'YData',-0.5847953216374293);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',44.47004608294931, ...
+	'YData',-2.339181286549703);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',44.93087557603687, ...
+	'YData',-4.385964912280699);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',46.7741935483871, ...
+	'YData',-9.064327485380119);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',47.00460829493088, ...
+	'YData',-10.81871345029239);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',47.69585253456221, ...
+	'YData',mat5);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',47.69585253456221, ...
+	'YData',-15.20467836257309);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',47.23502304147466, ...
+	'YData',-19.00584795321637);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',47.23502304147466, ...
+	'YData',-19.88304093567251);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',47.23502304147466, ...
+	'YData',-22.51461988304093);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',47.23502304147466, ...
+	'YData',-23.09941520467836);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',47.23502304147466, ...
+	'YData',-26.02339181286549);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',47.23502304147466, ...
+	'YData',-26.31578947368421);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',47.23502304147466, ...
+	'YData',-27.77777777777777);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',47.23502304147466, ...
+	'YData',-28.3625730994152);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',47.23502304147466, ...
+	'YData',-30.99415204678362);
+h2 = text('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'Position',[47.23502304147466 -30.99415204678362 0], ...
+	'String','40');
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',47.46543778801843, ...
+	'YData',-31.57894736842105);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',47.46543778801843, ...
+	'YData',-33.62573099415204);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',47.46543778801843, ...
+	'YData',-34.50292397660818);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',47.46543778801843, ...
+	'YData',-37.42690058479531);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',47.46543778801843, ...
+	'YData',-38.01169590643274);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',47.00460829493088, ...
+	'YData',-42.39766081871344);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',47.00460829493088, ...
+	'YData',-42.98245614035087);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',47.00460829493088, ...
+	'YData',-46.49122807017543);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',46.7741935483871, ...
+	'YData',-46.78362573099415);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',46.54377880184332, ...
+	'YData',-49.41520467836257);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',46.54377880184332, ...
+	'YData',-49.70760233918128);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',45.85253456221199, ...
+	'YData',-51.46198830409356);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',45.85253456221199, ...
+	'YData',-51.75438596491227);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',44.93087557603687, ...
+	'YData',-53.21637426900584);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',44.70046082949308, ...
+	'YData',-53.21637426900584);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',44.00921658986175, ...
+	'YData',-54.09356725146198);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',43.77880184331798, ...
+	'YData',-54.38596491228069);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',41.93548387096774, ...
+	'YData',-54.97076023391811);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',41.47465437788019, ...
+	'YData',-55.26315789473683);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',39.1705069124424, ...
+	'YData',-55.55555555555554);
+h2 = text('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'Position',[39.1705069124424 -55.55555555555554 0], ...
+	'String','60');
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',38.94009216589862, ...
+	'YData',-55.84795321637426);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',36.63594470046083, ...
+	'YData',-55.55555555555554);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',36.17511520737327, ...
+	'YData',-55.55555555555554);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',32.94930875576037, ...
+	'YData',-54.97076023391811);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',32.48847926267281, ...
+	'YData',-54.97076023391811);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',28.11059907834102, ...
+	'YData',-53.80116959064326);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',27.64976958525346, ...
+	'YData',-53.50877192982455);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',23.963133640553, ...
+	'YData',-53.50877192982455);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',23.27188940092166, ...
+	'YData',-53.50877192982455);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',19.5852534562212, ...
+	'YData',-54.97076023391811);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',19.12442396313364, ...
+	'YData',-54.97076023391811);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',mat6, ...
+	'YData',-56.14035087719297);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',mat7, ...
+	'YData',-56.14035087719297);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',9.907834101382491, ...
+	'YData',-57.30994152046782);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',9.447004608294932, ...
+	'YData',-57.30994152046782);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',6.221198156682029, ...
+	'YData',-57.30994152046782);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',4.838709677419356, ...
+	'YData',-56.7251461988304);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',2.764976958525345, ...
+	'YData',-56.14035087719297);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',2.534562211981569, ...
+	'YData',-56.14035087719297);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',0.9216589861751174, ...
+	'YData',-53.80116959064327);
+h2 = text('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'Position',[0.9216589861751174 -53.80116959064327 0], ...
+	'String','80');
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',0.6912442396313381, ...
+	'YData',-53.21637426900584);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-1.152073732718893, ...
+	'YData',-48.24561403508771);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-1.152073732718893, ...
+	'YData',-47.953216374269);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-1.843317972350228, ...
+	'YData',-44.73684210526315);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-1.843317972350228, ...
+	'YData',-44.44444444444444);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-2.304147465437787, ...
+	'YData',-39.76608187134502);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-2.764976958525345, ...
+	'YData',-38.01169590643274);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-3.225806451612904, ...
+	'YData',-30.99415204678362);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-3.225806451612904, ...
+	'YData',-29.82456140350877);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-3.225806451612904, ...
+	'YData',-24.85380116959064);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-3.225806451612904, ...
+	'YData',-24.26900584795321);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-2.534562211981566, ...
+	'YData',-17.5438596491228);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-2.304147465437787, ...
+	'YData',-16.95906432748537);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-1.612903225806452, ...
+	'YData',-11.98830409356725);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-1.612903225806452, ...
+	'YData',-11.40350877192982);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',mat8, ...
+	'YData',-8.47953216374269);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',mat9, ...
+	'YData',-8.187134502923968);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-1.152073732718893, ...
+	'YData',-5.263157894736835);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-1.152073732718893, ...
+	'YData',-4.970760233918128);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-0.9216589861751139, ...
+	'YData',-2.923976608187132);
+h2 = text('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'Position',[-0.9216589861751139 -2.923976608187132 0], ...
+	'String','100');
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-0.9216589861751139, ...
+	'YData',-2.631578947368411);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-0.6912442396313345, ...
+	'YData',mat10);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-0.6912442396313345, ...
+	'YData',-0.8771929824561369);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-0.6912442396313345, ...
+	'YData',-0.5847953216374293);
+h2 = text('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'HandleVisibility','off', ...
+	'HorizontalAlignment','center', ...
+	'Position',[19.80645161290322 12.0675105485232 17.32050807568877], ...
+	'VerticalAlignment','bottom');
+set(get(h2,'Parent'),'Title',h2);
+h1 = axes('Parent',h0, ...
+	'CameraUpVector',[0 1 0], ...
+	'Color',[1 1 1], ...
+	'ColorOrder',mat11, ...
+	'NextPlot','add', ...
+	'Position',[0.5779768786127169 0.11 0.3270231213872832 0.8149999999999998], ...
+	'XColor',[0 0 0], ...
+	'YColor',[0 0 0], ...
+	'ZColor',[0 0 0]);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-0.4608294930875587, ...
+	'YData',0);
+h2 = text('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'String','2');
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-2.764976958525345, ...
+	'YData',-0.2923976608187076);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-3.456221198156683, ...
+	'YData',-0.2923976608187076);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-7.834101382488477, ...
+	'YData',-0.2923976608187076);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-11.52073732718894, ...
+	'YData',-0.2923976608187076);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',mat12, ...
+	'YData',-0.2923976608187076);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-19.35483870967742, ...
+	'YData',0.2923976608187076);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-23.50230414746544, ...
+	'YData',0.2923976608187076);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-24.88479262672811, ...
+	'YData',0.8771929824561369);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-28.11059907834102, ...
+	'YData',0.8771929824561369);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-29.49308755760369, ...
+	'YData',1.461988304093566);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-31.10599078341014, ...
+	'YData',1.461988304093566);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-32.02764976958525, ...
+	'YData',1.461988304093566);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-33.17972350230414, ...
+	'YData',1.461988304093566);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-33.6405529953917, ...
+	'YData',1.461988304093566);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 1], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-34.7926267281106, ...
+	'YData',1.461988304093566);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-35.02304147465438, ...
+	'YData',1.461988304093566);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-35.48387096774194, ...
+	'YData',1.461988304093566);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-35.71428571428572, ...
+	'YData',1.461988304093566);
+h2 = text('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'Position',[-35.71428571428572 1.461988304093566 0], ...
+	'String','20');
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-36.17511520737327, ...
+	'YData',mat13);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-36.40552995391705, ...
+	'YData',0.8771929824561369);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-36.63594470046083, ...
+	'YData',0.2923976608187076);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-36.63594470046083, ...
+	'YData',0);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-36.63594470046083, ...
+	'YData',mat14);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-36.40552995391705, ...
+	'YData',-2.339181286549703);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-36.40552995391705, ...
+	'YData',-2.631578947368425);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-36.40552995391705, ...
+	'YData',-4.67836257309942);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-36.40552995391705, ...
+	'YData',-5.555555555555557);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-36.40552995391705, ...
+	'YData',-8.187134502923982);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-36.40552995391705, ...
+	'YData',-8.771929824561397);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-36.86635944700461, ...
+	'YData',-13.15789473684211);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.09677419354839, ...
+	'YData',mat15);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.09677419354839, ...
+	'YData',-16.08187134502924);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.09677419354839, ...
+	'YData',-17.54385964912281);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.09677419354839, ...
+	'YData',-18.12865497076023);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.32718894009217, ...
+	'YData',-19.88304093567251);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.32718894009217, ...
+	'YData',-20.17543859649123);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.09677419354839, ...
+	'YData',-21.92982456140351);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.09677419354839, ...
+	'YData',-22.22222222222222);
+h2 = text('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'Position',[-37.09677419354839 -22.22222222222222 0], ...
+	'String','40');
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.09677419354839, ...
+	'YData',-23.09941520467836);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.09677419354839, ...
+	'YData',-23.39181286549707);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.32718894009217, ...
+	'YData',-25.14619883040935);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.32718894009217, ...
+	'YData',-25.43859649122807);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.32718894009217, ...
+	'YData',-28.3625730994152);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.55760368663595, ...
+	'YData',-28.94736842105263);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.78801843317973, ...
+	'YData',-31.87134502923976);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.78801843317973, ...
+	'YData',-32.16374269005848);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.78801843317973, ...
+	'YData',-34.7953216374269);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.78801843317973, ...
+	'YData',-35.38011695906432);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.78801843317973, ...
+	'YData',-38.88888888888889);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.78801843317973, ...
+	'YData',-39.76608187134503);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.78801843317973, ...
+	'YData',-43.27485380116958);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.78801843317973, ...
+	'YData',-43.5672514619883);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.78801843317973, ...
+	'YData',-44.44444444444444);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.55760368663595, ...
+	'YData',-45.32163742690058);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.55760368663595, ...
+	'YData',-45.61403508771929);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.32718894009217, ...
+	'YData',-47.36842105263158);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-37.32718894009217, ...
+	'YData',-47.95321637426901);
+h2 = line('Parent',h1, ...
+	'Color',[0 1 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-36.86635944700461, ...
+	'YData',-49.70760233918129);
+h2 = text('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'Position',[-36.86635944700461 -49.70760233918129 0], ...
+	'String','60');
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-36.86635944700461, ...
+	'YData',-50);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-35.71428571428572, ...
+	'YData',-50.29239766081872);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-35.25345622119816, ...
+	'YData',-50.29239766081872);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-32.02764976958527, ...
+	'YData',-50.29239766081872);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-31.33640552995393, ...
+	'YData',-50.29239766081872);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-27.88018433179725, ...
+	'YData',-50.58479532163743);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-27.41935483870969, ...
+	'YData',-50.58479532163743);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-18.20276497695854, ...
+	'YData',-50.58479532163743);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-16.82027649769586, ...
+	'YData',-51.16959064327486);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-12.21198156682029, ...
+	'YData',-50.58479532163743);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-11.52073732718895, ...
+	'YData',-50.58479532163743);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-6.912442396313377, ...
+	'YData',-51.16959064327486);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-5.069124423963142, ...
+	'YData',-51.75438596491229);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',mat16, ...
+	'YData',-52.046783625731);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',-0.9216589861751281, ...
+	'YData',-52.33918128654972);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',0.2304147465437687, ...
+	'YData',-52.33918128654972);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',0.4608294930875481, ...
+	'YData',-52.33918128654972);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',2.304147465437776, ...
+	'YData',-52.63157894736843);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',2.534562211981548, ...
+	'YData',-52.63157894736843);
+h2 = line('Parent',h1, ...
+	'Color',[1 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',3.917050691244224, ...
+	'YData',-52.63157894736843);
+h2 = text('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'Position',[3.917050691244224 -52.63157894736843 0], ...
+	'String','80');
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',4.147465437788011, ...
+	'YData',-52.63157894736843);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',4.147465437788011, ...
+	'YData',-52.33918128654972);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',5.529953917050673, ...
+	'YData',-46.19883040935674);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',5.990783410138231, ...
+	'YData',-44.44444444444446);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',7.834101382488466, ...
+	'YData',-28.0701754385965);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',8.294930875576025, ...
+	'YData',-22.80701754385966);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',8.755760368663584, ...
+	'YData',mat17);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',8.525345622119797, ...
+	'YData',-14.9122807017544);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',7.373271889400908, ...
+	'YData',-10.23391812865498);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',7.142857142857135, ...
+	'YData',-9.94152046783627);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',6.221198156682018, ...
+	'YData',-7.602339181286567);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',6.221198156682018, ...
+	'YData',-7.309941520467845);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',5.760368663594459, ...
+	'YData',-5.555555555555571);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',5.529953917050673, ...
+	'YData',-5.555555555555571);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',5.2995391705069, ...
+	'YData',-4.093567251462005);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',5.069124423963128, ...
+	'YData',-2.631578947368439);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',5.069124423963128, ...
+	'YData',-2.339181286549717);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',5.069124423963128, ...
+	'YData',mat18);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',5.069124423963128, ...
+	'YData',-1.169590643274873);
+h2 = line('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'LineStyle','none', ...
+	'Marker','.', ...
+	'XData',4.838709677419342, ...
+	'YData',-0.2923976608187218);
+h2 = text('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'Position',[4.838709677419342 -0.2923976608187218 0], ...
+	'String','100');
+h2 = text('Parent',h1, ...
+	'Color',[0 0 0], ...
+	'HandleVisibility','off', ...
+	'HorizontalAlignment','center', ...
+	'Position',[-10.38961038961038 12.0675105485232 17.32050807568877], ...
+	'VerticalAlignment','bottom');
+set(get(h2,'Parent'),'Title',h2);
+if nargout > 0, fig = h0; end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/test_square_fig.mat b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/test_square_fig.mat
new file mode 100644
index 00000000..5b2b5f53
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Square/test_square_fig.mat
Binary files differdiff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/abcd_hhmm.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/abcd_hhmm.m
new file mode 100644
index 00000000..13e6d39f
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/abcd_hhmm.m
@@ -0,0 +1,97 @@
+% Make the HHMM in Figure 1 of the NIPS'01 paper
+
+Qsize = [2 3 2];
+Qnodes = 1:3;
+D = 3;
+transprob = cell(1,D);
+termprob = cell(1,D);
+startprob = cell(1,D);
+clear A;
+
+% transprob{d}(i,k,j), transprob{1}(i,j)
+% termprob{d}(k,j), termprob{1}(1,j)
+% startprob{d}(k,j), startprob{1}(1,j)
+
+
+% LEVEL 1
+
+%       1 2 e
+A{1} = [0 0 1;
+	0 0 1];
+[transprob{1}, termprob{1}] = remove_hhmm_end_state(A{1});
+startprob{1} = [0.5 0.5];
+
+% LEVEL 2
+A{2} = zeros(Qsize(2), Qsize(1), Qsize(2)+1);
+
+%              1 2 3 e
+A{2}(:,1,:) = [0 1 0 0  % Q1=1 => model below state 0
+	       0 0 1 0
+	       0 0 0 1];
+
+%              1 2 3 e
+A{2}(:,2,:) = [0 1 0 0 % Q1=2 => model below state 1
+	       0 0 1 0
+	       0 0 0 1];
+
+[transprob{2}, termprob{2}] = remove_hhmm_end_state(A{2});	       
+
+% always enter level 2 in state 1
+startprob{2} = [1 0 0
+		1 0 0];
+
+% LEVEL 3
+
+A{3} = zeros([Qsize(3) Qsize(2) Qsize(3)+1]);
+endstate = Qsize(3)+1;
+%    Qt-1(3) Qt(2) Qt(3)
+%                        1   2   e
+A{3}(1,      1,    endstate) = 1.0; % Q2=1 => model below state 2/5
+A{3}(:,      2,    :) = [0.0 1.0 0.0 % Q2=2 => model below state 3/6
+            	         0.5 0.0 0.5]; 
+A{3}(1,      3,    endstate) = 1.0; % Q2=3 => model below state 4/7
+
+[transprob{3}, termprob{3}] = remove_hhmm_end_state(A{3});	       
+
+startprob{3} = 'leftstart';
+
+
+
+% OBS LEVEl
+
+chars = ['a', 'b', 'c', 'd', 'x', 'y'];
+Osize = length(chars);
+
+obsprob = zeros([Qsize Osize]);
+%       1 2 3 O
+obsprob(1,1,1,find(chars == 'a')) =  1.0;
+
+obsprob(1,2,1,find(chars == 'x')) =  1.0;
+obsprob(1,2,2,find(chars == 'y')) =  1.0;
+
+obsprob(1,3,1,find(chars == 'b')) =  1.0;
+
+obsprob(2,1,1,find(chars == 'c')) =  1.0;
+
+obsprob(2,2,1,find(chars == 'x')) =  1.0;
+obsprob(2,2,2,find(chars == 'y')) =  1.0;
+
+obsprob(2,3,1,find(chars == 'd')) =  1.0;
+
+Oargs = {'CPT', obsprob};
+
+bnet = mk_hhmm('Qsizes', Qsize, 'Osize', Osize, 'discrete_obs', 1, ...
+	       'Oargs', Oargs, 'Ops', Qnodes(1:3), ...
+	       'startprob', startprob, 'transprob', transprob, 'termprob', termprob);
+
+
+Q1 = 1; Q2 = 2; Q3 = 3; F3 = 4; F2 = 5; Onode = 6;
+Qnodes = [Q1 Q2 Q3]; Fnodes = [F2 F3];
+
+for seqi=1:3
+  evidence = sample_dbn(bnet, 'stop_test', 'is_F2_true_D3');      
+  ev = cell2num(evidence);
+  chars(ev(end,:))
+  %T = size(evidence, 2)
+  %pretty_print_hhmm_parse(evidence, Qnodes, Fnodes, Onode, chars);
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/add_hhmm_end_state.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/add_hhmm_end_state.m
new file mode 100644
index 00000000..84c3c653
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/add_hhmm_end_state.m
@@ -0,0 +1,34 @@
+function A = add_hhmm_end_state(transprob, termprob)
+% ADD_HMM_END_STATE Combine trans and term probs into transmat for automaton with an end state
+% function A = add_hhmm_end_state(transprob, termprob)
+%
+% A(i,k,j) = Pr( i->j | Qps=k), where i in 1:Q, j in 1:(Q+1), and Q+1 is the end state
+% This implements the equation in sec 4.6 of my tech report, where
+% transprob(i,k,j) = \tilde{A}_k(i,j), termprob(k,j) = \tau_k(j)
+%
+% For the top level, the k index is missing.
+
+Q = size(transprob,1);
+toplevel = (ndims(transprob)==2);
+if toplevel
+  Qk = 1;
+  transprob = reshape(transprob, [Q 1 Q]);
+  termprob = reshape(termprob, [1 Q]);
+else
+  Qk = size(transprob, 2);
+end
+
+A = zeros(Q, Qk, Q+1);
+A(:,:,Q+1) = termprob';
+
+for k=1:Qk
+  for i=1:Q
+    for j=1:Q
+      A(i,k,j) = transprob(i,k,j) * (1-termprob(k,i));
+    end
+  end    
+end
+
+if toplevel
+  A = squeeze(A);
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/hhmm_jtree_clqs.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/hhmm_jtree_clqs.m
new file mode 100644
index 00000000..4192af11
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/hhmm_jtree_clqs.m
@@ -0,0 +1,143 @@
+% Find out how big the cliques are in an HHMM as a function of depth
+% (This is how we get the complexity bound of O(D K^{1.5D}).)
+
+if 0
+Qsize = [];
+Fsize = [];
+Nclqs = [];
+end
+
+ds = 1:15;
+
+for d = ds
+  allQ = 1;
+  [intra, inter, Qnodes, Fnodes, Onode] = mk_hhmm_topo(d, allQ);
+  
+  N = length(intra);
+  ns = 2*ones(1,N);
+  
+  bnet = mk_dbn(intra, inter, ns);
+  for i=1:N
+    bnet.CPD{i} = tabular_CPD(bnet, i);
+  end
+  
+  if 0
+    T = 5;
+    dag = unroll_dbn_topology(intra, inter, T);
+    engine = jtree_unrolled_dbn_inf_engine(bnet, T, 'constrained', 1);
+    S = struct(engine);
+    S1 = struct(S.sub_engine);
+  end
+  
+  engine = jtree_dbn_inf_engine(bnet);
+  S = struct(engine);
+  J = S.jtree_struct;
+  
+  ss = 2*d+1;
+  Qnodes2 = Qnodes + ss;
+  QQnodes = [Qnodes Qnodes2];
+  
+  % find out how many Q nodes in each clique, and how many F nodes
+  C = length(J.cliques);
+  Nclqs(d) = 0;
+  for c=1:C
+    Qsize(c,d) = length(myintersect(J.cliques{c}, QQnodes));
+    Fsize(c,d) = length(myintersect(J.cliques{c}, Fnodes));
+    if length(J.cliques{c}) > 1 % exclude observed leaves
+      Nclqs(d) = Nclqs(d) + 1;
+    end
+  end
+  %pred_max_Qsize(d) = ceil(d+(d+1)/2);
+  pred_max_Qsize(d) = ceil(1.5*d);
+  
+  fprintf('d=%d\n', d);
+  %fprintf('D=%d, max F = %d. max Q = %d, pred max Q = %d\n', ...
+	%  D, max(Fsize), max(Qsize), ceil(D+(D+1)/2));
+	     
+  %histc(Qsize,1:max(Qsize)) % how many of each size?
+end % next d
+
+
+Q = 2;
+pred_mass = ds.*(Q.^ds) + Q.^(ceil(1.5 * ds))
+pred_mass2 = Q.^(ceil(1.5 * ds))
+
+for d=ds
+  mass(d) = 0;
+  for c=1:C
+    mass(d) = mass(d) + Q^Qsize(c,d);
+  end
+end
+    
+
+if 0
+%plot(ds, max(Qsize), 'o-',  ds, pred_max_Qsize, '*--');
+%plot(ds, max(Qsize), 'o-',  ds, 1.5*ds, '*--');
+%plot(ds, mass, 'o-',  ds, pred_mass, '*--');
+D = 15;
+%plot(ds(1:D), mass(1:D), 'bo-',  ds(1:D), pred_mass(1:D), 'g*--', ds(1:D), pred_mass2(1:D), 'k+-.');
+plot(ds(1:D), log(mass(1:D)), 'bo-',  ds(1:D), log(pred_mass(1:D)), 'g*--', ds(1:D), log(pred_mass2(1:D)), 'k+-.');
+
+grid on
+xlabel('depth of hierarchy')
+title('max num Q nodes in any clique vs. depth')
+legend('actual', 'predicted')
+
+%previewfig(gcf, 'width', 3, 'height', 1.5, 'color', 'bw');
+%exportfig(gcf, '/home/cs/murphyk/WP/ConferencePapers/HHMM/clqsize2.eps', ...
+%          'width', 3, 'height', 1.5, 'color', 'bw');   
+
+end
+
+
+if 0
+for d=ds
+  effnumclqs(d) = length(find(Qsize(:,d)>0));
+end
+ds = 1:10;
+Qs = 2:10;
+maxC = size(Qsize, 1);
+cost = [];
+cost_bound = [];
+for qi=1:length(Qs)
+  Q = Qs(qi);
+  for d=ds
+    cost(d,qi) = 0;
+    for c=1:maxC
+      if length(Qsize(c,d) > 0) % this clique contains Q nodes
+	cost(d,qi) = cost(d,qi) + Q^Qsize(c,d)*2^Fsize(c,d);
+      end
+    end
+    %cost_bound(d,qi) = effnumclqs(d) * 8 * Q^(max(Qsize(:,d)));
+    cost_bound(d,qi) = (effnumclqs(d)*8) + Q^(max(Qsize(:,d)));
+  end
+end
+
+qi=2; plot(ds, cost(:,qi), 'o-',  ds, cost_bound(:,qi), '*--');
+end
+
+
+if 0
+% convert numbers in cliques into names
+for d=1:D
+  Fdecode(Fnodes(d)) = d;
+end
+for c=8:15
+  clqs = J.cliques{c};
+  fprintf('clique %d: ', c);
+  for k=clqs
+    if myismember(k, Qnodes)
+      fprintf('Q%d ', k)
+    elseif myismember(k, Fnodes)
+      fprintf('F%d ', Fdecode(k))
+    elseif isequal(k, Onode)
+      fprintf('O ')
+    elseif myismember(k, Qnodes2)
+      fprintf('Q%d* ', k-ss)
+    else
+      error(['unrecognized node ' k])
+    end
+  end
+  fprintf('\n');
+end
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/mk_hhmm.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/mk_hhmm.m
new file mode 100644
index 00000000..85ff7f6a
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/mk_hhmm.m
@@ -0,0 +1,258 @@
+function [bnet, Qnodes, Fnodes, Onode] = mk_hhmm(varargin)
+% MK_HHMM Make a Hierarchical HMM
+% function [bnet, Qnodes, Fnodes, Onode] = mk_hhmm(...)
+%
+% e.g. 3-layer hierarchical HMM where level 1 only connects to level 2
+% and the parents of the observed node are levels 2 and 3.
+% (This DBN is the same as Fig 10 in my tech report.)
+%
+%   Q1 ---------->   Q1
+%   |  \            ^ |
+%   |   v          /  |
+%   |    F2 ------/   |
+%   |   ^ ^        \  |
+%   |  /  |         \ |
+%   | /   |          ||
+%   v     |          vv
+%   Q2----| --------> Q2
+%  /| \   |          ^|
+% / |  v  |         / |
+% | |   F3 --------/  |
+% | |   ^          \  |
+% | v  /            v v
+% | Q3 ----------->  Q3
+% |  |    
+% \  | 
+%  v v    
+%   O
+%
+%
+% Optional arguments in name/value format [default value in brackets]
+%
+% Qsizes      - sizes at each level [ none ]
+% allQ       - 1 means level i connects to all Q levels below, 0 means just to i+1 [0]
+% transprob  - transprob{d}(i,k,j) = P(Q(d,t)=j|Q(d,t-1)=i,Q(1:d-1,t)=k)  ['leftright']
+% startprob  - startprob{d}(k,j) = P(Q(d,t)=j|Q(1:d-1,t)=k)  ['leftstart']
+% termprob   - termprob{d}(k,j) = P(F(d,t)=2|Q(1:d-1,t)=k,Q(d,t)=j) for d>1 ['rightstop']
+% selfprop   - prob of a self transition (termprob default = 1-selfprop) [0.8]
+% Osize       - size of O node
+% discrete_obs - 1 means O is tabular_CPD, 0 means gaussian_CPD [0]
+% Oargs       - cell array of args to pass to the O CPD  [ {} ]
+% Ops         - Q parents of O [Qnodes(end)]
+% F1          - 1 means level 1 can finish (restart), else there is no F1->Q1 arc [0]
+% clamp1     - 1 means we clamp the params of the Q nodes in slice 1 (Qt1params) [1]
+%   Note: the Qt1params are startprob, which should be shared with other slices.
+%   However, in the current implementation, the Qt1params will only be estimated
+%   from the initial state of each sequence.
+%
+% For d=1, startprob{1}(1,j) is only used in the first slice and
+% termprob{1} is ignored, since we assume the top level never resets.
+% Also, transprob{1}(i,j) can be used instead of transprob{1}(i,1,j).
+%
+% leftstart means the model always starts in state 1.
+% rightstop means the model can only finish in its last state (Qsize(d)).
+% unif means each state is equally like to reach any other
+% rnd means the transition/starting probs are random (drawn from rand)
+%
+% Q1:QD in slice 1 are of type tabular_CPD
+% Q1:QD in slice 2 are of type hhmmQ_CPD.
+% F(2:D-1) is of type hhmmF_CPD, FD is of type tabular_CPD.
+
+args = varargin;
+nargs = length(args);
+
+% get sizes of nodes and topology
+Qsizes = [];
+Osize = [];
+allQ = 0;
+Ops = [];
+F1 = 0;
+for i=1:2:nargs
+  switch args{i},
+   case 'Qsizes', Qsizes = args{i+1}; 
+   case 'Osize',  Osize = args{i+1}; 
+   case 'allQ',   allQ = args{i+1}; 
+   case 'Ops',    Ops = args{i+1}; 
+   case 'F1',     F1 = args{i+1}; 
+  end
+end
+if isempty(Qsizes), error('must specify Qsizes'); end
+if Osize==0, error('must specify Osize'); end
+D = length(Qsizes);
+Qnodes = 1:D;
+
+if isempty(Ops), Ops = Qnodes(end); end
+
+
+[intra, inter, Qnodes, Fnodes, Onode] = mk_hhmm_topo(D, allQ, Ops, F1);
+ss = length(intra);
+names = {};
+
+if F1
+  Fnodes_ndx = Fnodes;
+else
+  Fnodes_ndx = [-1 Fnodes]; % Fnodes(1) is a dummy index
+end
+		
+% set default params
+discrete_obs = 0;
+Oargs = {};
+startprob = cell(1,D);
+startprob{1} = 'unif';
+for d=2:D
+  startprob{d} = 'leftstart';
+end
+transprob = cell(1,D);
+transprob{1} = 'unif';
+for d=2:D
+  transprob{d} = 'leftright';
+end
+termprob = cell(1,D);
+for d=2:D
+  termprob{d} = 'rightstop';
+end
+selfprob = 0.8;
+clamp1 = 1;
+
+for i=1:2:nargs
+  switch args{i},
+   case 'discrete_obs', discrete_obs = args{i+1}; 
+   case 'Oargs',        Oargs = args{i+1};
+   case 'startprob',    startprob = args{i+1};
+   case 'transprob',    transprob = args{i+1};
+   case 'termprob',     termprob = args{i+1};
+   case 'selfprob',     selfprob = args{i+1};
+   case 'clamp1',       clamp1 = args{i+1};
+  end
+end
+
+ns = zeros(1,ss);
+ns(Qnodes) = Qsizes;
+ns(Onode) = Osize;
+ns(Fnodes) = 2;
+
+dnodes = [Qnodes Fnodes];
+if discrete_obs
+  dnodes = [dnodes Onode];
+end
+onodes = [Onode];
+
+bnet = mk_dbn(intra, inter, ns, 'observed', onodes, 'discrete', dnodes, 'names', names);
+eclass = bnet.equiv_class;
+
+for d=1:D
+  if d==1
+    Qps = [];
+  elseif allQ
+    Qps = Qnodes(1:d-1);
+  else
+    Qps = Qnodes(d-1);
+  end
+  Qpsz = prod(ns(Qps));
+  Qsz = ns(Qnodes(d));
+  if isstr(startprob{d})
+    switch startprob{d}
+     case 'unif', startprob{d} = mk_stochastic(ones(Qpsz, Qsz));
+     case 'rnd', startprob{d} = mk_stochastic(rand(Qpsz, Qsz));
+     case 'leftstart', startprob{d} = zeros(Qpsz, Qsz); startprob{d}(:,1) = 1;
+    end
+  end
+  if isstr(transprob{d})
+    switch transprob{d}
+     case 'unif', transprob{d} = mk_stochastic(ones(Qsz, Qpsz, Qsz));
+     case 'rnd', transprob{d} = mk_stochastic(rand(Qsz, Qpsz, Qsz));
+     case 'leftright',
+      LR = mk_leftright_transmat(Qsz, selfprob);
+      temp = repmat(reshape(LR, [1 Qsz Qsz]), [Qpsz 1 1]); % transprob(k,i,j)
+      transprob{d} = permute(temp, [2 1 3]); % now transprob(i,k,j)
+    end
+  end
+  if isstr(termprob{d})
+    switch termprob{d}
+     case 'unif', termprob{d} = mk_stochastic(ones(Qpsz, Qsz, 2));
+     case 'rnd', termprob{d} = mk_stochastic(rand(Qpsz, Qsz, 2));
+     case 'rightstop',
+      %termprob(k,i,t) Might terminate if i=Qsz; will not terminate if i<Qsz
+      stopprob = 1-selfprob;
+      termprob{d} = zeros(Qpsz, Qsz, 2);
+      termprob{d}(:,Qsz,2) = stopprob;
+      termprob{d}(:,Qsz,1) = 1-stopprob;
+      termprob{d}(:,1:(Qsz-1),1) = 1;
+     otherwise, error(['unrecognized termprob ' termprob{d}])
+    end
+  elseif d>1 % passed in termprob{d}(k,j)
+    temp = termprob{d};
+    termprob{d} = zeros(Qpsz, Qsz, 2);
+    termprob{d}(:,:,2) = temp;
+    termprob{d}(:,:,1) = ones(Qpsz,Qsz) - temp;
+  end
+end
+
+
+% SLICE 1
+
+for d=1:D
+  bnet.CPD{eclass(Qnodes(d),1)} = tabular_CPD(bnet, Qnodes(d), 'CPT', startprob{d}, 'adjustable', clamp1);
+end
+
+if F1
+  d = 1;
+  bnet.CPD{eclass(Fnodes_ndx(d),1)}  = hhmmF_CPD(bnet, Fnodes_ndx(d), Qnodes(d), Fnodes_ndx(d+1), ...
+						 'termprob', termprob{d});
+end
+for d=2:D-1
+  if allQ
+    Qps = Qnodes(1:d-1);
+  else
+    Qps = Qnodes(d-1);
+  end
+  bnet.CPD{eclass(Fnodes_ndx(d),1)}  = hhmmF_CPD(bnet, Fnodes_ndx(d), Qnodes(d), Fnodes_ndx(d+1), ...
+						 'Qps', Qps, 'termprob', termprob{d});
+end
+bnet.CPD{eclass(Fnodes_ndx(D),1)}  = tabular_CPD(bnet, Fnodes_ndx(D), 'CPT', termprob{D});
+
+if discrete_obs
+  bnet.CPD{eclass(Onode,1)} = tabular_CPD(bnet, Onode, Oargs{:});
+else
+  bnet.CPD{eclass(Onode,1)} = gaussian_CPD(bnet, Onode, Oargs{:});
+end
+
+% SLICE 2
+
+%for d=1:D
+%  bnet.CPD{eclass(Qnodes(d),2)} = hhmmQ_CPD(bnet, Qnodes(d)+ss, Qnodes, d, D, ...
+%					    'startprob', startprob{d}, 'transprob', transprob{d}, ...
+%					    'allQ', allQ);
+%end
+
+d = 1;
+if F1
+  bnet.CPD{eclass(Qnodes(d),2)} = hhmmQ_CPD(bnet, Qnodes(d)+ss, 'Fself', Fnodes_ndx(d), ...
+					    'Fbelow', Fnodes_ndx(d+1), ...
+					    'startprob', startprob{d}, 'transprob', transprob{d});
+else
+    bnet.CPD{eclass(Qnodes(d),2)} = hhmmQ_CPD(bnet, Qnodes(d)+ss, ...
+					    'Fbelow', Fnodes_ndx(d+1), ...
+					    'startprob', startprob{d}, 'transprob', transprob{d});
+end
+for d=2:D-1
+  if allQ
+    Qps = Qnodes(1:d-1);
+  else
+    Qps = Qnodes(d-1);
+  end
+  Qps = Qps + ss; % since all in slice 2
+  bnet.CPD{eclass(Qnodes(d),2)} = hhmmQ_CPD(bnet, Qnodes(d)+ss, 'Fself', Fnodes_ndx(d), ...
+					    'Fbelow', Fnodes_ndx(d+1), 'Qps', Qps, ...
+					    'startprob', startprob{d}, 'transprob', transprob{d});
+end
+d = D;
+if allQ
+  Qps = Qnodes(1:d-1);
+else
+  Qps = Qnodes(d-1);
+end
+Qps = Qps + ss; % since all in slice 2
+bnet.CPD{eclass(Qnodes(d),2)} = hhmmQ_CPD(bnet, Qnodes(d)+ss, 'Fself', Fnodes_ndx(d), ...
+					  'Qps', Qps, ...
+					  'startprob', startprob{d}, 'transprob', transprob{d});
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/mk_hhmm_topo.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/mk_hhmm_topo.m
new file mode 100644
index 00000000..7a5fe57c
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/mk_hhmm_topo.m
@@ -0,0 +1,76 @@
+function [intra, inter, Qnodes, Fnodes, Onode] = mk_hhmm_topo(D, all_Q_to_Qs, Ops, F1)
+% MK_HHMM_TOPO Make Hierarchical HMM topology
+% function [intra, inter, Qnodes, Fnodes, Onode] = mk_hhmm_topo(D, all_Q_to_Qs, Ops, F1)
+%
+% D is the depth of the hierarchy
+% If all_Q_to_Qs = 1, level i connects to all levels below, else just to i+1 [0]
+% Ops are the Q parents of the observed node [Qnodes(end)]
+% If F1=1, level 1 can finish (restart), else there is no F1->Q1 arc [0]
+
+Qnodes = 1:D;
+
+if nargin < 2, all_Q_to_Qs = 1; end
+if nargin < 3, Ops = Qnodes(D); end
+if nargin < 4, F1 = 0; end
+
+if F1
+  Fnodes = 2*D:-1:D+1; % must number from bottom to top
+  Onode = 2*D+1;
+  ss = 2*D+1;
+else
+  Fnodes = [-1 (2*D)-1:-1:D+1]; % Fnodes(1) is a dummy index
+  Onode = 2*D;
+  ss = 2*D;
+end
+
+intra = zeros(ss);
+intra(Ops, Onode) = 1;
+for d=1:D-1
+  if all_Q_to_Qs
+    intra(Qnodes(d), Qnodes(d+1:end)) = 1;
+  else
+    intra(Qnodes(d), Qnodes(d+1)) = 1;
+  end
+end
+for d=D:-1:3
+  intra(Fnodes(d), Fnodes(d-1)) = 1;
+end
+if F1
+  intra(Fnodes(2), Fnodes(1)) = 1;
+end
+if all_Q_to_Qs
+  if F1
+    intra(Qnodes(1), Fnodes(1:end)) = 1;
+  else
+    intra(Qnodes(1), Fnodes(2:end)) = 1;
+  end
+  for d=2:D
+    intra(Qnodes(d), Fnodes(d:end)) = 1;
+  end
+else
+  if F1
+    intra(Qnodes(1), Fnodes([1 2])) = 1;
+  else
+    intra(Qnodes(1), Fnodes(2)) = 1;
+  end
+  for d=2:D-1
+    intra(Qnodes(d), Fnodes([d d+1])) = 1;
+  end
+  intra(Qnodes(D), Fnodes(D)) = 1;
+end
+
+
+inter = zeros(ss);
+for d=1:D
+  inter(Qnodes(d), Qnodes(d)) = 1;
+end
+if F1
+  inter(Fnodes(1), Qnodes(1)) = 1;
+end
+for d=2:D
+  inter(Fnodes(d), Qnodes([d-1 d])) = 1;
+end
+
+if ~F1
+  Fnodes = Fnodes(2:end); % strip off dummy -1 term
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/mk_hhmm_topo_F1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/mk_hhmm_topo_F1.m
new file mode 100644
index 00000000..2fc5f912
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/mk_hhmm_topo_F1.m
@@ -0,0 +1,65 @@
+function [intra, inter, Qnodes, Fnodes, Onode] = mk_hhmm_topo_F1(D, all_Q_to_Qs, Ops)
+% MK_HHMM_TOPO Make Hierarchical HMM topology assuming level 1 can finish 
+% function [intra, inter, Qnodes, Fnodes, Onode] = mk_hhmm_topo(D, all_Q_to_Qs, Ops, F1)
+%
+% D is the depth of the hierarchy
+% If all_Q_to_Qs = 1, level i connects to all levels below, else just to i+1 [0]
+% Ops are the Q parents of the observed node [Qnodes(end)]
+% If F1=1, level 1 can finish (restart), else there is no F1->Q1 arc [0]
+
+Qnodes = 1:D;
+
+if nargin < 2, all_Q_to_Qs = 1; end
+if nargin < 3, Ops = Qnodes(D); end
+if nargin < 4, F1 = 0; end
+
+if F1
+  Fnodes = 2*D:-1:D+1; % must number from bottom to top
+  Onode = 2*D+1;
+  ss = 2*D+1;
+else
+  Fnodes = (2*D)-1:-1:D+1;
+  Onode = 2*D;
+  ss = 2*D;
+end
+
+intra = zeros(ss);
+intra(Ops, Onode) = 1;
+for d=1:D-1
+  if all_Q_to_Qs
+    intra(Qnodes(d), Qnodes(d+1:end)) = 1;
+  else
+    intra(Qnodes(d), Qnodes(d+1)) = 1;
+  end
+end
+for d=D:-1:3
+  intra(Fnodes(d), Fnodes(d-1)) = 1;
+end
+if F1
+  intra(Fnodes(2), Fnodes(1)) = 1;
+end
+if all_Q_to_Qs
+  for d=1:D
+    intra(Qnodes(d), Fnodes(d:end)) = 1;
+  end
+else
+  for d=1:D
+    if d < D
+      intra(Qnodes(d), Fnodes([d d+1])) = 1;
+    else
+      intra(Qnodes(d), Fnodes(d)) = 1;
+    end
+  end
+end
+
+inter = zeros(ss);
+for d=1:D
+  inter(Qnodes(d), Qnodes(d)) = 1;
+end
+for d=1:D
+  if d==1
+    inter(Fnodes(d), Qnodes(d)) = 1;
+  else
+    inter(Fnodes(d), Qnodes([d-1 d])) = 1;
+  end
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/pretty_print_hhmm_parse.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/pretty_print_hhmm_parse.m
new file mode 100644
index 00000000..81b965d5
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/pretty_print_hhmm_parse.m
@@ -0,0 +1,67 @@
+function pretty_print_hhmm_parse(mpe, Qnodes, Fnodes, Onode, alphabet)
+% function pretty_print_hhmm_parse(mpe, Qnodes, Fnodes, Onode, alphabet)
+%
+% mpe(i,t) is the most probable value of node i at time t
+% Qnodes(1:D), Fnodes = [F2 .. FD], Onode contain the node ids
+% alphabet(i) is the i'th output symbol, or [] if don't want displayed
+
+T = size(mpe,2);
+ncols = 20;
+t1 = 1; t2 = min(T, t1+ncols-1);
+while (t1 < T)
+  %fprintf('%d:%d\n', t1, t2);
+  if iscell(mpe)
+    print_block_cell(mpe(:,t1:t2), Qnodes, Fnodes, Onode, alphabet, t1);
+  else
+    print_block(mpe(:,t1:t2), Qnodes, Fnodes, Onode, alphabet, t1);
+  end
+  fprintf('\n\n');
+  t1 = t2+1; t2 = min(T, t1+ncols-1);
+end
+
+%%%%%%
+
+function print_block_cell(mpe, Qnodes, Fnodes, Onode, alphabet, start)
+
+D = length(Qnodes);
+T = size(mpe, 2);
+fprintf('%3d ', start:start+T-1); fprintf('\n');
+for d=1:D
+  for t=1:T
+    if (d > 1) & (mpe{Fnodes(d-1),t} == 2)
+      fprintf('%3d|', mpe{Qnodes(d), t});
+    else
+      fprintf('%3d ', mpe{Qnodes(d), t});
+    end
+  end
+  fprintf('\n');
+end
+if ~isempty(alphabet)
+  a = cell2num(mpe(Onode,:));
+  %fprintf('%3c ', alphabet(mpe{Onode,:}));
+  fprintf('%3c ', alphabet(a))
+  fprintf('\n');
+end
+
+
+%%%%%%
+
+function print_block(mpe, Qnodes, Fnodes, Onode, alphabet, start)
+
+D = length(Qnodes);
+T = size(mpe, 2);
+fprintf('%3d ', start:start+T-1); fprintf('\n');
+for d=1:D
+  for t=1:T
+    if (d > 1) & (mpe(Fnodes(d-1),t) == 2)
+      fprintf('%3d|', mpe(Qnodes(d), t));
+    else
+      fprintf('%3d ', mpe(Qnodes(d), t));
+    end
+  end
+  fprintf('\n');
+end
+if ~isempty(alphabet)
+  fprintf('%3c ', alphabet(mpe(Onode,:)));
+  fprintf('\n');
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/remove_hhmm_end_state.m b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/remove_hhmm_end_state.m
new file mode 100644
index 00000000..1ef9ded9
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/remove_hhmm_end_state.m
@@ -0,0 +1,41 @@
+function [transprob, termprob] = remove_hhmm_end_state(A)
+% REMOVE_END_STATE Infer transition and termination probabilities from automaton with an end state
+% [transprob, termprob] = remove_end_state(A)
+%
+% A(i,k,j) = Pr( i->j | Qps=k), where i in 1:Q, j in 1:(Q+1), and Q+1 is the end state
+% This implements the equation in footnote 3 of my NIPS 01 paper,
+% transprob(i,k,j) = \tilde{A}_k(i,j)
+% termprob(k,j) = \tau_k(j)
+%
+% For the top level, the k index is missing.
+
+Q = size(A,1);
+toplevel = (ndims(A)==2);
+if toplevel
+  Qk = 1;
+  A = reshape(A, [Q 1 Q+1]);
+else
+  Qk = size(A, 2);
+end
+
+transprob = A(:, :, 1:Q);
+term = A(:,:,Q+1)'; % term(k,j) = P(Qj -> end | k)
+termprob = term;
+%termprob = zeros(Qk, Q, 2);
+%termprob(:,:,2) = term;
+%termprob(:,:,1) = 1-term;
+
+for k=1:Qk
+  for i=1:Q
+    for j=1:Q
+      denom = (1-termprob(k,i));
+      denom = denom + (denom==0)*eps;
+      transprob(i,k,j) = transprob(i,k,j) / denom;
+    end
+  end    
+end
+
+if toplevel
+  termprob = squeeze(termprob);
+  transprob = squeeze(transprob);
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/Old/CVS/Entries b/sourcecodes/bnt-master/BNT/examples/dynamic/Old/CVS/Entries
new file mode 100644
index 00000000..b5b0dc43
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/Old/CVS/Entries
@@ -0,0 +1,8 @@
+/chmm1.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/cmp_inference.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/kalman1.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/old.water1.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/online1.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/online2.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/scg_dbn.m/1.1.1.1/Wed May 29 15:59:54 2002//
+D
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/Old/CVS/Repository b/sourcecodes/bnt-master/BNT/examples/dynamic/Old/CVS/Repository
new file mode 100644
index 00000000..b23f8f6d
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/Old/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/examples/dynamic/Old
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/Old/CVS/Root b/sourcecodes/bnt-master/BNT/examples/dynamic/Old/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/Old/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/Old/chmm1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/Old/chmm1.m
new file mode 100644
index 00000000..d4195c97
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/Old/chmm1.m
@@ -0,0 +1,40 @@
+% Compare the speeds of various inference engines on a coupled HMM
+
+N = 2;
+Q = 2;
+rand('state', 0);
+randn('state', 0);
+discrete = 1;
+if discrete
+  Y = 2; % size of output alphabet
+else
+  Y = 1;
+end
+coupled = 1;
+[bnet, onodes] = mk_chmm(N, Q, Y, discrete, coupled);
+ss = N*2;
+
+T = 3;
+
+
+engine = {};
+tic; engine{end+1} = jtree_dbn_inf_engine(bnet, 'observed', onodes);  toc
+%tic; engine{end+1} = jtree_ndxSD_dbn_inf_engine(bnet, onodes);  toc
+%tic; engine{end+1} = jtree_ndxB_dbn_inf_engine(bnet, onodes);  toc
+engine{end+1} = hmm_inf_engine(bnet, onodes);
+%engine{end+1} = dhmm_inf_engine(bnet, onodes);
+tic; engine{end+1} = jtree_unrolled_dbn_inf_engine(bnet, T, onodes);  toc
+
+%engine{end+1} = bk_inf_engine(bnet, 'ff', onodes);
+%engine{end+1} = loopy_dbn_inf_engine(bnet, onodes);
+
+exact = [1 2 3];
+
+filter = 0;
+single = 0;
+maximize = 0;
+
+[err, time, engine] = cmp_inference(bnet, onodes, engine, exact, T, filter, single, maximize);
+%err = cmp_learning(bnet, onodes, engine, exact, T);
+
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/Old/cmp_inference.m b/sourcecodes/bnt-master/BNT/examples/dynamic/Old/cmp_inference.m
new file mode 100644
index 00000000..b5c936f0
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/Old/cmp_inference.m
@@ -0,0 +1,75 @@
+function [err, time, engine] = cmp_inference(bnet, engine, exact, T, filter, singletons, maximize)
+% CMP_INFERENCE Compare several inference engines on a DBN
+% [err, time, engine] = cmp_inference(bnet, engine, exact, T, filter, singletons, maximize)
+%
+% engine{i} is the i'th inference engine.
+% 'exact' specifies which engines do exact inference - 
+%   we check that these all give the same results.
+% 'T' is the length of the random sequence we generate.
+% If filter=1, we do filtering, else smoothing (default: smoothing)
+% If singletons=1, we compare marginal_nodes, else marginal_family (default: family)
+%
+% err(e,n,t) = sum_i | Pr_exact(X(n,t)=i) - Pr_e(X(n,t)=i) |
+%   where Pr_e = prob. according to engine e
+% time(e) = elapsed time for doing inference with engine e
+
+err = [];
+
+if nargin < 5, filter = 0; end
+if nargin < 6, singletons = 0; end
+if nargin < 7, maximize = 0; end
+
+check_ll = 1;
+
+assert(~maximize);
+
+E = length(engine);
+ref = exact(1); % reference
+
+ss = length(bnet.intra);
+ev = sample_dbn(bnet, 'length', T);
+evidence = cell(ss,T);
+onodes = bnet.observed;
+evidence(onodes,:) = ev(onodes, :);
+
+assert(~filter);
+for i=1:E
+  tic;
+  %[engine{i}, ll(i)] = enter_evidence(engine{i}, evidence, 'maximize', maximize);
+  [engine{i}, ll(i)] = enter_evidence(engine{i}, evidence);
+  time(i)=toc;
+  fprintf('engine %d took %6.4f seconds\n', i, time(i));
+end
+
+cmp = mysetdiff(exact, ref);
+if check_ll
+for i=cmp(:)'
+  if ~approxeq(ll(ref), ll(i))
+    error(['engine ' num2str(i) ' has wrong ll'])
+  end
+end
+end
+ll
+
+hnodes = mysetdiff(1:ss, onodes);
+m = cell(1,E);
+for t=1:T
+  for n=hnodes(:)'
+    for e=1:E
+      if singletons
+	m{e} = marginal_nodes(engine{e}, n, t);
+      else
+	m{e} = marginal_family(engine{e}, n, t);
+      end
+    end
+    for e=1:E
+      assert(isequal(m{e}.domain, m{ref}.domain));
+    end
+    for e=cmp(:)'
+      if ~approxeq(m{ref}.T(:), m{e}.T(:))
+	str= sprintf('engine %d is wrong; n=%d, t=%d', e, n, t);
+	error(str)
+      end
+    end
+  end
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/Old/kalman1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/Old/kalman1.m
new file mode 100644
index 00000000..c068ab3e
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/Old/kalman1.m
@@ -0,0 +1,127 @@
+% Make a linear dynamical system
+%   X1 -> X2
+%   |     | 
+%   v     v
+%   Y1    Y2 
+
+intra = zeros(2);
+intra(1,2) = 1;
+inter = zeros(2);
+inter(1,1) = 1;
+n = 2;
+
+X = 2; % size of hidden state
+Y = 2; % size of observable state
+
+ns = [X Y];
+dnodes = [];
+onodes = [2];
+eclass1 = [1 2];
+eclass2 = [3 2];
+bnet = mk_dbn(intra, inter, ns, 'discrete', dnodes, 'eclass1', eclass1, 'eclass2', eclass2, ...
+	      'observed', onodes);
+
+x0 = rand(X,1);
+V0 = eye(X);
+C0 = rand(Y,X);
+R0 = eye(Y);
+A0 = rand(X,X);
+Q0 = eye(X);
+
+bnet.CPD{1} = gaussian_CPD(bnet, 1, 'mean', x0, 'cov', V0, 'cov_prior_weight', 0);
+bnet.CPD{2} = gaussian_CPD(bnet, 2, 'mean', zeros(Y,1), 'cov', R0, 'weights', C0, ...
+			   'clamp_mean', 1, 'cov_prior_weight', 0);
+bnet.CPD{3} = gaussian_CPD(bnet, 3, 'mean', zeros(X,1), 'cov', Q0, 'weights', A0, ...
+			   'clamp_mean', 1, 'cov_prior_weight', 0);
+
+
+T = 5; % fixed length sequences
+
+clear engine;
+engine{1} = kalman_inf_engine(bnet);
+engine{2} = jtree_unrolled_dbn_inf_engine(bnet, T);
+engine{3} = jtree_dbn_inf_engine(bnet);
+N = length(engine);
+
+% inference
+
+ev = sample_dbn(bnet, T);
+evidence = cell(n,T);
+evidence(onodes,:) = ev(onodes, :);
+
+t = 1;
+query = [1 3];
+m = cell(1, N);
+ll = zeros(1, N);
+for i=1:N
+  [engine{i}, ll(i)] = enter_evidence(engine{i}, evidence);
+  m{i} = marginal_nodes(engine{i}, query, t);
+end
+
+% compare all engines to engine{1}
+for i=2:N
+  assert(approxeq(m{1}.mu, m{i}.mu));
+  assert(approxeq(m{1}.Sigma, m{i}.Sigma));
+  assert(approxeq(ll(1), ll(i)));
+end
+
+if 0
+for i=2:N
+  approxeq(m{1}.mu, m{i}.mu)
+  approxeq(m{1}.Sigma, m{i}.Sigma)
+  approxeq(ll(1), ll(i))
+end
+end
+
+% learning
+
+ncases = 5;
+cases = cell(1, ncases);
+for i=1:ncases
+  ev = sample_dbn(bnet, T);
+  cases{i} = cell(n,T);
+  cases{i}(onodes,:) = ev(onodes, :);
+end
+
+max_iter = 2;
+bnet2 = cell(1,N);
+LLtrace = cell(1,N);
+for i=1:N
+  [bnet2{i}, LLtrace{i}] = learn_params_dbn_em(engine{i}, cases, 'max_iter', max_iter);
+end
+
+for i=1:N
+  temp = bnet2{i};
+  for e=1:3
+    CPD{i,e} = struct(temp.CPD{e});
+  end
+end
+
+for i=2:N
+  assert(approxeq(LLtrace{i}, LLtrace{1}));
+  for e=1:3
+    assert(approxeq(CPD{i,e}.mean, CPD{1,e}.mean));
+    assert(approxeq(CPD{i,e}.cov, CPD{1,e}.cov));
+    assert(approxeq(CPD{i,e}.weights, CPD{1,e}.weights));
+  end
+end
+
+
+% Compare to KF toolbox
+
+data = zeros(Y, T, ncases);
+for i=1:ncases
+  data(:,:,i) = cell2num(cases{i}(onodes, :));
+end   
+[A2, C2, Q2, R2, x2, V2, LL2trace] =  learn_kalman(data, A0, C0, Q0, R0, x0, V0, max_iter);
+
+
+e = 1;
+assert(approxeq(x2, CPD{e,1}.mean))
+assert(approxeq(V2, CPD{e,1}.cov))
+assert(approxeq(C2, CPD{e,2}.weights))
+assert(approxeq(R2, CPD{e,2}.cov));
+assert(approxeq(A2, CPD{e,3}.weights))
+assert(approxeq(Q2, CPD{e,3}.cov));
+assert(approxeq(LL2trace, LLtrace{1}))
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/Old/old.water1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/Old/old.water1.m
new file mode 100644
index 00000000..0a356ef8
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/Old/old.water1.m
@@ -0,0 +1,48 @@
+% Compare the speeds of various inference engines on the water DBN
+
+[bnet, onodes] = mk_water_dbn;
+
+T = 3;
+
+engine = {};
+engine{end+1} = jtree_unrolled_dbn_inf_engine(bnet, T, onodes);
+engine{end+1} = hmm_inf_engine(bnet, onodes);
+engine{end+1} = frontier_inf_engine(bnet, onodes);
+engine{end+1} = jtree_dbn_inf_engine(bnet, onodes);
+engine{end+1} = bk_inf_engine(bnet, 'exact', onodes);
+
+engine{end+1} = bk_inf_engine(bnet, 'ff', onodes);
+engine{end+1} = bk_inf_engine(bnet, { [1 2], [3 4 5 6], [7 8] }, onodes);
+
+N = length(engine);
+exact = 1:5;
+
+
+filter = 0;
+err = cmp_inference(bnet, onodes, engine, exact, T, filter);
+
+% elapsed times for enter_evidence  (matlab 5.3 on PIII with 256MB running Redhat linux)  
+
+% T = 5, 4/20/00
+%     0.6266 unrolled *
+%     0.3490 hmm *
+%     1.1743 frontier
+%     1.4621 old frontier
+%     0.3270 fast frontier *
+%     1.3926 jtree 
+%     1.3790 bk 
+%     0.4916 fast bk
+%     0.4190 fast bk compiled
+%     0.3574 fast jtree *
+
+
+err = cmp_learning(bnet, onodes, engine, exact, T);
+
+% elapsed times for learn_params_dbn_em (matlab 5.3 on PIII with 256MB running Redhat linux)  
+
+% T = 5, 2cases, 2 iter, 4/20/00
+% 3.5750 unrolled
+% 3.7475 hmm
+% 2.1452 fast frontier
+% 2.5724 fast bk compiled
+% 2.3387 fast jtree
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/Old/online1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/Old/online1.m
new file mode 100644
index 00000000..05708e10
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/Old/online1.m
@@ -0,0 +1,59 @@
+% Check that online inference gives same results as filtering for various algorithms
+
+N = 3;
+Q = 2;
+ss = N*2;
+
+rand('state', 0);
+randn('state', 0);
+
+
+obs_size = 1;
+discrete_obs = 0;
+bnet = mk_chmm(N, Q, obs_size, discrete_obs);
+ns = bnet.node_sizes_slice;
+
+engine = {};
+engine{end+1} = hmm_inf_engine(bnet);
+E = length(engine);
+
+onodes = (1:N)+N;
+
+T = 4;
+ev = cell(ss,T);
+ev(onodes,:) = num2cell(randn(N, T));
+
+
+filter = 1;
+loglik2 = zeros(1,E);
+for e=1:E
+  [engine2{e}, loglik2(e)] = enter_evidence(engine{e}, ev, 'filter', filter);
+end
+
+loglik = zeros(1,E);
+marg1 = cell(E,N,T);
+for e=1:E
+  ll = zeros(1,T);
+  engine{e} = dbn_init_bel(engine{e});
+  for t=1:T
+    [engine{e}, ll(t)] = dbn_update_bel(engine{e}, ev(:,t), t);
+    for i=1:N
+      marg1{e,i,t} = dbn_marginal_from_bel(engine{e}, i);
+    end
+  end
+  loglik1(e) = sum(ll);
+end
+
+assert(approxeq(loglik1, loglik2))
+
+a = zeros(E,N,T);
+for e=1:E
+  for t=1:T
+    for i=1:N
+      marg2{e,i,t} = marginal_nodes(engine2{e}, i, t);
+      a(e,i,t) = (approxeq(marg2{e,i,t}.T(:), marg1{e,i,t}.T(:)));
+    end
+  end
+end
+
+assert(all(a(:)==1))
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/Old/online2.m b/sourcecodes/bnt-master/BNT/examples/dynamic/Old/online2.m
new file mode 100644
index 00000000..6b141f19
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/Old/online2.m
@@ -0,0 +1,33 @@
+N = 1; % regular HMM
+Q = 2;
+ss = 2;
+hnodes = 1;
+onodes = 2;
+
+rand('state', 0);
+randn('state', 0);
+O = 2;
+discrete_obs = 1;
+bnet = mk_chmm(N, Q, O, discrete_obs);
+ns = bnet.node_sizes_slice;
+
+engine = hmm_inf_engine(bnet, onodes);
+
+T = 4;
+ev = cell(ss,T);
+ev(onodes,:) = num2cell(sample_discrete([0.5 0.5], N, T));
+
+
+engine = dbn_init_bel(engine);
+for t=1:T
+  if t==1
+    [engine, ll(t)] = dbn_update_bel1(engine, ev(:,t));
+  else
+    [engine, ll(t)] = dbn_update_bel(engine, ev(:,t-1:t));
+  end
+  % one-step ahead prediction
+  lag = 1;
+  engine2 = dbn_predict_bel(engine, lag);  
+  marg = dbn_marginal_from_bel(engine2, 1)
+  marg = dbn_marginal_from_bel(engine2, 2)
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/Old/scg_dbn.m b/sourcecodes/bnt-master/BNT/examples/dynamic/Old/scg_dbn.m
new file mode 100644
index 00000000..0ddabb34
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/Old/scg_dbn.m
@@ -0,0 +1,70 @@
+% to test whether scg inference engine can handl dynameic BN
+% Make a linear dynamical system
+%   X1 -> X2
+%   |     | 
+%   v     v
+%   Y1    Y2 
+
+intra = zeros(2);
+intra(1,2) = 1;
+inter = zeros(2);
+inter(1,1) = 1;
+n = 2;
+
+X = 2; % size of hidden state
+Y = 2; % size of observable state
+
+ns = [X Y];
+dnodes = [];
+onodes = [2];
+eclass1 = [1 2];
+eclass2 = [3 2];
+bnet = mk_dbn(intra, inter, ns, dnodes, eclass1, eclass2);
+
+x0 = rand(X,1);
+V0 = eye(X);
+C0 = rand(Y,X);
+R0 = eye(Y);
+A0 = rand(X,X);
+Q0 = eye(X);
+
+bnet.CPD{1} = gaussian_CPD(bnet, 1, 'mean', x0, 'cov', V0);
+%bnet.CPD{2} = gaussian_CPD(bnet, 2, 'mean', zeros(Y,1), 'cov', R0, 'weights', C0, 'full', 'untied', 'clamped_mean');
+%bnet.CPD{3} = gaussian_CPD(bnet, 3, 'mean', zeros(X,1), 'cov', Q0, 'weights', A0, 'full', 'untied', 'clamped_mean');
+bnet.CPD{2} = gaussian_CPD(bnet, 2, 'mean', zeros(Y,1), 'cov', R0, 'weights', C0);
+bnet.CPD{3} = gaussian_CPD(bnet, 3, 'mean', zeros(X,1), 'cov', Q0, 'weights', A0);
+
+
+T = 5; % fixed length sequences
+
+clear engine;
+%engine{1} = kalman_inf_engine(bnet, onodes);
+engine{1} = scg_unrolled_dbn_inf_engine(bnet, T, onodes);
+engine{2} = jtree_unrolled_dbn_inf_engine(bnet, T);
+
+N = length(engine);
+
+% inference
+
+ev = sample_dbn(bnet, T);
+evidence = cell(n,T);
+evidence(onodes,:) = ev(onodes, :);
+
+t = 2;
+query = [1 3];
+m = cell(1, N);
+ll = zeros(1, N);
+
+engine{1} = enter_evidence(engine{1}, evidence);
+[engine{2}, ll(2)] = enter_evidence(engine{2}, evidence);
+m{1} = marginal_nodes(engine{1}, query);
+m{2} = marginal_nodes(engine{2}, query, t);
+
+
+% compare all engines to engine{1}
+for i=2:N
+  assert(approxeq(m{1}.mu, m{i}.mu));
+  assert(approxeq(m{1}.Sigma, m{i}.Sigma));
+%  assert(approxeq(ll(1), ll(i)));
+end
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/CVS/Entries b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/CVS/Entries
new file mode 100644
index 00000000..6810ce1d
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/CVS/Entries
@@ -0,0 +1,7 @@
+/mk_gmux_robot_dbn.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/mk_linear_slam.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/slam_kf.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/slam_offline_loopy.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/slam_partial_kf.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/slam_stationary_loopy.m/1.1.1.1/Wed May 29 15:59:54 2002//
+D/Old////
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/CVS/Repository b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/CVS/Repository
new file mode 100644
index 00000000..e32a23fa
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/examples/dynamic/SLAM
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/CVS/Root b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/CVS/Entries b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/CVS/Entries
new file mode 100644
index 00000000..37fe6bb1
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/CVS/Entries
@@ -0,0 +1,5 @@
+/offline_loopy_slam.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/paskin1.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/skf_data_assoc_gmux2.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/slam_kf.m/1.1.1.1/Wed May 29 15:59:54 2002//
+D
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/CVS/Repository b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/CVS/Repository
new file mode 100644
index 00000000..1bae1a70
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/examples/dynamic/SLAM/Old
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/CVS/Root b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/offline_loopy_slam.m b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/offline_loopy_slam.m
new file mode 100644
index 00000000..377a4659
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/offline_loopy_slam.m
@@ -0,0 +1,231 @@
+% We navigate a robot around a square using a fixed control policy and no noise.
+% We assume the robot observes the relative distance to the nearest landmark.
+% Everything is linear-Gaussian.
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Create toy data set
+
+seed = 0;
+rand('state', seed);
+randn('state', seed);
+
+if 1
+  T = 20;
+  ctrl_signal = [repmat([1 0]', 1, T/4) repmat([0 1]', 1, T/4) ...
+		 repmat([-1 0]', 1, T/4) repmat([0 -1]', 1, T/4)];
+else
+  T = 5;
+  ctrl_signal = repmat([1 0]', 1, T);
+end
+
+nlandmarks = 4;
+true_landmark_pos = [1 1;
+		     4 1;
+		     4 4;
+		     1 4]';
+init_robot_pos = [0 0]';
+
+true_robot_pos = zeros(2, T);
+true_data_assoc = zeros(1, T);
+true_rel_dist = zeros(2, T);
+for t=1:T
+  if t>1
+    true_robot_pos(:,t) = true_robot_pos(:,t-1) + ctrl_signal(:,t);
+  else
+    true_robot_pos(:,t) = init_robot_pos + ctrl_signal(:,t);
+  end
+  nn = argmin(dist2(true_robot_pos(:,t)', true_landmark_pos'));
+  %nn = t; % observe 1, 2, 3
+  true_data_assoc(t) = nn;
+  true_rel_dist(:,t) = true_landmark_pos(:, nn) - true_robot_pos(:,t);
+end
+
+figure(1);
+%clf; 
+hold on
+%plot(true_landmark_pos(1,:), true_landmark_pos(2,:), '*');
+for i=1:nlandmarks
+  text(true_landmark_pos(1,i), true_landmark_pos(2,i), sprintf('L%d',i));
+end
+for t=1:T
+  text(true_robot_pos(1,t), true_robot_pos(2,t), sprintf('%d',t));
+end
+hold off
+axis([-1 6 -1 6])
+
+R = 1e-3*eye(2); % noise added to observation
+Q = 1e-3*eye(2); % noise added to robot motion
+
+% Create data set
+obs_noise_seq = sample_gaussian([0 0]', R, T)';
+obs_rel_pos = true_rel_dist + obs_noise_seq;
+%obs_rel_pos = true_rel_dist;
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Create params for inference
+
+% X(t) = A X(t-1) + B U(t) + noise(Q)
+
+% [L1]  = [1     ]  * [L1]       + [0]  * Ut  + [0   ]
+% [L2]    [  1   ]    [L2]         [0]          [ 0  ]
+% [R ]t   [     1]    [R ]t-1      [1]          [   Q]
+
+% Y(t)|S(t)=s  = C(s) X(t) + noise(R)
+% Yt|St=1 = [1 0 -1]  * [L1]  + R
+%                       [L2]    
+%                       [R ]    
+
+% Create indices into block structure
+bs = 2*ones(1, nlandmarks+1); % sizes of blocks in state space
+robot_block =  block(nlandmarks+1, bs);
+for i=1:nlandmarks
+  landmark_block(:,i) = block(i, bs)';
+end
+Xsz = 2*(nlandmarks+1); % 2 values for each landmark plus robot
+Ysz = 2; % observe relative location
+Usz = 2; % input is (dx, dy)
+
+
+% create block-diagonal trans matrix for each switch
+A = zeros(Xsz, Xsz);
+for i=1:nlandmarks
+  bi = landmark_block(:,i);
+  A(bi, bi) = eye(2);
+end
+bi = robot_block;
+A(bi, bi) = eye(2);
+A = repmat(A, [1 1 nlandmarks]); % same for all switch values
+
+% create block-diagonal system cov
+
+
+Qbig = zeros(Xsz, Xsz);
+bi = robot_block;
+Qbig(bi,bi) = Q; % only add noise to robot motion
+Qbig = repmat(Qbig, [1 1 nlandmarks]);
+
+% create input matrix
+B = zeros(Xsz, Usz);
+B(robot_block,:) = eye(2); % only add input to robot position
+B = repmat(B, [1 1 nlandmarks]);
+
+% create observation matrix for each value of the switch node
+% C(:,:,i) = (0 ... I ... -I) where the I is in the i'th posn.
+% This computes L(i) - R
+C = zeros(Ysz, Xsz, nlandmarks);
+for i=1:nlandmarks
+  C(:, landmark_block(:,i), i) = eye(2); 
+  C(:, robot_block, i) = -eye(2);
+end
+
+% create observation cov for each value of the switch node
+Rbig = repmat(R, [1 1 nlandmarks]);
+
+% initial conditions
+init_x = zeros(Xsz, 1);
+init_v = zeros(Xsz, Xsz);
+bi = robot_block;
+init_x(bi) = init_robot_pos;
+init_V(bi, bi) = 1e-5*eye(2); % very sure of robot posn
+for i=1:nlandmarks
+  bi = landmark_block(:,i);
+  init_V(bi,bi)= 1e5*eye(2); % very uncertain of landmark psosns
+  %init_x(bi) = true_landmark_pos(:,i);
+  %init_V(bi,bi)= 1e-5*eye(2); % very sure of landmark psosns
+end
+
+%%%%%%%%%%%%%%%%%%%%%
+% Inference
+if 1
+[xsmooth, Vsmooth] = kalman_smoother(obs_rel_pos, A, C, Qbig, Rbig, init_x, init_V, ...
+				     'model', true_data_assoc, 'u', ctrl_signal, 'B', B);
+
+est_robot_pos = xsmooth(robot_block, :);
+est_robot_pos_cov = Vsmooth(robot_block, robot_block, :);
+
+for i=1:nlandmarks
+  bi = landmark_block(:,i);
+  est_landmark_pos(:,i) = xsmooth(bi, T);
+  est_landmark_pos_cov(:,:,i) = Vsmooth(bi, bi, T);
+end
+end
+
+
+if 0
+figure(1); hold on
+for i=1:nlandmarks
+  h=plotgauss2d(est_landmark_pos(:,i), est_landmark_pos_cov(:,:,i));
+  set(h, 'color', 'r')
+end
+hold off
+
+hold on
+for t=1:T
+  h=plotgauss2d(est_robot_pos(:,t), est_robot_pos_cov(:,:,t));
+  set(h,'color','r')
+  h=text(est_robot_pos(1,t), est_robot_pos(2,2), sprintf('R%d', t));
+  set(h,'color','r')
+end
+hold off
+end
+
+
+if 0
+figure(3)
+if 0
+  for t=1:T
+    imagesc(inv(Vsmooth(:,:,t)))
+    colorbar
+    fprintf('t=%d; press key to continue\n', t);
+    pause
+  end
+else
+  for t=1:T
+    subplot(5,4,t)
+    imagesc(inv(Vsmooth(:,:,t)))
+  end
+end
+end
+
+
+
+
+
+%%%%%%%%%%%%%%%%%
+% DBN inference
+
+if 1
+  [bnet, Unode, Snode, Lnodes, Rnode, Ynode, Lsnode] = ...
+      mk_gmux_robot_dbn(nlandmarks, Q, R, init_x, init_V, robot_block, landmark_block);
+  engine = pearl_unrolled_dbn_inf_engine(bnet, 'max_iter', 50, 'filename', ...
+					 '/home/eecs/murphyk/matlab/loopyslam.txt');
+else
+  [bnet, Unode, Snode, Lnodes, Rnode, Ynode] = ...
+      mk_gmux2_robot_dbn(nlandmarks, Q, R, init_x, init_V, robot_block, landmark_block);
+  engine = jtree_dbn_inf_engine(bnet);
+end
+
+nnodes = bnet.nnodes_per_slice;
+evidence = cell(nnodes, T);
+evidence(Ynode, :) = num2cell(obs_rel_pos, 1);
+evidence(Unode, :) = num2cell(ctrl_signal, 1);
+evidence(Snode, :) = num2cell(true_data_assoc);
+
+
+[engine, ll, niter] = enter_evidence(engine, evidence);
+niter
+
+loopy_est_robot_pos = zeros(2, T);
+for t=1:T
+  m = marginal_nodes(engine, Rnode, t);
+  loopy_est_robot_pos(:,t) = m.mu;
+end
+
+for i=1:nlandmarks
+  m = marginal_nodes(engine, Lnodes(i), T);
+  loopy_est_landmark_pos(:,i) = m.mu;
+  loopy_est_landmark_pos_cov(:,:,i) = m.Sigma;
+end
+
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/paskin1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/paskin1.m
new file mode 100644
index 00000000..286793d3
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/paskin1.m
@@ -0,0 +1,238 @@
+% This is like robot1, except we only use a Kalman filter.
+% The goal is to study how the precision matrix changes.
+
+seed = 1;
+rand('state', seed);
+randn('state', seed);
+
+if 0
+  T = 20;
+  ctrl_signal = [repmat([1 0]', 1, T/4) repmat([0 1]', 1, T/4) ...
+		 repmat([-1 0]', 1, T/4) repmat([0 -1]', 1, T/4)];
+else
+  T = 60;
+  ctrl_signal = repmat([1 0]', 1, T);
+end
+
+nlandmarks = 6;
+if 0
+  true_landmark_pos = [1 1;
+		    4 1;
+		    4 4;
+		    1 4]';
+else
+  true_landmark_pos = 10*rand(2,nlandmarks);
+end
+if 0
+figure(1); clf
+hold on
+for i=1:nlandmarks
+  %text(true_landmark_pos(1,i), true_landmark_pos(2,i), sprintf('L%d',i));
+  plot(true_landmark_pos(1,i), true_landmark_pos(2,i), '*')
+end
+hold off
+end
+
+init_robot_pos = [0 0]';
+
+true_robot_pos = zeros(2, T);
+true_data_assoc = zeros(1, T);
+true_rel_dist = zeros(2, T);
+for t=1:T
+  if t>1
+    true_robot_pos(:,t) = true_robot_pos(:,t-1) + ctrl_signal(:,t);
+  else
+    true_robot_pos(:,t) = init_robot_pos + ctrl_signal(:,t);
+  end
+  nn = argmin(dist2(true_robot_pos(:,t)', true_landmark_pos'));
+  %true_data_assoc(t) = nn;
+  %true_data_assoc = wrap(t, nlandmarks); % observe 1, 2, 3, 4, 1, 2, ...
+  true_data_assoc  = sample_discrete(normalise(ones(1,nlandmarks)),1,T);
+  true_rel_dist(:,t) = true_landmark_pos(:, nn) - true_robot_pos(:,t);
+end
+
+R = 1e-3*eye(2); % noise added to observation
+Q = 1e-3*eye(2); % noise added to robot motion
+
+% Create data set
+obs_noise_seq = sample_gaussian([0 0]', R, T)';
+obs_rel_pos = true_rel_dist + obs_noise_seq;
+%obs_rel_pos = true_rel_dist;
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Create params for inference
+
+% X(t) = A X(t-1) + B U(t) + noise(Q) 
+
+% [L1]  = [1     ]  * [L1]       + [0]  * Ut  + [0   ]
+% [L2]    [  1   ]    [L2]         [0]          [ 0  ]
+% [R ]t   [     1]    [R ]t-1      [1]          [   Q]
+
+% Y(t)|S(t)=s  = C(s) X(t) + noise(R)
+% Yt|St=1 = [1 0 -1]  * [L1]  + R
+%                       [L2]    
+%                       [R ]    
+
+% Create indices into block structure
+bs = 2*ones(1, nlandmarks+1); % sizes of blocks in state space
+robot_block =  block(nlandmarks+1, bs);
+for i=1:nlandmarks
+  landmark_block(:,i) = block(i, bs)';
+end
+Xsz = 2*(nlandmarks+1); % 2 values for each landmark plus robot
+Ysz = 2; % observe relative location
+Usz = 2; % input is (dx, dy)
+
+
+% create block-diagonal trans matrix for each switch
+A = zeros(Xsz, Xsz);
+for i=1:nlandmarks
+  bi = landmark_block(:,i);
+  A(bi, bi) = eye(2);
+end
+bi = robot_block;
+A(bi, bi) = eye(2);
+A = repmat(A, [1 1 nlandmarks]); % same for all switch values
+
+% create block-diagonal system cov
+
+
+Qbig = zeros(Xsz, Xsz);
+bi = robot_block;
+Qbig(bi,bi) = Q; % only add noise to robot motion
+Qbig = repmat(Qbig, [1 1 nlandmarks]);
+
+% create input matrix
+B = zeros(Xsz, Usz);
+B(robot_block,:) = eye(2); % only add input to robot position
+B = repmat(B, [1 1 nlandmarks]);
+
+% create observation matrix for each value of the switch node
+% C(:,:,i) = (0 ... I ... -I) where the I is in the i'th posn.
+% This computes L(i) - R
+C = zeros(Ysz, Xsz, nlandmarks);
+for i=1:nlandmarks
+  C(:, landmark_block(:,i), i) = eye(2); 
+  C(:, robot_block, i) = -eye(2);
+end
+
+% create observation cov for each value of the switch node
+Rbig = repmat(R, [1 1 nlandmarks]);
+
+% initial conditions
+init_x = zeros(Xsz, 1);
+init_v = zeros(Xsz, Xsz);
+bi = robot_block;
+init_x(bi) = init_robot_pos;
+%init_V(bi, bi) = 1e-5*eye(2); % very sure of robot posn
+init_V(bi, bi) = Q; % simualate uncertainty due to 1 motion step
+for i=1:nlandmarks
+  bi = landmark_block(:,i);
+  init_V(bi,bi)= 1e5*eye(2); % very uncertain of landmark psosns
+  %init_x(bi) = true_landmark_pos(:,i);
+  %init_V(bi,bi)= 1e-5*eye(2); % very sure of landmark psosns
+end
+
+%k = nlandmarks-1; % exact
+k = 3;
+ndx = {};
+for t=1:T
+  landmarks = unique(true_data_assoc(t:-1:max(t-k,1)));
+  tmp = [landmark_block(:, landmarks) robot_block'];
+  ndx{t} = tmp(:);
+end
+
+[xa, Va] = kalman_filter(obs_rel_pos, A, C, Qbig, Rbig, init_x, init_V, ...
+				     'model', true_data_assoc, 'u', ctrl_signal, 'B', B, ...
+		       'ndx', ndx);
+
+[xe, Ve] = kalman_filter(obs_rel_pos, A, C, Qbig, Rbig, init_x, init_V, ...
+				     'model', true_data_assoc, 'u', ctrl_signal, 'B', B);
+
+
+if 0
+est_robot_pos = x(robot_block, :);
+est_robot_pos_cov = V(robot_block, robot_block, :);
+
+for i=1:nlandmarks
+  bi = landmark_block(:,i);
+  est_landmark_pos(:,i) = x(bi, T);
+  est_landmark_pos_cov(:,:,i) = V(bi, bi, T);
+end
+end
+
+
+
+nrows = 10;
+stepsize = T/(2*nrows);
+ts = 1:stepsize:T;
+
+if 1 % plot
+  
+clim = [0 max(max(Va(:,:,end)))];
+
+figure(2)
+if 0
+  imagesc(Ve(1:2:end,1:2:end, T))
+  clim = get(gca,'clim');
+else
+  i = 1;
+  for t=ts(:)'
+    subplot(nrows,2,i)
+    i = i + 1;
+    imagesc(Ve(1:2:end,1:2:end, t))
+    set(gca, 'clim', clim)
+    colorbar
+  end
+end
+suptitle('exact')
+
+
+figure(3)
+if 0
+  imagesc(Va(1:2:end,1:2:end, T))
+  set(gca,'clim', clim)
+else
+  i = 1;
+  for t=ts(:)'
+    subplot(nrows,2,i)
+    i = i+1;
+    imagesc(Va(1:2:end,1:2:end, t))
+    set(gca, 'clim', clim)
+    colorbar
+  end
+end
+suptitle('approx')
+
+
+figure(4)
+i = 1;
+for t=ts(:)'
+  subplot(nrows,2,i)
+  i = i+1;
+  Vd = Va(1:2:end,1:2:end, t) - Ve(1:2:end,1:2:end,t);
+  imagesc(Vd)
+  set(gca, 'clim', clim)
+  colorbar
+end
+suptitle('diff')
+
+end % all plot
+
+
+for t=1:T
+  i = 1:2*nlandmarks;
+  denom = Ve(i,i,t) + (Ve(i,i,t)==0);
+  Vd =(Va(i,i,t)-Ve(i,i,t)) ./ denom;
+  Verr(t) = max(Vd(:));
+end
+figure(6); plot(Verr)
+title('max relative Verr')
+
+for t=1:T
+  %err(t)=rms(xa(:,t), xe(:,t));
+  err(t)=rms(xa(1:end-2,t), xe(1:end-2,t)); % exclude robot
+end
+figure(5);plot(err)
+title('rms mean pos')
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/skf_data_assoc_gmux2.m b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/skf_data_assoc_gmux2.m
new file mode 100644
index 00000000..0272d3f6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/skf_data_assoc_gmux2.m
@@ -0,0 +1,155 @@
+% This is like skf_data_assoc_gmux, except the objects don't move.
+% We are uncertain of their initial positions, and get more and more observations
+% over time. The goal is to test deterministic links (0 covariance).
+% This is like robot1, except the robot doesn't move and is always at [0 0],
+% so the relative location is simply L(s).
+
+nobj = 2;
+N = nobj+2;
+Xs = 1:nobj;
+S = nobj+1;
+Y = nobj+2;
+
+intra = zeros(N,N);
+inter = zeros(N,N);
+intra([Xs S], Y) =1;
+for i=1:nobj
+  inter(Xs(i), Xs(i))=1;
+end
+
+Xsz = 2; % state space = (x y)
+Ysz = 2;
+ns = zeros(1,N);
+ns(Xs) = Xsz;
+ns(Y) = Ysz;
+ns(S) = nobj;
+
+bnet = mk_dbn(intra, inter, ns, 'discrete', S, 'observed', [S Y]);
+
+% For each object, we have
+% X(t+1) = F X(t) + noise(Q)
+% Y(t) = H X(t) + noise(R)
+F = eye(2);
+H = eye(2);
+Q = 0*eye(Xsz); % no noise in dynamics
+R = eye(Ysz);
+
+init_state{1} = [10 10]';
+init_state{2} = [10 -10]';
+init_cov = eye(2);
+
+% Uncertain of initial state (position)
+for i=1:nobj
+  bnet.CPD{Xs(i)} = gaussian_CPD(bnet, Xs(i), 'mean', init_state{i}, 'cov', init_cov);
+end
+bnet.CPD{S} = root_CPD(bnet, S); % always observed
+bnet.CPD{Y} = gmux_CPD(bnet, Y, 'cov', repmat(R, [1 1 nobj]), 'weights', repmat(H, [1 1 nobj]));
+% slice 2
+eclass = bnet.equiv_class;
+for i=1:nobj
+  bnet.CPD{eclass(Xs(i), 2)} = gaussian_CPD(bnet, Xs(i)+N, 'mean', zeros(Xsz,1), 'cov', Q, 'weights', F);
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Create LDS params 
+
+% X(t) = A X(t-1) + B U(t) + noise(Q)
+
+% [L11]  = [1  ]  * [L1]       +   [Q ]
+% [L2]     [  1]    [L2]           [ Q]
+
+% Y(t)|S(t)=s  = C(s) X(t) + noise(R)
+% Yt|St=1 = [1 0]  * [L1]  + R
+%                    [L2]    
+
+nlandmarks = nobj;
+
+% Create indices into block structure
+bs = 2*ones(1, nobj); % sizes of blocks in state space
+for i=1:nlandmarks
+  landmark_block(:,i) = block(i, bs)';
+end
+Xsz = 2*(nlandmarks); % 2 values for each landmark plus robot
+Ysz = 2; % observe relative location
+
+% create block-diagonal trans matrix for each switch
+A = zeros(Xsz, Xsz);
+for i=1:nlandmarks
+  bi = landmark_block(:,i);
+  A(bi, bi) = eye(2);
+end
+A = repmat(A, [1 1 nlandmarks]); % same for all switch values
+
+% create block-diagonal system cov
+Qbig = zeros(Xsz, Xsz);
+Qbig = repmat(Qbig, [1 1 nlandmarks]);
+
+
+% create observation matrix for each value of the switch node
+% C(:,:,i) = (0 ... I ...) where the I is in the i'th posn.
+C = zeros(Ysz, Xsz, nlandmarks);
+for i=1:nlandmarks
+  C(:, landmark_block(:,i), i) = eye(2);
+end
+
+% create observation cov for each value of the switch node
+Rbig = repmat(R, [1 1 nlandmarks]);
+
+% initial conditions
+init_x = [init_state{1}; init_state{2}];
+init_V = zeros(Xsz, Xsz);
+for i=1:nlandmarks
+  bi = landmark_block(:,i);
+  init_V(bi,bi) = init_cov;
+end
+
+
+
+%%%%%%%%%%%%%%%%
+% Observe objects at random
+T = 10;
+evidence = cell(N, T);
+data_assoc = sample_discrete(normalise(ones(1,nobj)), 1, T);
+evidence(S,:) = num2cell(data_assoc);
+evidence = sample_dbn(bnet, 'evidence', evidence);
+
+
+% Inference
+ev = cell(N,T);
+ev(bnet.observed,:) = evidence(bnet.observed, :);
+y = cell2num(evidence(Y,:));
+
+engine = pearl_unrolled_dbn_inf_engine(bnet);
+engine = enter_evidence(engine, ev);
+
+loopy_est_pos = zeros(2, nlandmarks);
+loopy_est_pos_cov = zeros(2, 2, nlandmarks);
+for i=1:nobj
+  m = marginal_nodes(engine, Xs(i), T);
+  loopy_est_pos(:,i) = m.mu;
+  loopy_est_pos_cov(:,:,i) = m.Sigma;
+end
+
+
+[xsmooth, Vsmooth] = kalman_smoother(y, A, C, Qbig, Rbig, init_x, init_V, 'model', data_assoc);
+
+kf_est_pos = zeros(2, nlandmarks);
+kf_est_pos_cov = zeros(2, 2, nlandmarks);
+for i=1:nlandmarks
+  bi = landmark_block(:,i);
+  kf_est_pos(:,i) = xsmooth(bi, T);
+  kf_est_pos_cov(:,:,i) = Vsmooth(bi, bi, T);
+end
+
+
+kf_est_pos
+loopy_est_pos
+
+kf_est_pos_time = zeros(2, nlandmarks, T);
+for t=1:T
+  for i=1:nlandmarks
+    bi = landmark_block(:,i);
+    kf_est_pos_time(:,i,t) = xsmooth(bi, t);
+  end
+end
+kf_est_pos_time % same for all t since smoothed
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/slam_kf.m b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/slam_kf.m
new file mode 100644
index 00000000..ba98140f
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/Old/slam_kf.m
@@ -0,0 +1,172 @@
+% This is like robot1, except we only use a Kalman filter.
+% The goal is to study how the precision matrix changes.
+
+seed = 0;
+rand('state', seed);
+randn('state', seed);
+
+if 0
+  T = 20;
+  ctrl_signal = [repmat([1 0]', 1, T/4) repmat([0 1]', 1, T/4) ...
+		 repmat([-1 0]', 1, T/4) repmat([0 -1]', 1, T/4)];
+else
+  T = 12;
+  ctrl_signal = repmat([1 0]', 1, T);
+end
+
+nlandmarks = 6;
+if 0
+  true_landmark_pos = [1 1;
+		    4 1;
+		    4 4;
+		    1 4]';
+else
+  true_landmark_pos = 10*rand(2,nlandmarks);
+end
+figure(1); clf
+hold on
+for i=1:nlandmarks
+  %text(true_landmark_pos(1,i), true_landmark_pos(2,i), sprintf('L%d',i));
+  plot(true_landmark_pos(1,i), true_landmark_pos(2,i), '*')
+end
+hold off
+
+init_robot_pos = [0 0]';
+
+true_robot_pos = zeros(2, T);
+true_data_assoc = zeros(1, T);
+true_rel_dist = zeros(2, T);
+for t=1:T
+  if t>1
+    true_robot_pos(:,t) = true_robot_pos(:,t-1) + ctrl_signal(:,t);
+  else
+    true_robot_pos(:,t) = init_robot_pos + ctrl_signal(:,t);
+  end
+  %nn = argmin(dist2(true_robot_pos(:,t)', true_landmark_pos'));
+  nn = wrap(t, nlandmarks); % observe 1, 2, 3, 4, 1, 2, ...
+  true_data_assoc(t) = nn;
+  true_rel_dist(:,t) = true_landmark_pos(:, nn) - true_robot_pos(:,t);
+end
+
+R = 1e-3*eye(2); % noise added to observation
+Q = 1e-3*eye(2); % noise added to robot motion
+
+% Create data set
+obs_noise_seq = sample_gaussian([0 0]', R, T)';
+obs_rel_pos = true_rel_dist + obs_noise_seq;
+%obs_rel_pos = true_rel_dist;
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Create params for inference
+
+% X(t) = A X(t-1) + B U(t) + noise(Q)
+
+% [L1]  = [1     ]  * [L1]       + [0]  * Ut  + [0   ]
+% [L2]    [  1   ]    [L2]         [0]          [ 0  ]
+% [R ]t   [     1]    [R ]t-1      [1]          [   Q]
+
+% Y(t)|S(t)=s  = C(s) X(t) + noise(R)
+% Yt|St=1 = [1 0 -1]  * [L1]  + R
+%                       [L2]    
+%                       [R ]    
+
+% Create indices into block structure
+bs = 2*ones(1, nlandmarks+1); % sizes of blocks in state space
+robot_block =  block(nlandmarks+1, bs);
+for i=1:nlandmarks
+  landmark_block(:,i) = block(i, bs)';
+end
+Xsz = 2*(nlandmarks+1); % 2 values for each landmark plus robot
+Ysz = 2; % observe relative location
+Usz = 2; % input is (dx, dy)
+
+
+% create block-diagonal trans matrix for each switch
+A = zeros(Xsz, Xsz);
+for i=1:nlandmarks
+  bi = landmark_block(:,i);
+  A(bi, bi) = eye(2);
+end
+bi = robot_block;
+A(bi, bi) = eye(2);
+A = repmat(A, [1 1 nlandmarks]); % same for all switch values
+
+% create block-diagonal system cov
+
+
+Qbig = zeros(Xsz, Xsz);
+bi = robot_block;
+Qbig(bi,bi) = Q; % only add noise to robot motion
+Qbig = repmat(Qbig, [1 1 nlandmarks]);
+
+% create input matrix
+B = zeros(Xsz, Usz);
+B(robot_block,:) = eye(2); % only add input to robot position
+B = repmat(B, [1 1 nlandmarks]);
+
+% create observation matrix for each value of the switch node
+% C(:,:,i) = (0 ... I ... -I) where the I is in the i'th posn.
+% This computes L(i) - R
+C = zeros(Ysz, Xsz, nlandmarks);
+for i=1:nlandmarks
+  C(:, landmark_block(:,i), i) = eye(2); 
+  C(:, robot_block, i) = -eye(2);
+end
+
+% create observation cov for each value of the switch node
+Rbig = repmat(R, [1 1 nlandmarks]);
+
+% initial conditions
+init_x = zeros(Xsz, 1);
+init_v = zeros(Xsz, Xsz);
+bi = robot_block;
+init_x(bi) = init_robot_pos;
+init_V(bi, bi) = 1e-5*eye(2); % very sure of robot posn
+for i=1:nlandmarks
+  bi = landmark_block(:,i);
+  init_V(bi,bi)= 1e5*eye(2); % very uncertain of landmark psosns
+  %init_x(bi) = true_landmark_pos(:,i);
+  %init_V(bi,bi)= 1e-5*eye(2); % very sure of landmark psosns
+end
+
+[xsmooth, Vsmooth] = kalman_filter(obs_rel_pos, A, C, Qbig, Rbig, init_x, init_V, ...
+				     'model', true_data_assoc, 'u', ctrl_signal, 'B', B);
+
+est_robot_pos = xsmooth(robot_block, :);
+est_robot_pos_cov = Vsmooth(robot_block, robot_block, :);
+
+for i=1:nlandmarks
+  bi = landmark_block(:,i);
+  est_landmark_pos(:,i) = xsmooth(bi, T);
+  est_landmark_pos_cov(:,:,i) = Vsmooth(bi, bi, T);
+end
+
+
+
+P = zeros(size(Vsmooth));
+for t=1:T
+  P(:,:,t) = inv(Vsmooth(:,:,t));
+end
+
+figure(1)
+for t=1:T
+  subplot(T/2,2,t)
+  imagesc(P(1:2:end,1:2:end, t))
+  colorbar
+end
+
+figure(2)
+for t=1:T
+  subplot(T/2,2,t)
+  imagesc(Vsmooth(1:2:end,1:2:end, t))
+  colorbar
+end
+
+
+
+% marginalize out robot position and then check structure
+bi = landmark_block(:);
+V = Vsmooth(bi,bi,T); 
+P = inv(V);
+P(1:2:end,1:2:end)
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/mk_gmux_robot_dbn.m b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/mk_gmux_robot_dbn.m
new file mode 100644
index 00000000..8ee3a7ca
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/mk_gmux_robot_dbn.m
@@ -0,0 +1,85 @@
+function [bnet, Unode, Snode, Lnodes, Rnode, Ynode, Lsnode] = ...
+    mk_gmux_robot_dbn(nlandmarks, Q, R, init_x, init_V, robot_block, landmark_block)
+
+% Make DBN
+
+% S
+% | L1 -------> L1'
+% |  | L2 ----------> L2'
+% \  | /
+%  v v v
+%    Ls
+%    |
+%    v
+%    Y
+%    ^
+%    |
+%    R ------->  R'
+%    ^      
+%    |      
+%    U      
+%
+%
+% S is a switch, Ls is a deterministic gmux, Y = Ls-R,
+% R(t+1) = R(t) + U(t+1), L(t+1) = L(t)
+
+
+% number nodes topologically
+Snode = 1;
+Lnodes = 2:nlandmarks+1;
+Lsnode = nlandmarks+2;
+Unode = nlandmarks+3;
+Rnode = nlandmarks+4;
+Ynode = nlandmarks+5;
+
+nnodes = nlandmarks+5; 
+intra = zeros(nnodes, nnodes);
+intra([Snode Lnodes], Lsnode) =1;
+intra(Unode,Rnode)=1;
+intra([Rnode Lsnode], Ynode)=1;
+
+inter = zeros(nnodes, nnodes);
+inter(Rnode, Rnode)=1;
+for i=1:nlandmarks
+  inter(Lnodes(i), Lnodes(i))=1;
+end
+
+Lsz = 2; % (x y) posn of landmark
+Rsz = 2; % (x y) posn of robot
+Ysz = 2; % relative distance
+Usz = 2; % (dx dy) ctrl
+Ssz = nlandmarks; % can switch between any landmark
+
+ns = zeros(1,nnodes);
+ns(Snode) = Ssz;
+ns(Lnodes) = Lsz;
+ns(Lsnode) = Lsz;
+ns(Ynode) = Ysz;
+ns(Rnode) = Rsz;
+ns(Ynode) = Usz;
+ns(Unode) = Usz;
+
+bnet = mk_dbn(intra, inter, ns, 'discrete', Snode, 'observed', [Snode Ynode Unode]);
+
+
+bnet.CPD{Snode} = root_CPD(bnet, Snode); % always observed
+bnet.CPD{Unode} = root_CPD(bnet, Unode); % always observed
+for i=1:nlandmarks
+  bi = landmark_block(:,i);
+  bnet.CPD{Lnodes(i)} = gaussian_CPD(bnet, Lnodes(i), 'mean', init_x(bi), 'cov', init_V(bi,bi));
+end
+bi = robot_block;
+bnet.CPD{Rnode} = gaussian_CPD(bnet, Rnode, 'mean', init_x(bi), 'cov', init_V(bi,bi), 'weights', eye(2));
+bnet.CPD{Lsnode} = gmux_CPD(bnet, Lsnode, 'cov', repmat(zeros(Lsz,Lsz), [1 1 nlandmarks]), ...
+			    'weights', repmat(eye(Lsz,Lsz), [1 1 nlandmarks]));
+W = [eye(2) -eye(2)]; % Y = Ls - R, where Ls is the lower-numbered parent
+bnet.CPD{Ynode} = gaussian_CPD(bnet, Ynode, 'mean', zeros(Ysz,1), 'cov', R, 'weights', W);
+
+% slice 2
+eclass = bnet.equiv_class;
+W = [eye(2) eye(2)]; % R(t) = R(t-1) + U(t), where R(t-1) is the lower-numbered parent
+bnet.CPD{eclass(Rnode,2)} = gaussian_CPD(bnet, Rnode+nnodes, 'mean', zeros(Rsz,1), 'cov', Q, 'weights', W);
+for i=1:nlandmarks
+  bnet.CPD{eclass(Lnodes(i), 2)} = gaussian_CPD(bnet, Lnodes(i)+nnodes, 'mean', zeros(2,1), ...
+						   'cov', zeros(2,2), 'weights', eye(2));
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/mk_linear_slam.m b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/mk_linear_slam.m
new file mode 100644
index 00000000..b8a819a2
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/mk_linear_slam.m
@@ -0,0 +1,164 @@
+function [A,B,C,Q,R,Qbig,Rbig,init_x,init_V,robot_block,landmark_block,...
+	  true_landmark_pos, true_robot_pos, true_data_assoc, ...
+	  obs_rel_pos, ctrl_signal] = mk_linear_slam(varargin)
+
+% We create data from a linear system for testing SLAM algorithms.
+% i.e. , new robot pos = old robot pos + ctrl_signal, which is just a displacement vector.
+% and  observation = landmark_pos - robot_pos, which is just a displacement vector.
+%
+% The behavior is determined by the following optional arguments:
+%
+% 'nlandmarks' - num. landmarks
+% 'landmarks' - 'rnd' means random locations in the unit sqyare
+%               'square' means at [1 1], [4 1], [4 4] and [1 4]
+% 'T' - num steps to run
+% 'ctrl' - 'stationary' means the robot remains at [0 0],
+%          'leftright' means the robot receives a constant contol of [1 0],
+%          'square' means we navigate the robot around the square
+% 'data-assoc' - 'rnd' means we observe landmarks at random
+%                'nn' means we observe the nearest neighbor landmark
+%                'cycle' means we observe landmarks in order 1,2,.., 1, 2, ...
+
+args = varargin;
+% get mandatory params
+for i=1:2:length(args)
+  switch args{i},
+   case 'nlandmarks', nlandmarks = args{i+1};
+   case 'T', T = args{i+1};
+  end
+end
+
+% set defaults
+true_landmark_pos = rand(2,nlandmarks);
+true_data_assoc = [];
+
+% get args
+for i=1:2:length(args)
+  switch args{i},
+   case 'landmarks',
+    switch args{i+1},
+     case 'rnd',   true_landmark_pos = rand(2,nlandmarks);
+     case 'square',   true_landmark_pos = [1 1; 4 1; 4 4; 1 4]';
+    end
+   case 'ctrl',
+    switch args{i+1},
+     case 'stationary', ctrl_signal = repmat([0 0]', 1, T);
+     case 'leftright', ctrl_signal = repmat([1 0]', 1, T);
+     case 'square',   ctrl_signal = [repmat([1 0]', 1, T/4) repmat([0 1]', 1, T/4) ...
+		    repmat([-1 0]', 1, T/4) repmat([0 -1]', 1, T/4)];
+    end
+   case 'data-assoc', 
+    switch args{i+1},
+     case 'rnd', true_data_assoc  = sample_discrete(normalise(ones(1,nlandmarks)),1,T);
+     case 'cycle', true_data_assoc = wrap(1:T, nlandmarks);
+    end
+  end
+end
+if isempty(true_data_assoc)
+  use_nn = 1;
+else
+  use_nn = 0;
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%
+% generate data
+
+init_robot_pos = [0 0]';
+true_robot_pos = zeros(2, T);
+true_rel_dist = zeros(2, T);
+for t=1:T
+  if t>1
+    true_robot_pos(:,t) = true_robot_pos(:,t-1) + ctrl_signal(:,t);
+  else
+    true_robot_pos(:,t) = init_robot_pos + ctrl_signal(:,t);
+  end
+  nn = argmin(dist2(true_robot_pos(:,t)', true_landmark_pos'));
+  if use_nn
+    true_data_assoc(t) = nn;
+  end
+  true_rel_dist(:,t) = true_landmark_pos(:, nn) - true_robot_pos(:,t);
+end
+
+
+R = 1e-3*eye(2); % noise added to observation
+Q = 1e-3*eye(2); % noise added to robot motion
+
+% Create data set
+obs_noise_seq = sample_gaussian([0 0]', R, T)';
+obs_rel_pos = true_rel_dist + obs_noise_seq;
+%obs_rel_pos = true_rel_dist;
+
+%%%%%%%%%%%%%%%%%%
+% Create params
+
+
+% X(t) = A X(t-1) + B U(t) + noise(Q) 
+
+% [L1]  = [1     ]  * [L1]       + [0]  * Ut  + [0   ]
+% [L2]    [  1   ]    [L2]         [0]          [ 0  ]
+% [R ]t   [     1]    [R ]t-1      [1]          [   Q]
+
+% Y(t)|S(t)=s  = C(s) X(t) + noise(R)
+% Yt|St=1 = [1 0 -1]  * [L1]  + R
+%                       [L2]    
+%                       [R ]    
+
+% Create indices into block structure
+bs = 2*ones(1, nlandmarks+1); % sizes of blocks in state space
+robot_block =  block(nlandmarks+1, bs);
+for i=1:nlandmarks
+  landmark_block(:,i) = block(i, bs)';
+end
+Xsz = 2*(nlandmarks+1); % 2 values for each landmark plus robot
+Ysz = 2; % observe relative location
+Usz = 2; % input is (dx, dy)
+
+
+% create block-diagonal trans matrix for each switch
+A = zeros(Xsz, Xsz);
+for i=1:nlandmarks
+  bi = landmark_block(:,i);
+  A(bi, bi) = eye(2);
+end
+bi = robot_block;
+A(bi, bi) = eye(2);
+A = repmat(A, [1 1 nlandmarks]); % same for all switch values
+
+% create block-diagonal system cov
+
+
+Qbig = zeros(Xsz, Xsz);
+bi = robot_block;
+Qbig(bi,bi) = Q; % only add noise to robot motion
+Qbig = repmat(Qbig, [1 1 nlandmarks]);
+
+% create input matrix
+B = zeros(Xsz, Usz);
+B(robot_block,:) = eye(2); % only add input to robot position
+B = repmat(B, [1 1 nlandmarks]);
+
+% create observation matrix for each value of the switch node
+% C(:,:,i) = (0 ... I ... -I) where the I is in the i'th posn.
+% This computes L(i) - R
+C = zeros(Ysz, Xsz, nlandmarks);
+for i=1:nlandmarks
+  C(:, landmark_block(:,i), i) = eye(2); 
+  C(:, robot_block, i) = -eye(2);
+end
+
+% create observation cov for each value of the switch node
+Rbig = repmat(R, [1 1 nlandmarks]);
+
+% initial conditions
+init_x = zeros(Xsz, 1);
+init_v = zeros(Xsz, Xsz);
+bi = robot_block;
+init_x(bi) = init_robot_pos;
+%init_V(bi, bi) = 1e-5*eye(2); % very sure of robot posn
+init_V(bi, bi) = Q; % simualate uncertainty due to 1 motion step
+for i=1:nlandmarks
+  bi = landmark_block(:,i);
+  init_V(bi,bi)= 1e5*eye(2); % very uncertain of landmark psosns
+  %init_x(bi) = true_landmark_pos(:,i);
+  %init_V(bi,bi)= 1e-5*eye(2); % very sure of landmark psosns
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/slam_kf.m b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/slam_kf.m
new file mode 100644
index 00000000..9844352b
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/slam_kf.m
@@ -0,0 +1,78 @@
+% Plot how precision matrix changes over time for KF solution
+
+seed = 0;
+rand('state', seed);
+randn('state', seed);
+
+[A,B,C,Q,R,Qbig,Rbig,init_x,init_V,robot_block,landmark_block,...
+	  true_landmark_pos, true_robot_pos, true_data_assoc, ...
+	  obs_rel_pos, ctrl_signal] = mk_linear_slam(...
+	      'nlandmarks', 6, 'T', 12, 'ctrl', 'leftright', 'data-assoc', 'cycle');
+
+figure(1); clf
+hold on
+for i=1:nlandmarks
+  %text(true_landmark_pos(1,i), true_landmark_pos(2,i), sprintf('L%d',i));
+  plot(true_landmark_pos(1,i), true_landmark_pos(2,i), '*')
+end
+hold off
+
+
+[x, V] = kalman_filter(obs_rel_pos, A, C, Qbig, Rbig, init_x, init_V, ...
+				     'model', true_data_assoc, 'u', ctrl_signal, 'B', B);
+
+est_robot_pos = x(robot_block, :);
+est_robot_pos_cov = V(robot_block, robot_block, :);
+
+for i=1:nlandmarks
+  bi = landmark_block(:,i);
+  est_landmark_pos(:,i) = x(bi, T);
+  est_landmark_pos_cov(:,:,i) = V(bi, bi, T);
+end
+
+
+if 0
+figure(1); hold on
+for i=1:nlandmarks
+  h=plotgauss2d(est_landmark_pos(:,i), est_landmark_pos_cov(:,:,i));
+  set(h, 'color', 'r')
+end
+hold off
+
+hold on
+for t=1:T
+  h=plotgauss2d(est_robot_pos(:,t), est_robot_pos_cov(:,:,t));
+  set(h,'color','r')
+  h=text(est_robot_pos(1,t), est_robot_pos(2,2), sprintf('R%d', t));
+  set(h,'color','r')
+end
+hold off
+end
+
+
+P = zeros(size(V));
+for t=1:T
+  P(:,:,t) = inv(V(:,:,t));
+end
+
+if 0
+  figure(2)
+  for t=1:T
+    subplot(T/2,2,t)
+    imagesc(P(1:2:end,1:2:end, t))
+    colorbar
+  end
+else
+  figure(2)
+  for t=1:T
+    subplot(T/2,2,t)
+    imagesc(V(1:2:end,1:2:end, t))
+    colorbar
+  end
+end
+
+% marginalize out robot position and then check structure
+bi = landmark_block(:);
+V = V(bi,bi,T); 
+P = inv(V);
+P(1:2:end,1:2:end)
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/slam_offline_loopy.m b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/slam_offline_loopy.m
new file mode 100644
index 00000000..6abc0fe0
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/slam_offline_loopy.m
@@ -0,0 +1,59 @@
+% Compare Kalman smoother with loopy
+
+seed = 0;
+rand('state', seed);
+randn('state', seed);
+nlandmarks = 6;
+T = 12;
+
+[A,B,C,Q,R,Qbig,Rbig,init_x,init_V,robot_block,landmark_block,...
+	  true_landmark_pos, true_robot_pos, true_data_assoc, ...
+	  obs_rel_pos, ctrl_signal] = mk_linear_slam(...
+	      'nlandmarks', nlandmarks, 'T', T, 'ctrl', 'leftright', 'data-assoc', 'cycle');
+
+[xsmooth, Vsmooth] = kalman_smoother(obs_rel_pos, A, C, Qbig, Rbig, init_x, init_V, ...
+				     'model', true_data_assoc, 'u', ctrl_signal, 'B', B);
+
+est_robot_pos = xsmooth(robot_block, :);
+est_robot_pos_cov = Vsmooth(robot_block, robot_block, :);
+
+for i=1:nlandmarks
+  bi = landmark_block(:,i);
+  est_landmark_pos(:,i) = xsmooth(bi, T);
+  est_landmark_pos_cov(:,:,i) = Vsmooth(bi, bi, T);
+end
+
+
+if 1
+  [bnet, Unode, Snode, Lnodes, Rnode, Ynode, Lsnode] = ...
+      mk_gmux_robot_dbn(nlandmarks, Q, R, init_x, init_V, robot_block, landmark_block);
+  engine = pearl_unrolled_dbn_inf_engine(bnet, 'max_iter', 50, 'filename', ...
+					 '/home/eecs/murphyk/matlab/loopyslam.txt');
+else
+  [bnet, Unode, Snode, Lnodes, Rnode, Ynode] = ...
+      mk_gmux2_robot_dbn(nlandmarks, Q, R, init_x, init_V, robot_block, landmark_block);
+  engine = jtree_dbn_inf_engine(bnet);
+end
+
+nnodes = bnet.nnodes_per_slice;
+evidence = cell(nnodes, T);
+evidence(Ynode, :) = num2cell(obs_rel_pos, 1);
+evidence(Unode, :) = num2cell(ctrl_signal, 1);
+evidence(Snode, :) = num2cell(true_data_assoc);
+
+[engine, ll, niter] = enter_evidence(engine, evidence);
+niter
+
+loopy_est_robot_pos = zeros(2, T);
+for t=1:T
+  m = marginal_nodes(engine, Rnode, t);
+  loopy_est_robot_pos(:,t) = m.mu;
+end
+
+for i=1:nlandmarks
+  m = marginal_nodes(engine, Lnodes(i), T);
+  loopy_est_landmark_pos(:,i) = m.mu;
+  loopy_est_landmark_pos_cov(:,:,i) = m.Sigma;
+end
+
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/slam_partial_kf.m b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/slam_partial_kf.m
new file mode 100644
index 00000000..3fe998be
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/slam_partial_kf.m
@@ -0,0 +1,107 @@
+% See how well partial Kalman filter updates work
+
+seed = 0;
+rand('state', seed);
+randn('state', seed);
+nlandmarks = 6;
+T = 12;
+
+[A,B,C,Q,R,Qbig,Rbig,init_x,init_V,robot_block,landmark_block,...
+	  true_landmark_pos, true_robot_pos, true_data_assoc, ...
+	  obs_rel_pos, ctrl_signal] = mk_linear_slam(...
+	      'nlandmarks', nlandmarks, 'T', T, 'ctrl', 'leftright', 'data-assoc', 'cycle');
+
+% exact
+[xe, Ve] = kalman_filter(obs_rel_pos, A, C, Qbig, Rbig, init_x, init_V, ...
+				     'model', true_data_assoc, 'u', ctrl_signal, 'B', B);
+
+
+% approx
+%k = nlandmarks-1; % exact
+k = 3;
+ndx = {};
+for t=1:T
+  landmarks = unique(true_data_assoc(t:-1:max(t-k,1)));
+  tmp = [landmark_block(:, landmarks) robot_block'];
+  ndx{t} = tmp(:);
+end
+
+[xa, Va] = kalman_filter(obs_rel_pos, A, C, Qbig, Rbig, init_x, init_V, ...
+			 'model', true_data_assoc, 'u', ctrl_signal, 'B', B, ...
+		       'ndx', ndx);
+
+
+
+nrows = 10;
+stepsize = T/(2*nrows);
+ts = 1:stepsize:T;
+
+if 1 % plot
+  
+clim = [0 max(max(Va(:,:,end)))];
+
+figure(2)
+if 0
+  imagesc(Ve(1:2:end,1:2:end, T))
+  clim = get(gca,'clim');
+else
+  i = 1;
+  for t=ts(:)'
+    subplot(nrows,2,i)
+    i = i + 1;
+    imagesc(Ve(1:2:end,1:2:end, t))
+    set(gca, 'clim', clim)
+    colorbar
+  end
+end
+suptitle('exact')
+
+
+figure(3)
+if 0
+  imagesc(Va(1:2:end,1:2:end, T))
+  set(gca,'clim', clim)
+else
+  i = 1;
+  for t=ts(:)'
+    subplot(nrows,2,i)
+    i = i+1;
+    imagesc(Va(1:2:end,1:2:end, t))
+    set(gca, 'clim', clim)
+    colorbar
+  end
+end
+suptitle('approx')
+
+
+figure(4)
+i = 1;
+for t=ts(:)'
+  subplot(nrows,2,i)
+  i = i+1;
+  Vd = Va(1:2:end,1:2:end, t) - Ve(1:2:end,1:2:end,t);
+  imagesc(Vd)
+  set(gca, 'clim', clim)
+  colorbar
+end
+suptitle('diff')
+
+end % all plot
+
+
+for t=1:T
+  %err(t)=rms(xa(:,t), xe(:,t));
+  err(t)=rms(xa(1:end-2,t), xe(1:end-2,t)); % exclude robot
+end
+figure(5);plot(err)
+title('rms mean pos')
+
+
+for t=1:T
+  i = 1:2*nlandmarks;
+  denom = Ve(i,i,t) + (Ve(i,i,t)==0);
+  Vd =(Va(i,i,t)-Ve(i,i,t)) ./ denom;
+  Verr(t) = max(Vd(:));
+end
+figure(6); plot(Verr)
+title('max relative Verr')
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/slam_stationary_loopy.m b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/slam_stationary_loopy.m
new file mode 100644
index 00000000..0272d3f6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/SLAM/slam_stationary_loopy.m
@@ -0,0 +1,155 @@
+% This is like skf_data_assoc_gmux, except the objects don't move.
+% We are uncertain of their initial positions, and get more and more observations
+% over time. The goal is to test deterministic links (0 covariance).
+% This is like robot1, except the robot doesn't move and is always at [0 0],
+% so the relative location is simply L(s).
+
+nobj = 2;
+N = nobj+2;
+Xs = 1:nobj;
+S = nobj+1;
+Y = nobj+2;
+
+intra = zeros(N,N);
+inter = zeros(N,N);
+intra([Xs S], Y) =1;
+for i=1:nobj
+  inter(Xs(i), Xs(i))=1;
+end
+
+Xsz = 2; % state space = (x y)
+Ysz = 2;
+ns = zeros(1,N);
+ns(Xs) = Xsz;
+ns(Y) = Ysz;
+ns(S) = nobj;
+
+bnet = mk_dbn(intra, inter, ns, 'discrete', S, 'observed', [S Y]);
+
+% For each object, we have
+% X(t+1) = F X(t) + noise(Q)
+% Y(t) = H X(t) + noise(R)
+F = eye(2);
+H = eye(2);
+Q = 0*eye(Xsz); % no noise in dynamics
+R = eye(Ysz);
+
+init_state{1} = [10 10]';
+init_state{2} = [10 -10]';
+init_cov = eye(2);
+
+% Uncertain of initial state (position)
+for i=1:nobj
+  bnet.CPD{Xs(i)} = gaussian_CPD(bnet, Xs(i), 'mean', init_state{i}, 'cov', init_cov);
+end
+bnet.CPD{S} = root_CPD(bnet, S); % always observed
+bnet.CPD{Y} = gmux_CPD(bnet, Y, 'cov', repmat(R, [1 1 nobj]), 'weights', repmat(H, [1 1 nobj]));
+% slice 2
+eclass = bnet.equiv_class;
+for i=1:nobj
+  bnet.CPD{eclass(Xs(i), 2)} = gaussian_CPD(bnet, Xs(i)+N, 'mean', zeros(Xsz,1), 'cov', Q, 'weights', F);
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Create LDS params 
+
+% X(t) = A X(t-1) + B U(t) + noise(Q)
+
+% [L11]  = [1  ]  * [L1]       +   [Q ]
+% [L2]     [  1]    [L2]           [ Q]
+
+% Y(t)|S(t)=s  = C(s) X(t) + noise(R)
+% Yt|St=1 = [1 0]  * [L1]  + R
+%                    [L2]    
+
+nlandmarks = nobj;
+
+% Create indices into block structure
+bs = 2*ones(1, nobj); % sizes of blocks in state space
+for i=1:nlandmarks
+  landmark_block(:,i) = block(i, bs)';
+end
+Xsz = 2*(nlandmarks); % 2 values for each landmark plus robot
+Ysz = 2; % observe relative location
+
+% create block-diagonal trans matrix for each switch
+A = zeros(Xsz, Xsz);
+for i=1:nlandmarks
+  bi = landmark_block(:,i);
+  A(bi, bi) = eye(2);
+end
+A = repmat(A, [1 1 nlandmarks]); % same for all switch values
+
+% create block-diagonal system cov
+Qbig = zeros(Xsz, Xsz);
+Qbig = repmat(Qbig, [1 1 nlandmarks]);
+
+
+% create observation matrix for each value of the switch node
+% C(:,:,i) = (0 ... I ...) where the I is in the i'th posn.
+C = zeros(Ysz, Xsz, nlandmarks);
+for i=1:nlandmarks
+  C(:, landmark_block(:,i), i) = eye(2);
+end
+
+% create observation cov for each value of the switch node
+Rbig = repmat(R, [1 1 nlandmarks]);
+
+% initial conditions
+init_x = [init_state{1}; init_state{2}];
+init_V = zeros(Xsz, Xsz);
+for i=1:nlandmarks
+  bi = landmark_block(:,i);
+  init_V(bi,bi) = init_cov;
+end
+
+
+
+%%%%%%%%%%%%%%%%
+% Observe objects at random
+T = 10;
+evidence = cell(N, T);
+data_assoc = sample_discrete(normalise(ones(1,nobj)), 1, T);
+evidence(S,:) = num2cell(data_assoc);
+evidence = sample_dbn(bnet, 'evidence', evidence);
+
+
+% Inference
+ev = cell(N,T);
+ev(bnet.observed,:) = evidence(bnet.observed, :);
+y = cell2num(evidence(Y,:));
+
+engine = pearl_unrolled_dbn_inf_engine(bnet);
+engine = enter_evidence(engine, ev);
+
+loopy_est_pos = zeros(2, nlandmarks);
+loopy_est_pos_cov = zeros(2, 2, nlandmarks);
+for i=1:nobj
+  m = marginal_nodes(engine, Xs(i), T);
+  loopy_est_pos(:,i) = m.mu;
+  loopy_est_pos_cov(:,:,i) = m.Sigma;
+end
+
+
+[xsmooth, Vsmooth] = kalman_smoother(y, A, C, Qbig, Rbig, init_x, init_V, 'model', data_assoc);
+
+kf_est_pos = zeros(2, nlandmarks);
+kf_est_pos_cov = zeros(2, 2, nlandmarks);
+for i=1:nlandmarks
+  bi = landmark_block(:,i);
+  kf_est_pos(:,i) = xsmooth(bi, T);
+  kf_est_pos_cov(:,:,i) = Vsmooth(bi, bi, T);
+end
+
+
+kf_est_pos
+loopy_est_pos
+
+kf_est_pos_time = zeros(2, nlandmarks, T);
+for t=1:T
+  for i=1:nlandmarks
+    bi = landmark_block(:,i);
+    kf_est_pos_time(:,i,t) = xsmooth(bi, t);
+  end
+end
+kf_est_pos_time % same for all t since smoothed
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/arhmm1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/arhmm1.m
new file mode 100644
index 00000000..ac1f7fce
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/arhmm1.m
@@ -0,0 +1,42 @@
+% Make an HMM with autoregressive Gaussian observations (switching AR model)
+%   X1 -> X2
+%   |     | 
+%   v     v
+%   Y1 -> Y2 
+
+seed = 0;
+rand('state', seed);
+randn('state', seed);
+
+intra = zeros(2);
+intra(1,2) = 1;
+inter = zeros(2);
+inter(1,1) = 1;
+inter(2,2) = 1;
+n = 2;
+
+Q = 2; % num hidden states
+O = 2; % size of observed vector
+
+ns = [Q O];
+dnodes = 1;
+onodes = [2];
+bnet = mk_dbn(intra, inter, ns, 'discrete', dnodes, 'observed', onodes);
+
+bnet.CPD{1} = tabular_CPD(bnet, 1);
+bnet.CPD{2} = gaussian_CPD(bnet, 2);
+bnet.CPD{3} = tabular_CPD(bnet, 3);
+bnet.CPD{4} = gaussian_CPD(bnet, 4);
+
+
+T = 10; % fixed length sequences
+
+engine = {};
+%engine{end+1} = hmm_inf_engine(bnet);
+engine{end+1} = jtree_unrolled_dbn_inf_engine(bnet, T);
+%engine{end+1} = smoother_engine(hmm_2TBN_inf_engine(bnet));
+%engine{end+1} = smoother_engine(jtree_2TBN_inf_engine(bnet));
+
+inf_time = cmp_inference_dbn(bnet, engine, T, 'check_ll',1);
+learning_time = cmp_learning_dbn(bnet, engine, T, 'check_ll', 1);
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/bat1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/bat1.m
new file mode 100644
index 00000000..3b24e144
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/bat1.m
@@ -0,0 +1,44 @@
+% Compare the speeds of various inference engines on the BAT DBN
+[bnet, names] = mk_bat_dbn;
+
+T = 3; % fixed length sequence - we make it short just for speed
+
+USEC = exist('@jtree_C_inf_engine/collect_evidence','file');
+
+disp('constructing engines for BAT');
+engine = {}; % time in seconds for inference
+engine{end+1} = jtree_unrolled_dbn_inf_engine(bnet, T, 'useC', USEC);  % 0.39
+engine{end+1} = smoother_engine(jtree_2TBN_inf_engine(bnet)); % 4.89
+engine{end+1} = jtree_dbn_inf_engine(bnet); % 4.45
+if 0
+engine{end+1} = jtree_ndx_dbn_inf_engine(bnet, 'ndx_type', 'SD'); % 2.98
+engine{end+1} = jtree_ndx_dbn_inf_engine(bnet, 'ndx_type', 'D'); % 3.52
+engine{end+1} = jtree_ndx_dbn_inf_engine(bnet, 'ndx_type', 'B'); % 2.40
+if USEC, engine{end+1} = jtree_C_dbn_inf_engine(bnet); end % 3.54
+%engine{end+1} = hmm_inf_engine(bnet, onodes); % too big
+end
+
+%tic; engine{end+1} = frontier_inf_engine(bnet); toc % very slow
+% The frontier engine thrashes badly on the BAT network
+%tic; engine{end+1} = bk_inf_engine(bnet, 'exact', onodes); toc  % SLOW!
+
+%tic; engine{end+1} = bk_inf_engine(bnet, 'ff', onodes); toc
+
+%clusters{1} = [stringmatch({'LeftClr', 'RightClr', 'LatAct', 'Xdot', 'InLane'}, names)];
+%clusters{2} = [stringmatch({'FwdAct', 'Ydot', 'Stopped', 'EngStatus', 'FBStatus'}, names)];      
+
+%tic; engine{end+1} = bk_inf_engine(bnet, clusters, onodes); toc
+
+disp('inference')
+time = cmp_inference_dbn(bnet, engine, T)
+
+disp('learning')
+time = cmp_learning_dbn(bnet, engine, T)
+
+
+
+
+
+
+
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/bkff1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/bkff1.m
new file mode 100644
index 00000000..c5b62332
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/bkff1.m
@@ -0,0 +1,23 @@
+% Compare different implementations of fully factored Boyen Koller
+
+water = 1;
+if water
+  bnet = mk_water_dbn;
+else
+  N = 5;
+  Q = 2;
+  Y = 2;
+  bnet = mk_chmm(N, Q, Y);
+end
+ss = length(bnet.intra);
+
+engine = {};
+engine{end+1} = bk_inf_engine(bnet, 'clusters', 'ff');        
+engine{end+1} = bk_ff_hmm_inf_engine(bnet);   
+E = length(engine);
+
+T = 5;
+time = cmp_inference_dbn(bnet, engine, T, 'singletons_only', 1)
+
+
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/chmm1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/chmm1.m
new file mode 100644
index 00000000..10df79d8
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/chmm1.m
@@ -0,0 +1,41 @@
+% Compare the speeds of various inference engines on a coupled HMM
+
+N = 3;
+Q = 2;
+rand('state', 0);
+randn('state', 0);
+discrete = 0;
+if discrete
+  Y = 2; % size of output alphabet
+else
+  Y = 3; % size of observed vectors
+end
+coupled = 1;
+bnet = mk_chmm(N, Q, Y, discrete, coupled); 
+%bnet = mk_fhmm(N, Q, Y, discrete);  % factorial HMM
+ss = length(bnet.node_sizes_slice);
+
+T = 3;
+
+USEC = exist('@jtree_C_inf_engine/collect_evidence','file');
+
+engine = {};
+engine{end+1} = jtree_dbn_inf_engine(bnet);
+%engine{end+1} = jtree_ndx_dbn_inf_engine(bnet, 'ndx_type', 'SD');
+%engine{end+1} = jtree_ndx_dbn_inf_engine(bnet, 'ndx_type', 'D');
+%engine{end+1} = jtree_ndx_dbn_inf_engine(bnet, 'ndx_type', 'B');
+if USEC, engine{end+1} = jtree_C_dbn_inf_engine(bnet); end
+engine{end+1} = hmm_inf_engine(bnet);
+engine{end+1} = jtree_unrolled_dbn_inf_engine(bnet, T); 
+
+% times in matlab N=4 Q=4 T=5 (* = winner)
+%     jtree    SD       B          hmm       dhmm      unrolled
+%    0.6266    1.1563    8.3815    0.3069    0.1948*    0.8654  inf
+%    0.9057*   2.1522   12.6314    2.6847    2.3107    3.1905  learn
+
+%engine{end+1} = bk_inf_engine(bnet, 'ff', onodes);
+%engine{end+1} = pearl_unrolled_dbn_inf_engine(bnet, T);
+
+inf_time = cmp_inference_dbn(bnet, engine, T)
+learning_time = cmp_learning_dbn(bnet, engine, T)
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/cmp_inference_dbn.m b/sourcecodes/bnt-master/BNT/examples/dynamic/cmp_inference_dbn.m
new file mode 100644
index 00000000..da54095f
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/cmp_inference_dbn.m
@@ -0,0 +1,100 @@
+function [time, engine] = cmp_inference_dbn(bnet, engine, T, varargin)
+% CMP_INFERENCE_DBN Compare several inference engines on a DBN
+% function [time, engine] = cmp_inference_dbn(bnet, engine, T, ...)
+%
+% engine{i} is the i'th inference engine.
+% time(e) = elapsed time for doing inference with engine e
+%
+% The list below gives optional arguments [default value in brackets].
+%
+% exact - specifies which engines do exact inference [ 1:length(engine) ]
+% singletons_only - if 1, we only call marginal_nodes, else this  and marginal_family [0]
+% check_ll - 1 means we check that the log-likelihoods are correct [1]
+
+% set default params
+exact = 1:length(engine);
+singletons_only = 0;
+check_ll = 1;
+onodes = bnet.observed;
+
+args = varargin;
+nargs = length(args);
+for i=1:2:nargs
+  switch args{i},
+   case 'exact', exact = args{i+1};
+   case 'singletons_only', singletons_only = args{i+1};
+   case 'check_ll', check_ll = args{i+1};
+   case 'observed', onodes = args{i+1};
+   otherwise,
+    error(['unrecognized argument ' args{i}])
+  end
+end
+
+E = length(engine);
+ref = exact(1); % reference
+
+ss = length(bnet.intra);
+ev = sample_dbn(bnet, 'length', T);
+evidence = cell(ss,T);
+evidence(onodes,:) = ev(onodes, :);
+
+for i=1:E
+  tic;
+  [engine{i}, ll(i)] = enter_evidence(engine{i}, evidence);
+  time(i)=toc;
+  fprintf('engine %d took %6.4f seconds\n', i, time(i));
+end
+
+cmp = mysetdiff(exact, ref);
+if check_ll
+  for i=cmp(:)'
+    if ~approxeq(ll(ref), ll(i))
+      error(['engine ' num2str(i) ' has wrong ll'])
+    end
+  end
+end
+ll
+
+hnodes = mysetdiff(1:ss, onodes);
+
+if ~singletons_only
+  get_marginals(engine, hnodes, exact, 0, T);
+end
+get_marginals(engine, hnodes, exact, 1, T);
+
+%%%%%%%%%%
+
+function get_marginals(engine, hnodes, exact, singletons, T)
+
+bnet = bnet_from_engine(engine{1});
+N = length(bnet.intra);
+cnodes_bitv = zeros(1,N);
+cnodes_bitv(bnet.cnodes) = 1;
+ref = exact(1); % reference
+cmp = exact(2:end);
+E = length(engine);
+m = cell(1,E);
+
+for t=1:T
+  for n=1:N
+  %for n=hnodes(:)'
+    for e=1:E
+      if singletons
+	m{e} = marginal_nodes(engine{e}, n, t);
+      else
+	m{e} = marginal_family(engine{e}, n, t);
+      end
+    end
+    for e=cmp(:)'
+      assert(isequal(m{e}.domain, m{ref}.domain));
+      if cnodes_bitv(n) & isfield(m{e}, 'mu') & isfield(m{ref}, 'mu')
+	wrong = ~approxeq(m{ref}.mu, m{e}.mu) | ~approxeq(m{ref}.Sigma, m{e}.Sigma);
+      else
+	wrong = ~approxeq(m{ref}.T(:), m{e}.T(:));
+      end
+      if wrong
+	error(sprintf('engine %d is wrong; n=%d, t=%d, fam=%d', e, n, t, ~singletons))
+      end
+    end
+  end
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/cmp_learning_dbn.m b/sourcecodes/bnt-master/BNT/examples/dynamic/cmp_learning_dbn.m
new file mode 100644
index 00000000..d6138f9d
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/cmp_learning_dbn.m
@@ -0,0 +1,89 @@
+function [time, CPD, LL, cases] = cmp_learning_dbn(bnet, engine, T, varargin)
+% CMP_LEARNING_DBN Compare a bunch of inference engines by learning a DBN
+% function [time, CPD, LL, cases] = cmp_learning_dbn(bnet, engine, exact, T, ncases, max_iter)
+%
+% engine{i} is the i'th inference engine.
+% time(e) = elapsed time for doing inference with engine e
+% CPD{e,c} is the learned CPD for eclass c in engine e
+% LL{e} is the learning curve for engine e
+% cases{i} is the i'th training case
+%
+% The list below gives optional arguments [default value in brackets].
+%
+% exact - specifies which engines do exact inference [ 1:length(engine) ]
+% check_ll - 1 means we check that the log-likelihoods are correct [1]
+% ncases - num. random training cases [2]
+% max_iter - max. num EM iterations [2]
+
+% set default params
+exact = 1:length(engine);
+check_ll = 1;
+ncases = 2;
+max_iter = 2;
+
+args = varargin;
+nargs = length(args);
+for i=1:2:nargs
+  switch args{i},
+   case 'exact', exact = args{i+1};
+   case 'check_ll', check_ll = args{i+1};
+   case 'ncases', ncases = args{i+1};
+   case 'max_iter', max_iter = args{i+1};
+   otherwise,
+    error(['unrecognized argument ' args{i}])
+  end
+end
+
+E = length(engine);
+ss = length(bnet.intra);
+onodes = bnet.observed;
+
+cases = cell(1, ncases);
+for i=1:ncases
+  ev = sample_dbn(bnet, 'length', T);
+  cases{i} = cell(ss,T);
+  cases{i}(onodes,:) = ev(onodes, :);
+end
+
+LL = cell(1,E);
+time = zeros(1,E);
+for i=1:E
+  tic
+  [bnet2{i}, LL{i}] = learn_params_dbn_em(engine{i}, cases, 'max_iter', max_iter);
+  time(i) = toc;
+  fprintf('engine %d took %6.4f seconds\n', i, time(i));
+end
+
+ref = exact(1); % reference
+cmp = mysetdiff(exact, ref);
+if check_ll
+  for i=cmp(:)'
+    if ~approxeq(LL{ref}, LL{i})
+      error(['engine ' num2str(i) ' has wrong ll'])
+    end
+  end
+end
+
+nCPDs = length(bnet.CPD);
+CPD = cell(E, nCPDs);
+tabular = zeros(1, nCPDs);
+for i=1:E
+  temp = bnet2{i};
+  for c=1:nCPDs
+    tabular(c) = isa(temp.CPD{c}, 'tabular_CPD');
+    CPD{i,c} = struct(temp.CPD{c});
+  end
+end
+
+for i=cmp(:)'
+  for c=1:nCPDs
+    if tabular(c)
+      assert(approxeq(CPD{i,c}.CPT, CPD{ref,c}.CPT));
+    else
+      assert(approxeq(CPD{i,c}.mean, CPD{ref,c}.mean));
+      assert(approxeq(CPD{i,c}.cov, CPD{ref,c}.cov));
+      assert(approxeq(CPD{i,c}.weights, CPD{ref,c}.weights));
+    end
+  end
+end
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/cmp_online_inference.m b/sourcecodes/bnt-master/BNT/examples/dynamic/cmp_online_inference.m
new file mode 100644
index 00000000..5360d120
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/cmp_online_inference.m
@@ -0,0 +1,97 @@
+function [time, engine] = cmp_online_inference(bnet, engine, T, varargin)
+% CMP_ONLINE_INFERENCE Compare several online inference engines on a DBN
+% function [time, engine] = cmp_online_inference(bnet, engine, T, ...)
+%
+% engine{i} is the i'th inference engine.
+% time(e) = elapsed time for doing inference with engine e
+%
+% The list below gives optional arguments [default value in brackets].
+%
+% exact - specifies which engines do exact inference [ 1:length(engine) ]
+% singletons_only - if 1, we only call marginal_nodes, else this  and marginal_family [0]
+% check_ll - 1 means we check that the log-likelihoods are correct [1]
+
+% set default params
+exact = 1:length(engine);
+singletons_only = 0;
+check_ll = 1;
+onodes = bnet.observed;
+
+args = varargin;
+nargs = length(args);
+for i=1:2:nargs
+  switch args{i},
+   case 'exact', exact = args{i+1};
+   case 'singletons_only', singletons_only = args{i+1};
+   case 'check_ll', check_ll = args{i+1};
+   case 'observed', onodes = args{i+1};
+   otherwise,
+    error(['unrecognized argument ' args{i}])
+  end
+end
+
+E = length(engine);
+ref = exact(1); % reference
+cmp = mysetdiff(exact, ref);
+
+ss = length(bnet.intra);
+hnodes = mysetdiff(1:ss, onodes);
+ev = sample_dbn(bnet, 'length', T);
+evidence = cell(ss,T);
+evidence(onodes,:) = ev(onodes, :);
+
+time = zeros(1,E);
+for t=1:T
+  for e=1:E
+    tic;
+    [engine{e}, ll(e)] = enter_evidence(engine{e}, evidence(:,t), t);
+    time(e)= time(e) + toc;
+  end
+  if check_ll
+    for e=cmp(:)'
+      if ~approxeq(ll(ref), ll(e))
+	error(['engine ' num2str(e) ' has wrong ll'])
+      end
+    end
+  end
+  if ~singletons_only
+    check_marginals(engine, hnodes, exact, 0, t);
+  end
+  check_marginals(engine, hnodes, exact, 1, t);
+end
+
+
+%%%%%%%%%%
+
+function check_marginals(engine, hnodes, exact, singletons, t)
+
+bnet = bnet_from_engine(engine{1});
+N = length(bnet.intra);
+cnodes_bitv = zeros(1,N);
+cnodes_bitv(bnet.cnodes) = 1;
+ref = exact(1); % reference
+cmp = exact(2:end);
+E = length(engine);
+m = cell(1,E);
+
+for n=1:N
+  %for n=hnodes(:)'
+  for e=1:E
+    if singletons
+      m{e} = marginal_nodes(engine{e}, n, t);
+    else
+      m{e} = marginal_family(engine{e}, n, t);
+    end
+  end
+  for e=cmp(:)'
+    assert(isequal(m{e}.domain, m{ref}.domain));
+    if cnodes_bitv(n) & isfield(m{e}, 'mu') & isfield(m{ref}, 'mu')
+      wrong = ~approxeq(m{ref}.mu, m{e}.mu) | ~approxeq(m{ref}.Sigma, m{e}.Sigma);
+    else
+      wrong = ~approxeq(m{ref}.T(:), m{e}.T(:));
+    end
+    if wrong
+      error(sprintf('engine %d is wrong; n=%d, t=%d, fam=%d', e, n, t, ~singletons))
+    end
+  end
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/dhmm1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/dhmm1.m
new file mode 100644
index 00000000..a3c4084d
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/dhmm1.m
@@ -0,0 +1,66 @@
+% Make an HMM with discrete observations
+%   X1 -> X2
+%   |     | 
+%   v     v
+%   Y1    Y2 
+
+intra = zeros(2);
+intra(1,2) = 1;
+inter = zeros(2);
+inter(1,1) = 1;
+n = 2;
+
+Q = 2; % num hidden states
+O = 2; % num observable symbols
+
+ns = [Q O];
+dnodes = 1:2;
+onodes = [2];
+eclass1 = [1 2];
+eclass2 = [3 2];
+bnet = mk_dbn(intra, inter, ns, 'discrete', dnodes, 'eclass1', eclass1, 'eclass2', eclass2, ...
+	      'observed', onodes);
+
+rand('state', 0);
+prior1 = normalise(rand(Q,1));
+transmat1 = mk_stochastic(rand(Q,Q));
+obsmat1 = mk_stochastic(rand(Q,O));
+bnet.CPD{1} = tabular_CPD(bnet, 1, prior1);
+bnet.CPD{2} = tabular_CPD(bnet, 2, obsmat1);
+bnet.CPD{3} = tabular_CPD(bnet, 3, transmat1);
+
+
+T = 5; % fixed length sequences
+
+engine = {};
+engine{end+1} = jtree_unrolled_dbn_inf_engine(bnet, T);
+engine{end+1} = hmm_inf_engine(bnet);
+engine{end+1} = smoother_engine(hmm_2TBN_inf_engine(bnet));
+engine{end+1} = smoother_engine(jtree_2TBN_inf_engine(bnet));
+if 1
+%engine{end+1} = frontier_inf_engine(bnet); % broken
+engine{end+1} = bk_inf_engine(bnet, 'clusters', {[1]});
+engine{end+1} = jtree_dbn_inf_engine(bnet);
+end
+
+inf_time = cmp_inference_dbn(bnet, engine, T);
+
+ncases = 2;
+max_iter = 2;
+[learning_time, CPD, LL, cases] = cmp_learning_dbn(bnet, engine, T, 'ncases', ncases, 'max_iter', max_iter);
+
+% Compare to HMM toolbox
+
+data = zeros(ncases, T);
+for i=1:ncases
+  %data(i,:) = cat(2, cases{i}{onodes,:});
+  data(i,:) = cell2num(cases{i}(onodes,:));
+end
+[LL2, prior2, transmat2, obsmat2] = dhmm_em(data, prior1, transmat1, obsmat1, 'max_iter', max_iter);
+
+e = 1;
+assert(approxeq(prior2, CPD{e,1}.CPT))
+assert(approxeq(obsmat2, CPD{e,2}.CPT))
+assert(approxeq(transmat2, CPD{e,3}.CPT))
+assert(approxeq(LL2, LL{e}))        
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/ehmm1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/ehmm1.m
new file mode 100644
index 00000000..d6af4147
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/ehmm1.m
@@ -0,0 +1,24 @@
+% make the structure of an embedded HMM with 2 rows and 3 columns
+
+% 1------------>2
+% |\   \        | \  \
+% 3->4->5       6->7->8
+
+n = 8;
+dag = zeros(n);
+dag(1,[2 3 4 5])=1;
+dag(2,[6 7 8])=1;
+for i=3:4
+  dag(i,i+1)=1;
+end
+for i=6:7
+  dag(i,i+1)=1;
+end
+ns = 2*ones(1,n);
+bnet = mk_bnet(dag,ns);
+for i=1:n
+  bnet.CPD{i}=tabular_CPD(bnet,i);
+end
+[jtree, root, cliques] =  graph_to_jtree(moralize(bnet.dag), ones(1,n), {}, {});
+%[jtree, root, cliques, B, w, elim_order, moral_edges, fill_in_edges] = dag_to_jtree(bnet);
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/fhmm_infer.m b/sourcecodes/bnt-master/BNT/examples/dynamic/fhmm_infer.m
new file mode 100644
index 00000000..62eec4a3
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/fhmm_infer.m
@@ -0,0 +1,324 @@
+function [loglik, gamma] = fhmm_infer(inter, CPTs_slice1, CPTs, obsmat, node_sizes)
+% FHMM_INFER Exact inference for a factorial HMM.
+% [loglik, gamma] = fhmm_infer(inter, CPTs_slice1, CPTs, obsmat, node_sizes)
+%
+% Inputs:
+% inter - the inter-slice adjacency matrix
+% CPTs_slice1{s}(j) = Pr(Q(s,1) = j) where Q(s,t) = hidden node s in slice t
+% CPT{s}(i1, i2, ..., j) = Pr(Q(s,t) = j | Pa(s,t-1) = i1, i2, ...),
+% obsmat(i,t) = Pr(y(t) | Q(t)=i)
+% node_sizes is a vector with the cardinality of the hidden nodes
+%
+% Outputs:
+% gamma(i,t) = Pr(X(t)=i | O(1:T)) as in an HMM,
+% except that i is interpreted as an M digit, base-K number (if there are M chains each of cardinality K).
+%
+%
+% For M chains each of cardinality K, the frontiers  (i.e., cliques)
+% contain M+1 nodes, and it takes M steps to advance the frontier by one time step,
+% so the run time is O(T M K^(M+1)).
+% An HMM takes O(T S^2) where S is the size of the state space.
+% Collapsing the FHMM to an HMM results in S = K^M.
+% For details, see
+%   "The Factored Frontier Algorithm for Approximate Inference in DBNs",
+%    Kevin Murphy and Yair Weiss, submitted to NIPS 2000.
+%
+% The frontier algorithm makes the following topological assumptions:
+% 
+%  - All nodes are persistent (connect to the next slice)
+%  - No connections within a timeslice
+%  - There is a single observation variable, which depends on all the hidden nodes
+%  - Each node can have several parents in the previous time slice (generalizes a FHMM slightly)
+%
+
+% The forwards pass of the frontier algorithm can be explained with the following example.
+% Suppose we have 3 hidden nodes per slice, A, B, C.
+% The goal is to compute alpha(j, t) = Pr( (A_t,B_t,C_t)=j | Y(1:t))
+% We move alpha from t to t+1 one node at a time, as follows.
+% We define the following quantities:
+% s([a1 b1 c1], 1) = Prob(A(t)=a1, B(t)=b1, C(t)=c1 | Y(1:t)) = alpha(j, t)
+% s([a2 b1 c1], 2) = Prob(A(t+1)=a2, B(t)=b1, C(t)=c1 | Y(1:t))
+% s([a2 b2 c1], 3) = Prob(A(t+1)=a2, B(t+1)=b2, C(t)=c1 | Y(1:t))
+% s([a2 b2 c2], 4) = Prob(A(t+1)=a2, B(t+1)=b2, C(t+1)=c2 | Y(1:t))
+% s([a2 b2 c2], 5) = Prob(A(t+1)=a2, B(t+1)=b2, C(t+1)=c2 | Y(1:t+1)) = alpha(j, t+1)
+%
+% These can be computed recursively as follows:
+%
+% s([a2 b1 c1], 2) = sum_{a1} P(a2|a1) s([a1 b1 c1], 1)
+% s([a2 b2 c1], 3) = sum_{b1} P(b2|b1) s([a2 b1 c1], 2)
+% s([a2 b2 c2], 4) = sum_{c1} P(c2|c1) s([a2 b2 c1], 1)
+% s([a2 b2 c2], 5) = normalise( s([a2 b2 c2], 4) .* P(Y(t+1)|a2,b2,c2)
+
+
+[kk,ll,mm] = make_frontier_indices(inter, node_sizes); % can pass in as args
+
+scaled = 1;
+
+M = length(node_sizes);
+S = prod(node_sizes);
+T = size(obsmat, 2);
+
+alpha = zeros(S, T);
+beta = zeros(S, T);
+gamma = zeros(S, T);
+scale = zeros(1,T);
+tiny = exp(-700);
+
+
+alpha(:,1) = make_prior_from_CPTs(CPTs_slice1, node_sizes);
+alpha(:,1) = alpha(:,1) .* obsmat(:, 1);
+
+if scaled
+  s = sum(alpha(:,1));
+  if s==0, s = s + tiny; end
+  scale(1) = 1/s;
+else
+  scale(1) = 1;
+end
+alpha(:,1) = alpha(:,1) * scale(1);
+
+%a = zeros(S, M+1);
+%b = zeros(S, M+1);
+anew = zeros(S,1);
+aold = zeros(S,1);
+bnew = zeros(S,1);
+bold = zeros(S,1);
+
+for t=2:T
+  %a(:,1) = alpha(:,t-1);
+  aold =  alpha(:,t-1);
+  
+  c = 1;
+  for i=1:M
+    ns = node_sizes(i);
+    cpt = CPTs{i};
+    for j=1:S
+      s = 0;
+      for xx=1:ns
+	%k = kk(xx,j,i);
+	%l = ll(xx,j,i);
+	k = kk(c);
+	l = ll(c);
+	c = c + 1;
+	% s = s + a(k,i) * CPTs{i}(l);
+	s = s + aold(k) * cpt(l);
+      end
+      %a(j,i+1) = s;
+      anew(j) = s;
+    end
+    aold = anew;
+  end
+  
+  %alpha(:,t) = a(:,M+1) .* obsmat(:, obs(t));
+  alpha(:,t) = anew .* obsmat(:, t);
+
+  if scaled
+    s = sum(alpha(:,t));
+    if s==0, s = s + tiny; end
+    scale(t) = 1/s;
+  else
+    scale(t) = 1;
+  end
+  alpha(:,t) = alpha(:,t) * scale(t);
+
+end
+
+
+beta(:,T) = ones(S,1) * scale(T);
+for t=T-1:-1:1
+  %b(:,1) = beta(:,t+1) .* obsmat(:, obs(t+1));
+  bold = beta(:,t+1) .* obsmat(:, t+1);
+
+  c = 1;
+  for i=1:M
+    ns = node_sizes(i);
+    cpt = CPTs{i};
+    for j=1:S
+      s = 0;
+      for xx=1:ns
+	%k = kk(xx,j,i);
+	%m = mm(xx,j,i);
+	k = kk(c);
+	m = mm(c);
+	c = c + 1;
+	% s = s + b(k,i) * CPTs{i}(m);
+	s = s + bold(k) * cpt(m);
+      end
+      %b(j,i+1) = s;
+      bnew(j) = s;
+    end
+    bold = bnew;
+  end
+  % beta(:,t) = b(:,M+1) * scale(t);
+  beta(:,t) = bnew * scale(t);
+end
+
+
+if scaled
+  loglik = -sum(log(scale)); % scale(i) is finite
+else
+  lik = alpha(:,1)' * beta(:,1);
+  loglik = log(lik+tiny);
+end
+
+for t=1:T
+  gamma(:,t) = normalise(alpha(:,t) .* beta(:,t));
+end
+
+%%%%%%%%%%%
+
+function [kk,ll,mm] = make_frontier_indices(inter, node_sizes)
+%
+% Precompute indices for use in the frontier algorithm.
+% These only depend on the topology, not the parameters or data.
+% Hence we can compute them outside of fhmm_infer.
+% This saves a lot of run-time computation.
+
+M = length(node_sizes);
+S = prod(node_sizes);
+
+mns = max(node_sizes);
+kk = zeros(mns, S, M);
+ll = zeros(mns, S, M);
+mm = zeros(mns, S, M);
+
+for i=1:M
+  for j=1:S
+    u = ind2subv(node_sizes, j);
+    x = u(i);
+    for xx=1:node_sizes(i)
+      uu = u;
+      uu(i) = xx;
+      k = subv2ind(node_sizes, uu);
+      kk(xx,j,i) = k;
+      ps = find(inter(:,i)==1);
+      ps = ps(:)';
+      l = subv2ind(node_sizes([ps i]), [uu(ps) x]); % sum over parent
+      ll(xx,j,i) = l;
+      m = subv2ind(node_sizes([ps i]), [u(ps) xx]); % sum over child
+      mm(xx,j,i) = m;
+    end
+  end
+end
+
+%%%%%%%%%
+
+function prior=make_prior_from_CPTs(indiv_priors, node_sizes)
+%
+% composite_prior=make_prior(individual_priors, node_sizes)
+% Make the prior for the first node in a Markov chain
+% from the priors on each node in the equivalent DBN.
+% prior{i}(j) = Pr(X_i=j), where X_i is the i'th node in slice 1.
+% composite_prior(i) = Pr(slice1 = i).
+
+n = length(indiv_priors);
+S = prod(node_sizes);
+prior = zeros(S,1);
+for i=1:S
+  vi = ind2subv(node_sizes, i);
+  p = 1;
+  for k=1:n
+    p = p * indiv_priors{k}(vi(k));
+  end
+  prior(i) = p;
+end
+
+
+
+%%%%%%%%%%%
+
+function [loglik, alpha, beta] = FHMM_slow(inter, CPTs_slice1, CPTs, obsmat, node_sizes, data)
+% 
+% Same as the above, except we don't use the optimization of computing the indices outside the loop.
+
+
+scaled = 1;
+
+M = length(node_sizes);
+S = prod(node_sizes);
+[numex T] = size(data);
+
+obs = data;
+
+alpha = zeros(S, T);
+beta = zeros(S, T);
+a = zeros(S, M+1);
+b = zeros(S, M+1);
+scale = zeros(1,T);
+
+alpha(:,1) = make_prior_from_CPTs(CPTs_slice1, node_sizes);
+alpha(:,1) = alpha(:,1) .* obsmat(:, obs(1));
+if scaled
+  s = sum(alpha(:,1));
+  if s==0, s = s + tiny; end
+  scale(1) = 1/s;
+else
+  scale(1) = 1;
+end
+alpha(:,1) = alpha(:,1) * scale(1);
+
+for t=2:T
+  fprintf(1, 't %d\n', t);
+  a(:,1) = alpha(:,t-1);
+  for i=1:M
+    for j=1:S
+      u = ind2subv(node_sizes, j);
+      xnew = u(i);
+      s = 0;
+      for xold=1:node_sizes(i)
+	uold = u;
+	uold(i) = xold;
+	k = subv2ind(node_sizes, uold);
+	ps = find(inter(:,i)==1);
+	ps = ps(:)';
+	l = subv2ind(node_sizes([ps i]), [uold(ps) xnew]);
+	s = s + a(k,i) * CPTs{i}(l);
+      end
+      a(j,i+1) = s;
+    end
+  end
+  alpha(:,t) = a(:,M+1) .* obsmat(:, obs(t));
+
+  if scaled
+    s = sum(alpha(:,t));
+    if s==0, s = s + tiny; end
+    scale(t) = 1/s;
+  else
+    scale(t) = 1;
+  end
+  alpha(:,t) = alpha(:,t) * scale(t);
+
+end
+
+
+beta(:,T) = ones(S,1) * scale(T);
+for t=T-1:-1:1
+  fprintf(1, 't %d\n', t);
+  b(:,1) = beta(:,t+1) .* obsmat(:, obs(t+1));
+  for i=1:M
+    for j=1:S
+      u = ind2subv(node_sizes, j);
+      xold = u(i);
+      s = 0;
+      for xnew=1:node_sizes(i)
+	unew = u;
+	unew(i) = xnew;
+	k = subv2ind(node_sizes, unew);
+	ps = find(inter(:,i)==1);
+	ps = ps(:)';
+	l = subv2ind(node_sizes([ps i]), [u(ps) xnew]);
+	s = s + b(k,i) * CPTs{i}(l);
+      end
+      b(j,i+1) = s;
+    end
+  end
+  beta(:,t) = b(:,M+1) * scale(t);
+end
+
+
+if scaled
+  loglik = -sum(log(scale)); % scale(i) is finite
+else
+  lik = alpha(:,1)' * beta(:,1);
+  loglik = log(lik+tiny);
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/filter_test1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/filter_test1.m
new file mode 100644
index 00000000..9e65508a
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/filter_test1.m
@@ -0,0 +1,24 @@
+% Compare online filtering algorithms on some DBNs
+
+seed = 0;
+rand('state', seed);
+randn('state', seed);
+
+if 0
+  N = 3;
+  Q = 2;
+  obs_size = 1;
+  discrete_obs = 0;
+  bnet = mk_chmm(N, Q, obs_size, discrete_obs);
+else
+  %bnet = mk_bat_dbn;
+  bnet = mk_water_dbn;
+end
+
+T = 3;
+
+engine = {};
+engine{end+1} = filter_engine(hmm_2TBN_inf_engine(bnet));
+engine{end+1} = filter_engine(jtree_2TBN_inf_engine(bnet));
+
+time = cmp_online_inference(bnet, engine, T);
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/ghmm1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/ghmm1.m
new file mode 100644
index 00000000..8590a25a
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/ghmm1.m
@@ -0,0 +1,64 @@
+% Make an HMM with Gaussian observations
+%   X1 -> X2
+%   |     | 
+%   v     v
+%   Y1    Y2 
+
+intra = zeros(2);
+intra(1,2) = 1;
+inter = zeros(2);
+inter(1,1) = 1;
+n = 2;
+
+Q = 2; % num hidden states
+O = 2; % size of observed vector
+ns = [Q O];
+bnet = mk_dbn(intra, inter, ns, 'discrete', 1, 'observed', 2);
+
+prior0 = normalise(rand(Q,1));
+transmat0 = mk_stochastic(rand(Q,Q));
+mu0 = rand(O,Q);
+Sigma0 = repmat(eye(O), [1 1 Q]);
+bnet.CPD{1} = tabular_CPD(bnet, 1, prior0);
+%% we set the cov prior to 0 to give same results as HMM toolbox
+%bnet.CPD{2} = gaussian_CPD(bnet, 2, 'mean', mu0, 'cov', Sigma0, 'cov_prior_weight', 0);
+bnet.CPD{2} = gaussian_CPD(bnet, 2, 'mean', mu0, 'cov', Sigma0);
+bnet.CPD{3} = tabular_CPD(bnet, 3, transmat0);
+
+
+T = 5; % fixed length sequences
+
+engine = {};
+engine{end+1} = smoother_engine(jtree_2TBN_inf_engine(bnet));
+engine{end+1} = smoother_engine(hmm_2TBN_inf_engine(bnet));
+engine{end+1} = hmm_inf_engine(bnet);
+engine{end+1} = jtree_unrolled_dbn_inf_engine(bnet, T);
+%engine{end+1} = frontier_inf_engine(bnet);
+engine{end+1} = bk_inf_engine(bnet, 'clusters', {[1]});
+engine{end+1} = jtree_dbn_inf_engine(bnet);
+
+
+inf_time = cmp_inference_dbn(bnet, engine, T);
+
+ncases = 2;
+max_iter = 2;
+[learning_time, CPD, LL, cases] = cmp_learning_dbn(bnet, engine, T, 'ncases', ncases, 'max_iter', max_iter);
+
+% Compare to HMM toolbox
+
+data = zeros(O, T, ncases);
+for i=1:ncases
+  data(:,:,i) = cell2num(cases{i}(bnet.observed, :));  
+end
+
+tic
+[LL2, prior2, transmat2, mu2, Sigma2] = mhmm_em(data, prior0, transmat0, mu0, Sigma0, [],  'max_iter', max_iter);
+t=toc;
+disp(['HMM toolbox took ' num2str(t) ' seconds '])
+
+e = 1;
+assert(approxeq(prior2, CPD{e,1}.CPT))
+assert(approxeq(mu2, CPD{e,2}.mean))
+assert(approxeq(Sigma2, CPD{e,2}.cov))
+assert(approxeq(transmat2, CPD{e,3}.CPT))
+assert(approxeq(LL2, LL{e}))
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/ho1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/ho1.m
new file mode 100644
index 00000000..b6825ce1
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/ho1.m
@@ -0,0 +1,156 @@
+function ho1()
+
+% Example of how to create a higher order DBN
+% Written by Rainer Deventer <deventer@informatik.uni-erlangen.de> 3/28/03
+
+bnet = createBNetNL();
+
+%%%%%%%%%%%%
+
+
+function bnet = createBNetNL(varargin)
+     % Generate a Bayesian network, which is able to model nonlinearities at
+% the input. The only input is the order of the dynamic system. If this 
+% parameter is missing, the an order of two is assumed
+if nargin > 0 
+    order = varargin{1}
+else
+    order = 2;
+end
+
+ss = 6; % For each time slice the following nodes are modeled
+        % ud(t_k) Discrete node, which decides whether saturation is reached.
+        %         Node number 2
+        % uv(t_k) Visible input node with node number  2
+        % uh(t_k) Hidden  input node with node number 3     
+        % y(t_k)  Modeled output, Number 4
+        % z(t_k)  Disturbing variable, number 5
+        % q(t_k), number6 6
+
+intra = zeros(ss,ss);
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Within each timeslice ud(t_k) is connected with uv(t_k) and uh(t_k)    %
+% This part is used to model saturation                                  %
+% A connection from  uv(t_k) to uh(t_k) is omitted                       %
+% Additionally   y(t_k) is connected with q(t_k). To model the disturbing%
+% value z(t_k) is connected with q(t_k).                                 %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+intra(1,2:3) = 1; % Connections ud(t_k) -> uv(t_k) and ud(t_k) -> uh(t_k)
+intra(4:5,6) = 1; % Connectios  y(t_k)  -> q(t_k)  and z(t_k)  -> q(t_k) 
+
+
+  
+inter = zeros(ss,ss,order);
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% The Markov assumption is not met as connections from time slice t to t+2 %
+% exist.                                                                   %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+for i = 1:order
+    if i == 1
+        inter(1,1,i) = 1; %Connect the discrete nodes. This is necessary to improve
+                          %the disturbing reaction
+        inter(3,4,i) = 1; %Connect uh(t_{k-1}) with y(t_k)
+        inter(4,4,i) = 1; %Connect y(t_{k-1})  with y(t_k)    
+        inter(5,5,i) = 1; %Connect z(t_{k-1})  with z(t_k)
+    else
+        inter(3,4,i) = 1; %Connect uh(t_{k-i}) with y(t_k)
+        inter(4,4,i) = 1; %Connect  y(t_{k-i}) with y(t_k)
+    end
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Define the dimensions of the discrete nodes. Node 1 has two states     %
+% 1 = lower saturation reached                                           %
+% 2 = Upper saturation reached                                           %
+% Values in between are model by probabilities between 0 and 1           %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+node_sizes = ones(1,ss);
+node_sizes(1) = 2;
+dnodes = [1];
+
+eclass = [1:6;7 2:3 8 9 6;7 2:3 10 11 6];
+bnet = mk_higher_order_dbn(intra,inter,node_sizes,...
+                           'discrete',dnodes,...
+                           'eclass',eclass);
+
+cov_high = 400;
+cov_low  = 0.01;
+weight1 = randn(1,1);
+weight2 = randn(1,1);
+weight3 = randn(1,1);
+weight4 = randn(1,1);
+
+numOfNodes = 5 + order;
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Nodes of the first time-slice   %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Discrete input node, 
+bnet.CPD{1} = tabular_CPD(bnet,1,'CPT',[1/2 1/2],'adjustable',0);
+
+
+% Modeled visible input
+bnet.CPD{2} = gaussian_CPD(bnet,2,'mean',[0 10],'clamp_mean',1,...
+                            'cov',[10 10],'clamp_cov',1);
+
+% Modeled hidden input
+bnet.CPD{3} = gaussian_CPD(bnet,3,'mean',[0, 10],'clamp_mean',1,...
+			          'cov',[0.1 0.1],'clamp_cov',1);
+
+% Modeled output in the first timeslice, thus there are no parents
+% Usuallz the output nodes get a low covariance. But in the first
+% time-slice a prediction of the output is not possible due to 
+% missing information
+bnet.CPD{4} = gaussian_CPD(bnet,4,'mean',0,'clamp_mean',1,...
+			          'cov',cov_high,'clamp_cov',1);
+
+%Disturbance
+bnet.CPD{5} = gaussian_CPD(bnet,5,'mean',0,...
+                                  'cov',[4],...
+                                  'clamp_mean',1,...
+                                  'clamp_cov',1);
+
+%Observed output. 
+bnet.CPD{6} = gaussian_CPD(bnet,6,'mean',0,...
+                                  'clamp_mean',1,...
+                                  'cov',cov_low,'clamp_cov',1,...
+                                  'weights',[1 1],'clamp_weights',1);
+
+% Discrete node at second time slice
+bnet.CPD{7} = tabular_CPD(bnet,7,'CPT',[0.6 0.4 0.4 0.6],'adjustable',0);
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Node for the model output %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+bnet.CPD{8} = gaussian_CPD(bnet,10,'mean',0,...
+				   'cov',cov_high,...
+				   'clamp_mean',1,...
+			           'clamp_cov',1);
+%                                   'weights',[0.0791 0.9578]);
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Node for the disturbance %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%                        
+bnet.CPD{9} = gaussian_CPD(bnet,11,'mean',0,'clamp_mean',1,...
+                                   'cov',[4],'clamp_cov',1,...
+                                   'weights',[1],'clamp_weights',1);
+                                   
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Node for the model output %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+bnet.CPD{10} = gaussian_CPD(bnet,16,'mean',0,'clamp_mean',1,...
+                                    'cov',cov_low,'clamp_cov',1);
+%                                   'weights',[0.0188 -0.0067 0.0791 0.9578]);
+
+
+
+    
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Node for the disturbance %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%                        
+bnet.CPD{11} = gaussian_CPD(bnet,17,'mean',0,'clamp_mean',1,...
+                                           'cov',[0.2],'clamp_cov',1,...
+                                           'weights',[1],'clamp_weights',1);
+
+
+
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/jtree_clq_test.m b/sourcecodes/bnt-master/BNT/examples/dynamic/jtree_clq_test.m
new file mode 100644
index 00000000..647a2763
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/jtree_clq_test.m
@@ -0,0 +1,150 @@
+% Construct various DBNs and examine their clique structure.
+% This was used to generate various figures in chap 3-4 of my thesis.
+
+% Examine the cliques in the unrolled mildew net
+
+%dbn = mk_mildew_dbn;
+dbn = mk_chmm(4);
+ss = dbn.nnodes_per_slice;
+T = 7;
+N = ss*T;
+bnet = dbn_to_bnet(dbn, T);
+
+constrained = 0;
+if constrained
+  stages = num2cell(unroll_set(1:ss, ss, T), 1);
+else
+  stages = { 1:N; };
+end
+clusters = {};
+%[jtree, root, cliques, B, w, elim_order, moral_edges, fill_in_edges] = ...
+%    dag_to_jtree(bnet, bnet.observed, stages, clusters);
+[jtree, root, cliques] =  graph_to_jtree(moralize(bnet.dag), ones(1,N), stages, clusters);
+
+flip=1;
+clf;[dummyx, dummyy, h] = draw_dbn(dbn.intra, dbn.inter, flip, T, -1);
+dir = '/home/eecs/murphyk/WP/Thesis/Figures/Inf/MildewUnrolled';
+mk_ps_from_clqs(dbn, T, cliques, [])
+%mk_collage_from_clqs(dir, cliques)
+
+
+% Examine the cliques in the cascade DBN
+
+% A-A
+%  \
+% B B
+%  \
+% C C
+%  \
+% D D
+ss = 4;
+intra = zeros(ss);
+inter = zeros(ss);
+inter(1, [1 2])=1;
+for i=2:ss-1
+  inter(i,i+1)=1;
+end
+
+
+% 2 coupled HMMs 1,3  and 2,4
+ss = 4;
+intra = zeros(ss);
+inter = zeros(ss); % no persistent edges
+%inter = diag(ones(ss,1)); % persitence edges
+inter(1,3)=1; inter(3,1)=1;
+inter(2,4)=1; inter(4,2)=1;
+
+%bnet = mk_fhmm(3);
+bnet = mk_chmm(4);
+intra = bnet.intra;
+inter = bnet.inter;
+
+clqs = compute_minimal_interface(intra, inter);
+celldisp(clqs)
+
+
+
+
+% A A
+%  \
+% B B
+%  \
+% C C
+%  \
+% D-D
+ss = 4;
+intra = zeros(ss);
+inter = zeros(ss);
+for i=1:ss-1
+  inter(i,i+1)=1;
+end
+inter(4,4)=1;
+
+
+
+ns = 2*ones(1,ss);
+dbn = mk_dbn(intra, inter, ns);
+for i=2*ss
+  dbn.CPD{i} = tabular_CPD(bnet, i);
+end
+
+T = 4;
+N = ss*T;
+bnet = dbn_to_bnet(dbn, T);
+
+constrained = 1;
+if constrained
+  % elim first 3 slices first in any order
+  stages = {1:12, 13:16};
+  %stages = num2cell(unroll_set(1:ss, ss, T), 1);
+else
+  stages = { 1:N; };
+end
+clusters = {};
+%[jtree, root, cliques, B, w, elim_order, moral_edges, fill_in_edges] = ...
+%    dag_to_jtree(bnet, bnet.observed, stages, clusters);
+[jtree, root, cliques] =  graph_to_jtree(moralize(bnet.dag), ones(1,N), stages, clusters);
+
+
+
+
+
+% Examine the cliques in the 1.5 slice DBN
+
+%dbn = mk_mildew_dbn;
+dbn = mk_water_dbn;
+%dbn = mk_bat_dbn;
+ss = dbn.nnodes_per_slice;
+int = compute_fwd_interface(dbn);
+bnet15 = mk_slice_and_half_dbn(dbn, int);
+N = length(bnet15.dag);
+stages = {1:N};
+
+% bat
+%cl1 = [16 17 19 7 14];
+%cl2 = [27 25 21 23 20];
+%clusters = {cl1, cl2, cl1+ss, cl2+ss};
+
+% water
+%cl1 = 1:2; cl2 = 3:6; cl3 = 7:8;
+%clusters = {cl1, cl2, cl3, cl1+ss, cl2+ss, cl3+ss};
+
+%clusters = {};
+clusters = {int, int+ss};
+%[jtree, root, cliques, B, w, elim_order, moral_edges, fill_in_edges] = ...
+%    dag_to_jtree(bnet15, bnet.observed, stages, clusters);
+[jtree, root, cliques] =  graph_to_jtree(moralize(bnet15.dag), ones(1,N), stages, clusters);
+
+clq_len = [];
+for c=1:length(cliques)
+  clq_len(c) = length(cliques{c});
+end
+hist(clq_len, 1:max(clq_len));
+h=hist(clq_len, 1:max(clq_len));
+axis([1 max(clq_len)+1 0 max(h)+1])
+xlabel('clique size','fontsize',16)
+ylabel('number','fontsize',16)
+
+
+
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/jtree_clq_test2.m b/sourcecodes/bnt-master/BNT/examples/dynamic/jtree_clq_test2.m
new file mode 100644
index 00000000..975cc46b
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/jtree_clq_test2.m
@@ -0,0 +1,23 @@
+
+%bnet = mk_uffe_dbn;
+bnet = mk_mildew_dbn;
+ss = length(bnet.intra);
+
+% construct jtree from 1.5 slice DBN
+
+int = compute_fwd_interface(bnet.intra, bnet.inter);
+bnet15 = mk_slice_and_half_dbn(bnet, int);
+
+% use unconstrained elimination,
+% but force there to be a clique containing both interfaces
+clusters = {int, int+ss};
+jtree_engine = jtree_inf_engine(bnet15, 'clusters', clusters, 'root', int+ss);
+S=struct(jtree_engine)
+in_clq = clq_containing_nodes(jtree_engine, int);
+out_clq = clq_containing_nodes(jtree_engine, int+ss)
+
+
+% Also make a jtree from slice 1
+bnet1 = mk_bnet(bnet.intra1, bnet.node_sizes_slice);
+jtree_engine1 = jtree_inf_engine(bnet1, 'clusters', {int}, 'root', int);
+S1=struct(jtree_engine1)
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/kalman1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/kalman1.m
new file mode 100644
index 00000000..32c3583c
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/kalman1.m
@@ -0,0 +1,66 @@
+% Make a linear dynamical system
+%   X1 -> X2
+%   |     | 
+%   v     v
+%   Y1    Y2 
+
+intra = zeros(2);
+intra(1,2) = 1;
+inter = zeros(2);
+inter(1,1) = 1;
+n = 2;
+
+X = 2; % size of hidden state
+Y = 2; % size of observable state
+ns = [X Y];
+bnet = mk_dbn(intra, inter, ns, 'discrete', [], 'observed', 2);
+
+x0 = rand(X,1);
+V0 = eye(X);
+C0 = rand(Y,X);
+R0 = eye(Y);
+A0 = rand(X,X);
+Q0 = eye(X);
+
+bnet.CPD{1} = gaussian_CPD(bnet, 1, 'mean', x0, 'cov', V0, 'cov_prior_weight', 0);
+bnet.CPD{2} = gaussian_CPD(bnet, 2, 'mean', zeros(Y,1), 'cov', R0, 'weights', C0, ...
+			   'clamp_mean', 1, 'cov_prior_weight', 0);
+bnet.CPD{3} = gaussian_CPD(bnet, 3, 'mean', zeros(X,1), 'cov', Q0, 'weights', A0, ...
+			   'clamp_mean', 1, 'cov_prior_weight', 0);
+
+
+T = 5; % fixed length sequences
+
+clear engine;
+engine{1} = kalman_inf_engine(bnet);
+engine{2} = jtree_unrolled_dbn_inf_engine(bnet, T);
+engine{3} = jtree_dbn_inf_engine(bnet);
+engine{end+1} = smoother_engine(jtree_2TBN_inf_engine(bnet));
+N = length(engine);
+
+
+inf_time = cmp_inference_dbn(bnet, engine, T);
+
+ncases = 2;
+max_iter = 2;
+[learning_time, CPD, LL, cases] = cmp_learning_dbn(bnet, engine, T, 'ncases', ncases, 'max_iter', max_iter);
+
+
+% Compare to KF toolbox
+
+data = zeros(Y, T, ncases);
+for i=1:ncases
+  data(:,:,i) = cell2num(cases{i}(onodes, :));
+end   
+[A2, C2, Q2, R2, x2, V2, LL2trace] =  learn_kalman(data, A0, C0, Q0, R0, x0, V0, max_iter);
+
+
+e = 1;
+assert(approxeq(x2, CPD{e,1}.mean))
+assert(approxeq(V2, CPD{e,1}.cov))
+assert(approxeq(C2, CPD{e,2}.weights))
+assert(approxeq(R2, CPD{e,2}.cov));
+assert(approxeq(A2, CPD{e,3}.weights))
+assert(approxeq(Q2, CPD{e,3}.cov));
+assert(approxeq(LL2trace, LL{1}))
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/kjaerulff1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/kjaerulff1.m
new file mode 100644
index 00000000..28b315fc
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/kjaerulff1.m
@@ -0,0 +1,55 @@
+% Compare the speeds of various inference engines on the DBN in Kjaerulff
+% "dHugin: A computational system for dynamic time-sliced {B}ayesian networks",
+% Intl. J. Forecasting 11:89-111, 1995.
+%
+% The intra structure is (all arcs point downwards)
+%
+%  1 -> 2
+%   \  /
+%     3
+%     |
+%     4
+%    / \
+%   5   6
+%   \  /
+%     7
+%     |
+%     8
+%
+% The inter structure is 1->1, 4->4, 8->8
+
+seed = 0;
+rand('state', seed);
+randn('state', seed);
+
+ss = 8;
+intra = zeros(ss);
+intra(1,[2 3])=1;
+intra(2,3)=1;
+intra(3,4)=1;
+intra(4,[5 6])=1;
+intra([5 6], 7)=1;
+intra(7,8)=1;
+
+inter = zeros(ss);
+inter(1,1)=1;
+inter(4,4)=1;
+inter(8,8)=1;
+
+ns = 2*ones(1,ss);
+onodes = 2;
+bnet = mk_dbn(intra, inter, ns, 'observed', onodes, 'eclass2', (1:ss)+ss);
+for i=1:2*ss
+  bnet.CPD{i} = tabular_CPD(bnet, i);
+end
+
+T = 4;
+
+engine = {};
+engine{end+1} = jtree_unrolled_dbn_inf_engine(bnet, T);
+engine{end+1} = jtree_dbn_inf_engine(bnet);
+engine{end+1} = smoother_engine(jtree_2TBN_inf_engine(bnet));
+%engine{end+1} = smoother_engine(hmm_2TBN_inf_engine(bnet)); % observed nodes have children
+
+inf_time = cmp_inference_dbn(bnet, engine, T)
+learning_time = cmp_learning_dbn(bnet, engine, T)
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/loopy_dbn1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/loopy_dbn1.m
new file mode 100644
index 00000000..27facf0b
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/loopy_dbn1.m
@@ -0,0 +1,24 @@
+N = 1; % single chain = HMM - should give exact answers
+Q = 2;
+rand('state', 0);
+randn('state', 0);
+discrete = 1;
+if discrete
+  Y = 2; % size of output alphabet
+else
+  Y = 1;
+end
+coupled = 1;
+bnet  = mk_chmm(N, Q, Y, discrete, coupled);
+ss = N*2;
+
+T = 3;
+
+engine = {};
+engine{end+1} = jtree_dbn_inf_engine(bnet); 
+engine{end+1} = jtree_unrolled_dbn_inf_engine(bnet, T); 
+engine{end+1} = pearl_unrolled_dbn_inf_engine(bnet, 'protocol', 'tree');  
+
+inf_time = cmp_inference_dbn(bnet, engine, T)
+learning_time = cmp_learning_dbn(bnet, engine, T)
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/mhmm1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/mhmm1.m
new file mode 100644
index 00000000..6efb9f72
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/mhmm1.m
@@ -0,0 +1,85 @@
+% Make an HMM with mixture of Gaussian observations
+%    Q1 ---> Q2
+%  /  |   /  |
+% M1  |  M2  | 
+%  \  v   \  v
+%    Y1     Y2 
+% where Pr(m=j|q=i) is a multinomial and Pr(y|m,q) is a Gaussian     
+
+%seed = 3;
+%rand('state', seed);
+%randn('state', seed);
+
+intra = zeros(3);
+intra(1,[2 3]) = 1;
+intra(2,3) = 1;
+inter = zeros(3);
+inter(1,1) = 1;
+n = 3;
+
+Q = 2; % num hidden states
+O = 2; % size of observed vector
+M = 2; % num mixture components per state
+
+ns = [Q M O];
+dnodes = [1 2];
+onodes = [3];
+eclass1 = [1 2 3];
+eclass2 = [4 2 3];
+bnet = mk_dbn(intra, inter, ns, 'discrete', dnodes, 'eclass1', eclass1, 'eclass2', eclass2, ...
+	      'observed', onodes);
+
+prior0 = normalise(rand(Q,1));
+transmat0 = mk_stochastic(rand(Q,Q));
+mixmat0 = mk_stochastic(rand(Q,M));
+mu0 = rand(O,Q,M);
+Sigma0 = repmat(eye(O), [1 1 Q M]);
+bnet.CPD{1} = tabular_CPD(bnet, 1, prior0);
+bnet.CPD{2} = tabular_CPD(bnet, 2, mixmat0);
+%% we set the cov prior to 0 to give same results as HMM toolbox
+%bnet.CPD{3} = gaussian_CPD(bnet, 3, 'mean', mu0, 'cov', Sigma0, 'cov_prior_weight', 0);
+% new version of HMM toolbox uses the same default prior on Gaussians as BNT
+bnet.CPD{3} = gaussian_CPD(bnet, 3, 'mean', mu0, 'cov', Sigma0);
+bnet.CPD{4} = tabular_CPD(bnet, 4, transmat0);
+
+
+
+T = 5; % fixed length sequences
+
+engine = {};
+engine{end+1} = hmm_inf_engine(bnet);
+engine{end+1} = smoother_engine(jtree_2TBN_inf_engine(bnet));
+engine{end+1} = smoother_engine(hmm_2TBN_inf_engine(bnet));
+if 0
+engine{end+1} = jtree_unrolled_dbn_inf_engine(bnet, T);
+%engine{end+1} = frontier_inf_engine(bnet);
+engine{end+1} = bk_inf_engine(bnet, 'clusters', 'exact');
+engine{end+1} = jtree_dbn_inf_engine(bnet);
+end
+
+inf_time = cmp_inference_dbn(bnet, engine, T);
+
+ncases = 2;
+max_iter = 2;
+[learning_time, CPD, LL, cases] = cmp_learning_dbn(bnet, engine, T, 'ncases', ncases, 'max_iter', max_iter);
+
+% Compare to HMM toolbox
+
+data = zeros(O, T, ncases);
+for i=1:ncases
+  data(:,:,i) = reshape(cell2num(cases{i}(onodes,:)), [O T]);
+end
+tic;
+[LL2, prior2, transmat2, mu2, Sigma2, mixmat2] = ...
+    mhmm_em(data, prior0, transmat0,  mu0, Sigma0, mixmat0, 'max_iter', max_iter);
+t=toc;
+disp(['HMM toolbox took ' num2str(t) ' seconds '])
+
+for e = 1:length(engine)
+  assert(approxeq(prior2, CPD{e,1}.CPT))
+  assert(approxeq(mixmat2, CPD{e,2}.CPT))
+  assert(approxeq(mu2, CPD{e,3}.mean))
+  assert(approxeq(Sigma2, CPD{e,3}.cov))
+  assert(approxeq(transmat2, CPD{e,4}.CPT))
+  assert(approxeq(LL2, LL{e}))
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/mildew1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/mildew1.m
new file mode 100644
index 00000000..f38aee91
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/mildew1.m
@@ -0,0 +1,30 @@
+bnet = mk_mildew_dbn;
+
+T = 4;
+engine = {};
+engine{end+1} = jtree_unrolled_dbn_inf_engine(bnet, T);
+engine{end+1} = jtree_dbn_inf_engine(bnet); 
+%engine{end+1} = hmm_inf_engine(bnet); % 8 is observed but has kids
+engine{end+1} = smoother_engine(jtree_2TBN_inf_engine(bnet));
+%engine{end+1} = smoother_engine(hmm_2TBN_inf_engine(bnet));
+
+inf_time = cmp_inference_dbn(bnet, engine, T, 'check_ll', 0)
+%learning_time = cmp_learning_dbn(bnet, engine, T)
+
+S = struct(engine{1});
+S1 = struct(S.unrolled_engine);
+G = S1.jtree;
+%graph_to_dot(G, 'directed', 0, 'leftright', 1, ...
+%	     'filename', '/home/eecs/murphyk/WP/Thesis/Figures/Inf/Mildew/jtree.dot')
+%!dot -Tps jtree.dot -o jtree.ps
+% The resulting ps file cannot be converted using ps2pdf.
+
+N = length(G);
+for i=1:N
+  for j=1:N
+    if G(i,j)
+      G(j,i)=1;
+    end
+  end
+end
+draw_graph(G)
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/mk_bat_dbn.m b/sourcecodes/bnt-master/BNT/examples/dynamic/mk_bat_dbn.m
new file mode 100644
index 00000000..e4d6f8b9
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/mk_bat_dbn.m
@@ -0,0 +1,63 @@
+function [bnet, names] = mk_bat_dbn()
+% MK_BAT_DBN Make the BAT DBN
+% [bnet, names] = mk_bat_dbn()
+% See
+% - Forbes, Huang, Kanazawa and Russell, "The BATmobile: Towards a Bayesian Automated Taxi", IJCAI 95
+% - Boyen and Koller, "Tractable Inference for Complex Stochastic Processes", UAI98.
+
+names = {'LeftClr', 'RightClr', 'LatAct', 'Xdot', 'InLane', 'FwdAct', ...
+      'Ydot', 'Stopped', 'EngStatus', 'FBStatus', ...
+      'LeftClrSens', 'RightClrSens', 'TurnSignalSens', 'XdotSens', 'YdotSens', ...
+      'FYdotDiffSens', 'FclrSens', 'BXdotSens', 'BclrSens', 'BYdotDiffSens', ...
+      'SensorValid', 'FYdotDiff', 'FcloseSlow', 'Fclr', 'BXdot', 'BcloseFast', 'Bclr', 'BYdotDiff'};
+ss = length(names);
+
+intrac = {...
+      'LeftClr', 'LeftClrSens';
+  'RightClr', 'RightClrSens';
+  'LatAct', 'TurnSignalSens'; 'LatAct', 'Xdot';
+  'Xdot', 'XdotSens';
+  'FwdAct', 'Ydot';
+  'Ydot', 'YdotSens'; 'Ydot', 'Stopped';
+  'EngStatus', 'Ydot'; 'EngStatus', 'FYdotDiff'; 'EngStatus', 'Fclr'; 'EngStatus', 'BXdot';
+  'SensorValid', 'XdotSens';   'SensorValid', 'YdotSens';
+  'FYdotDiff', 'FYdotDiffSens'; 'FYdotDiff', 'FcloseSlow';
+  'FcloseSlow', 'FBStatus';
+  'Fclr', 'FclrSens'; 'Fclr', 'FcloseSlow';
+  'BXdot', 'BXdotSens';
+  'Bclr', 'BclrSens'; 'Bclr', 'BXdot'; 'Bclr', 'BcloseFast';
+  'BcloseFast', 'FBStatus';
+  'BYdotDiff', 'BYdotDiffSens'; 'BYdotDiff', 'BcloseFast'};
+[intra, names] = mk_adj_mat(intrac, names, 1);
+
+
+interc = {...
+      'LeftClr', 'LeftClr'; 'LeftClr', 'LatAct';
+  'RightClr', 'RightClr'; 'RightClr', 'LatAct';
+  'LatAct', 'LatAct'; 'LatAct', 'FwdAct';
+  'Xdot', 'Xdot'; 'Xdot', 'InLane';
+  'InLane', 'InLane'; 'InLane', 'LatAct';
+  'FwdAct', 'FwdAct';
+  'Ydot', 'Ydot';
+  'Stopped', 'Stopped';
+  'EngStatus', 'EngStatus';
+  'FBStatus', 'FwdAct'; 'FBStatus', 'LatAct'};
+inter = mk_adj_mat(interc, names, 0);  
+
+obs = {'LeftClrSens', 'RightClrSens', 'TurnSignalSens', 'XdotSens', 'YdotSens', 'FYdotDiffSens', ...
+      'FclrSens', 'BXdotSens', 'BclrSens', 'BYdotDiffSens'};
+
+for i=1:length(obs)
+  onodes(i) = strmatch(obs{i}, names); %stringmatch(obs{i}, names);
+end
+onodes = sort(onodes);
+
+dnodes = 1:ss; 
+ns = 2*ones(1,ss); % binary nodes
+bnet = mk_dbn(intra, inter, ns, 'discrete', dnodes, 'observed', onodes, 'eclass2', (1:ss)+ss);
+
+% make rnd params
+for i=1:2*ss
+  bnet.CPD{i} = tabular_CPD(bnet, i);
+end
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/mk_chmm.m b/sourcecodes/bnt-master/BNT/examples/dynamic/mk_chmm.m
new file mode 100644
index 00000000..8da245ef
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/mk_chmm.m
@@ -0,0 +1,103 @@
+function bnet = mk_chmm(N, Q, Y, discrete_obs, coupled, CPD)
+% MK_CHMM Make a coupled Hidden Markov Model
+%
+% There are N hidden nodes, each connected to itself and its two nearest neighbors in the next
+% slice (apart from the edges, where there is 1 nearest neighbor).
+%
+% Example: If N = 3, the hidden backbone is as follows, where all arrows point to the righ+t
+%
+% X1--X2
+%   \/ 
+%   /\
+% X2--X2
+%   \/ 
+%   /\
+% X3--X3
+%
+% Each hidden node has a "private" observed child (not shown).
+%
+% BNET = MK_CHMM(N, Q, Y)
+% Each hidden node is discrete and has Q values.
+% Each observed node is a Gaussian vector of length Y.
+%
+% BNET = MK_CHMM(N, Q, Y, DISCRETE_OBS)
+% If discrete_obs = 1, the observations are discrete (values in {1, .., Y}).
+%
+% BNET = MK_CHMM(N, Q, Y, DISCRETE_OBS, COUPLED)
+% If coupled = 0, the chains are not coupled, i.e., we make N parallel HMMs.
+%
+% BNET = MK_CHMM(N, Q, Y, DISCRETE_OBS, COUPLED, CPDs)
+% means use the specified CPD structures instead of creating random params.
+%  CPD{i}.CPT, i=1:N specifies the prior
+%  CPD{i}.CPT, i=2N+1:3N specifies the transition model
+%  CPD{i}.mean, CPD{i}.cov, i=N+1:2N specifies the observation model if Gaussian
+%  CPD{i}.CPT, i=N+1:2N if discrete
+
+
+if nargin < 2, Q = 2; end
+if nargin < 3, Y = 1; end
+if nargin < 4, discrete_obs = 0; end
+if nargin < 5, coupled = 1; end
+if nargin < 6, rnd = 1; else rnd = 0; end
+  
+ss = N*2;
+hnodes = 1:N;
+onodes = (1:N)+N;
+
+intra = zeros(ss);
+for i=1:N
+  intra(hnodes(i), onodes(i))=1;
+end
+
+inter = zeros(ss);
+if coupled
+  for i=1:N
+    inter(i, max(i-1,1):min(i+1,N))=1;
+  end
+else
+  inter(1:N, 1:N) = eye(N);
+end  
+
+ns = [Q*ones(1,N) Y*ones(1,N)]; 
+
+eclass1 = [hnodes onodes];
+eclass2 = [hnodes+ss onodes];
+if discrete_obs
+  dnodes = 1:ss;
+else
+  dnodes = hnodes;
+end
+bnet = mk_dbn(intra, inter, ns, 'discrete', dnodes, 'eclass1', eclass1, 'eclass2', eclass2, ...
+	      'observed', onodes);
+
+if rnd
+  for i=hnodes(:)'
+    bnet.CPD{i} = tabular_CPD(bnet, i);
+  end
+  for i=onodes(:)'
+    if discrete_obs
+      bnet.CPD{i} = tabular_CPD(bnet, i);
+    else
+      bnet.CPD{i} = gaussian_CPD(bnet, i);
+    end
+  end
+  for i=hnodes(:)'+ss
+    bnet.CPD{i} = tabular_CPD(bnet, i);
+  end
+else
+  for i=hnodes(:)'
+    bnet.CPD{i} = tabular_CPD(bnet, i, CPD{i}.CPT);
+  end
+  for i=onodes(:)'
+    if discrete_obs
+      bnet.CPD{i} = tabular_CPD(bnet, i, CPD{i}.CPT);
+    else
+      bnet.CPD{i} = gaussian_CPD(bnet, i, CPD{i}.mean, CPD{i}.cov);
+    end
+  end
+  for i=hnodes(:)'+ss
+    bnet.CPD{i} = tabular_CPD(bnet, i, CPD{i}.CPT);
+  end
+end
+
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/mk_collage_from_clqs.m b/sourcecodes/bnt-master/BNT/examples/dynamic/mk_collage_from_clqs.m
new file mode 100644
index 00000000..90159f7e
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/mk_collage_from_clqs.m
@@ -0,0 +1,44 @@
+function mk_collage_from_clqs(dir, cliques)
+
+% For use with mk_ps_from_clqs.
+% This generates a latex file that glues all the .ps files
+% into one big figure.
+
+cd(dir)
+C = length(cliques);
+
+ncols = 4;
+width = 1.5;
+fid = fopen('collage.tex', 'w');
+fprintf(fid, '\\documentclass{article}\n');
+fprintf(fid, '\\usepackage{psfig}\n');
+fprintf(fid, '\\begin{document}\n');
+fprintf(fid, '\\centerline{\n');
+fprintf(fid, '\\begin{tabular}{');
+for col=1:ncols,  fprintf(fid, 'c'); end
+fprintf(fid, '}\n');
+c = 1;
+for row = 1:floor(C/ncols)
+  for col=1:ncols-1
+    fname = sprintf('%s/clq%d.ps', dir, c);
+    fprintf(fid, '\\psfig{file=%s,width=%3fin} & \n', fname, width);
+    c = c + 1;
+  end
+  fname = sprintf('%s/clq%d.ps', dir, c);
+  fprintf(fid, '\\psfig{file=%s,width=%3fin} \\\\ \n', fname, width);
+  c = c + 1;
+end
+% last row
+while (c <= C)
+  fname = sprintf('%s/clq%d.ps', dir, c);
+  fprintf(fid, '\\psfig{file=%s,width=%3fin} & \n', fname, width);
+  c = c + 1;
+end
+fprintf(fid, '\\end{tabular}\n');
+fprintf(fid, '}\n');
+fprintf(fid, '\\end{document}');
+fclose(fid);
+
+!latex collage.tex &
+!dvips -o collage.ps collage.dvi &
+!ghostview collage.ps &
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/mk_fhmm.m b/sourcecodes/bnt-master/BNT/examples/dynamic/mk_fhmm.m
new file mode 100644
index 00000000..ffbe05a5
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/mk_fhmm.m
@@ -0,0 +1,58 @@
+function bnet = mk_fhmm(N, Q, Y, discrete_obs)
+% MK_FHMM Make a factorial Hidden Markov Model
+%
+% There are N independent parallel hidden chains, each connected to the output
+%
+% e.g., N = 2 (vertical/diagonal edges point down)
+%
+% A1--->A2
+% | B1--|->B2
+% | /   |/
+% Y1    Y2
+%
+% [bnet, onode] = mk_chmm(n, q, y, discrete_obs)
+%
+% Each hidden node is discrete and has Q values.
+% If discrete_obs = 1, each observed node is discrete and has values 1..Y.
+% If discrete_obs = 0, each observed node is a Gaussian vector of length Y.
+
+if nargin < 2, Q = 2; end
+if nargin < 3, Y = 2; end
+if nargin < 4, discrete_obs = 1; end
+
+ss = N+1;
+hnodes = 1:N;
+onode = N+1;
+
+intra = zeros(ss);
+intra(hnodes, onode) = 1;
+
+inter = eye(ss);
+inter(onode,onode) = 0;
+
+ns = [Q*ones(1,N) Y];
+
+eclass1 = [hnodes onode];
+eclass2 = [hnodes+ss onode];
+if discrete_obs
+  dnodes = 1:ss;
+else
+  dnodes = hnodes;
+end
+bnet = mk_dbn(intra, inter, ns, 'discrete', dnodes, 'eclass1', eclass1, 'eclass2', eclass2, ...
+	      'observed', onode);
+
+for i=hnodes(:)'
+  bnet.CPD{i} = tabular_CPD(bnet, i);
+end
+i = onode;
+if discrete_obs
+  bnet.CPD{i} = tabular_CPD(bnet, i);
+else
+  bnet.CPD{i} = gaussian_CPD(bnet, i);
+end
+for i=hnodes(:)'+ss
+  bnet.CPD{i} = tabular_CPD(bnet, i);
+end
+
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/mk_mildew_dbn.m b/sourcecodes/bnt-master/BNT/examples/dynamic/mk_mildew_dbn.m
new file mode 100644
index 00000000..71f393e3
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/mk_mildew_dbn.m
@@ -0,0 +1,31 @@
+function bnet = mk_mildew_dbn()
+
+% DBN for foreacasting the gross yield of wheat based on climatic data,
+% observations of leaf area index (LAI) and extension of mildew,
+% and knowledge of amount of fungicides used and time of usage.
+% From Kjaerulff '95.
+
+Fungi=1; Mildew=2; LAI=3; Precip=4; Temp=5; Micro=6; Solar=7; Photo=8; Dry=9;
+n = 9;
+intra = zeros(n,n);
+intra(Mildew, LAI)=1;
+intra(LAI,[Micro Photo])=1;
+intra(Precip,Micro)=1;
+intra(Temp,[Micro Photo])=1;
+intra(Solar,Photo)=1;
+intra(Photo,Dry)=1;
+
+inter = zeros(n,n);
+inter(Fungi,Mildew)=1;
+inter(Mildew,Mildew)=1;
+inter(LAI,LAI)=1;
+inter(Micro,Mildew)=1;
+inter(Dry,Dry)=1;
+
+ns = 2*ones(1,n);
+bnet = mk_dbn(intra, inter, ns, 'observed', [Photo]);
+
+for e=1:max(bnet.equiv_class(:))
+  i = bnet.rep_of_eclass(e);
+  bnet.CPD{e} = tabular_CPD(bnet,i);
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/mk_orig_bat_dbn.m b/sourcecodes/bnt-master/BNT/examples/dynamic/mk_orig_bat_dbn.m
new file mode 100644
index 00000000..0065ad5e
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/mk_orig_bat_dbn.m
@@ -0,0 +1,198 @@
+function [bnet, names] = mk_orig_bat_dbn()
+% MK_BAT_DBN Make the BAT DBN
+% [bnet, names] = mk_bat_dbn()
+% See
+% - Forbes, Huang, Kanazawa and Russell, "The BATmobile: Towards a Bayesian Automated Taxi", IJCAI 95
+% - Boyen and Koller, "Tractable Inference for Complex Stochastic Processes", UAI98.
+
+names = {'LeftClr', 'RightClr', 'LatAct', 'Xdot', 'InLane', 'FwdAct', ...
+      'Ydot', 'Stopped', 'EngStatus', 'FBStatus', ...
+      'LeftClrSens', 'RightClrSens', 'TurnSignalSens', 'XdotSens', 'YdotSens', ...
+      'FYdotDiffSens', 'FclrSens', 'BXdotSens', 'BclrSens', 'BYdotDiffSens', ...
+      'SensorValid', 'FYdotDiff', 'FcloseSlow', 'Fclr', 'BXdot', 'BcloseFast', 'Bclr', 'BYdotDiff'};
+ss = length(names);
+
+intrac = {...
+      'LeftClr', 'LeftClrSens';
+  'RightClr', 'RightClrSens';
+  'LatAct', 'TurnSignalSens'; 'LatAct', 'Xdot';
+  'Xdot', 'XdotSens';
+  'FwdAct', 'Ydot';
+  'Ydot', 'YdotSens'; 'Ydot', 'Stopped';
+  'EngStatus', 'Ydot'; 'EngStatus', 'FYdotDiff'; 'EngStatus', 'Fclr'; 'EngStatus', 'BXdot';
+  'SensorValid', 'XdotSens';   'SensorValid', 'YdotSens';
+  'FYdotDiff', 'FYdotDiffSens'; 'FYdotDiff', 'FcloseSlow';
+  'FcloseSlow', 'FBStatus';
+  'Fclr', 'FclrSens'; 'Fclr', 'FcloseSlow';
+  'BXdot', 'BXdotSens';
+  'Bclr', 'BclrSens'; 'Bclr', 'BXdot'; 'Bclr', 'BcloseFast';
+  'BcloseFast', 'FBStatus';
+  'BYdotDiff', 'BYdotDiffSens'; 'BYdotDiff', 'BcloseFast'};
+[intra, names] = mk_adj_mat(intrac, names, 1);
+
+
+interc = {...
+      'LeftClr', 'LeftClr'; 'LeftClr', 'LatAct';
+  'RightClr', 'RightClr'; 'RightClr', 'LatAct';
+  'LatAct', 'LatAct'; 'LatAct', 'FwdAct';
+  'Xdot', 'Xdot'; 'Xdot', 'InLane';
+  'InLane', 'InLane'; 'InLane', 'LatAct';
+  'FwdAct', 'FwdAct';
+  'Ydot', 'Ydot';
+  'Stopped', 'Stopped';
+  'EngStatus', 'EngStatus';
+  'FBStatus', 'FwdAct'; 'FBStatus', 'LatAct'};
+inter = mk_adj_mat(interc, names, 0);  
+
+obs = {'LeftClrSens', 'RightClrSens', 'TurnSignalSens', 'XdotSens', 'YdotSens', 'FYdotDiffSens', ...
+      'FclrSens', 'BXdotSens', 'BclrSens', 'BYdotDiffSens'};
+
+for i=1:length(obs)
+  onodes(i) = stringmatch(obs{i}, names);
+end
+onodes = sort(onodes);
+
+dnodes = 1:ss; 
+ns = zeros(1,ss);
+
+ns(stringmatch('LeftClr', names)) = 2;
+ns(stringmatch('RightClr', names)) = 2;
+ns(stringmatch('LatAct', names)) = 3;
+ns(stringmatch('Xdot', names)) = 7;
+ns(stringmatch('InLane', names)) = 2;
+ns(stringmatch('FwdAct', names)) = 3;
+ns(stringmatch('Ydot', names)) = 11;
+ns(stringmatch('Stopped', names)) = 2;
+ns(stringmatch('EngStatus', names)) = 2;
+ns(stringmatch('FBStatus', names)) = 3;
+ns(stringmatch('LeftClrSens', names)) = 2;
+ns(stringmatch('RightClrSens', names)) = 2;
+ns(stringmatch('TurnSignalSens', names)) = 3;
+ns(stringmatch('XdotSens', names)) = 7;
+ns(stringmatch('YdotSens', names)) = 11;
+ns(stringmatch('FYdotDiffSens', names)) = 8;
+ns(stringmatch('FclrSens', names)) = 20;
+ns(stringmatch('BXdotSens', names)) = 8;
+ns(stringmatch('BclrSens', names)) = 20;
+ns(stringmatch('BYdotDiffSens', names)) = 8;
+ns(stringmatch('SensorValid', names)) = 2;
+ns(stringmatch('FYdotDiff', names)) = 4;
+ns(stringmatch('FcloseSlow', names)) = 2;
+ns(stringmatch('Fclr', names)) = 3;
+ns(stringmatch('BXdot', names)) = 8;
+ns(stringmatch('BcloseFast', names)) = 2;
+ns(stringmatch('Bclr', names)) = 3;
+ns(stringmatch('BYdotDiff', names)) = 4;
+
+%ns = 2*ones(1,ss);
+
+
+bnet = mk_dbn(intra, inter, ns, 'discrete', dnodes, 'observed', onodes, 'eclass2', (1:ss)+ss);
+
+% make unif params
+for i=1:2*ss
+  bnet.CPD{i} = tabular_CPD(bnet, i, 'CPT', 'unif');
+end
+
+i = stringmatch('LeftClr', names)+ss;
+bnet.CPD{i} = tabular_CPD(bnet, i, [0.99 0.01 0.01 0.99]);
+
+i = stringmatch('RightClr', names)+ss;
+bnet.CPD{i} = tabular_CPD(bnet, i, [0.99 0.01 0.01 0.99]);
+
+i = stringmatch('LatAct', names)+ss;
+bnet.CPD{i} = tabular_CPD(bnet, i, [0.166666666666667 0.975609756097561 0.111111111111111 0.961538461538462 0.00980392156862745 0.0380952380952381 0.00952380952380952 0.037037037037037 0.166666666666667 0.444444444444444 0.0048780487804878 0.0192307692307692 0.0384615384615385 0.888888888888889 0.0344827586206897 0.87719298245614 0.00819672131147541 0.032 0.008 0.03125 0.0384615384615385 0.137931034482759 0.00444444444444444 0.0175438596491228 0.166666666666667 0.975609756097561 0.111111111111111 0.961538461538462 0.166666666666667 0.8 0.04 0.454545454545455 0.166666666666667 0.444444444444444 0.0048780487804878 0.0192307692307692 0.0384615384615385 0.888888888888889 0.0344827586206897 0.87719298245614 0.0384615384615385 0.444444444444444 0.0222222222222222 0.3125 0.0384615384615385 0.137931034482759 0.00444444444444444 0.0175438596491228 0.166666666666667 0.975609756097561 0.111111111111111 0.961538461538462 0.166666666666667 0.8 0.04 0.454545454545455 0.166666666666667 0.444444444444444 0.0048780487804878 0.0192307692307692 0.0384615384615385 0.888888888888889 0.0344827586206897 0.87719298245614 0.0384615384615385 0.444444444444444 0.0222222222222222 0.3125 0.0384615384615385 0.137931034482759 0.00444444444444444 0.0175438596491228 0.666666666666667 0.0195121951219512 0.444444444444444 0.0192307692307692 0.980392156862745 0.952380952380952 0.952380952380952 0.925925925925926 0.666666666666667 0.444444444444444 0.0195121951219512 0.0192307692307692 0.923076923076923 0.106666666666667 0.827586206896552 0.105263157894737 0.983606557377049 0.96 0.96 0.9375 0.923076923076923 0.827586206896552 0.106666666666667 0.105263157894737 0.666666666666667 0.0195121951219512 0.444444444444444 0.0192307692307692 0.666666666666667 0.16 0.16 0.0909090909090909 0.666666666666667 0.444444444444444 0.0195121951219512 0.0192307692307692 0.923076923076923 0.106666666666667 0.827586206896552 0.105263157894737 0.923076923076923 0.533333333333333 0.533333333333333 0.375 0.923076923076923 0.827586206896552 0.106666666666667 0.105263157894737 0.666666666666667 0.0195121951219512 0.444444444444444 0.0192307692307692 0.666666666666667 0.16 0.16 0.0909090909090909 0.666666666666667 0.444444444444444 0.0195121951219512 0.0192307692307692 0.923076923076923 0.106666666666667 0.827586206896552 0.105263157894737 0.923076923076923 0.533333333333333 0.533333333333333 0.375 0.923076923076923 0.827586206896552 0.106666666666667 0.105263157894737 0.166666666666667 0.0048780487804878 0.444444444444444 0.0192307692307692 0.00980392156862745 0.00952380952380952 0.0380952380952381 0.037037037037037 0.166666666666667 0.111111111111111 0.975609756097561 0.961538461538462 0.0384615384615385 0.00444444444444444 0.137931034482759 0.0175438596491228 0.00819672131147541 0.008 0.032 0.03125 0.0384615384615385 0.0344827586206897 0.888888888888889 0.87719298245614 0.166666666666667 0.0048780487804878 0.444444444444444 0.0192307692307692 0.166666666666667 0.04 0.8 0.454545454545455 0.166666666666667 0.111111111111111 0.975609756097561 0.961538461538462 0.0384615384615385 0.00444444444444444 0.137931034482759 0.0175438596491228 0.0384615384615385 0.0222222222222222 0.444444444444444 0.3125 0.0384615384615385 0.0344827586206897 0.888888888888889 0.87719298245614 0.166666666666667 0.0048780487804878 0.444444444444444 0.0192307692307692 0.166666666666667 0.04 0.8 0.454545454545455 0.166666666666667 0.111111111111111 0.975609756097561 0.961538461538462 0.0384615384615385 0.00444444444444444 0.137931034482759 0.0175438596491228 0.0384615384615385 0.0222222222222222 0.444444444444444 0.3125 0.0384615384615385 0.0344827586206897 0.888888888888889 0.87719298245614]);
+
+i = stringmatch('Xdot', names)+ss;
+bnet.CPD{i} = tabular_CPD(bnet, i, [0.497512437810945 0.115207373271889 0.0564971751412429 0.0290697674418605 0.075187969924812 0.0300751879699248 0.0298507462686567 0.0980392156862745 0.0392156862745098 0.043956043956044 0.0294117647058824 0.0283687943262411 0.0392156862745098 0.0392156862745098 0.0373134328358209 0.0300751879699248 0.0300751879699248 0.0232558139534884 0.0225988700564972 0.0184331797235023 0.0199004975124378 0.373134328358209 0.460829493087558 0.282485875706215 0.290697674418605 0.37593984962406 0.075187969924812 0.0373134328358209 0.490196078431373 0.0980392156862745 0.043956043956044 0.0294117647058824 0.0283687943262411 0.0392156862745098 0.0392156862745098 0.0746268656716418 0.037593984962406 0.0300751879699248 0.0232558139534884 0.0225988700564972 0.0184331797235023 0.0199004975124378 0.0497512437810945 0.345622119815668 0.564971751412429 0.581395348837209 0.37593984962406 0.37593984962406 0.0746268656716418 0.245098039215686 0.490196078431373 0.21978021978022 0.0735294117647059 0.0354609929078014 0.0490196078431373 0.0392156862745098 0.373134328358209 0.075187969924812 0.037593984962406 0.0232558139534884 0.0225988700564972 0.0184331797235023 0.0199004975124378 0.0199004975124378 0.0230414746543779 0.0282485875706215 0.0290697674418605 0.075187969924812 0.37593984962406 0.373134328358209 0.0490196078431373 0.245098039215686 0.54945054945055 0.735294117647059 0.709219858156028 0.245098039215686 0.0490196078431373 0.373134328358209 0.37593984962406 0.075187969924812 0.0290697674418605 0.0282485875706215 0.0230414746543779 0.0199004975124378 0.0199004975124378 0.0184331797235023 0.0225988700564972 0.0232558139534884 0.037593984962406 0.075187969924812 0.373134328358209 0.0392156862745098 0.0490196078431373 0.0549450549450549 0.0735294117647059 0.141843971631206 0.490196078431373 0.245098039215686 0.0746268656716418 0.37593984962406 0.37593984962406 0.581395348837209 0.564971751412429 0.345622119815668 0.0497512437810945 0.0199004975124378 0.0184331797235023 0.0225988700564972 0.0232558139534884 0.0300751879699248 0.037593984962406 0.0746268656716418 0.0392156862745098 0.0392156862745098 0.043956043956044 0.0294117647058824 0.0283687943262411 0.0980392156862745 0.490196078431373 0.0373134328358209 0.075187969924812 0.37593984962406 0.290697674418605 0.282485875706215 0.460829493087558 0.373134328358209 0.0199004975124378 0.0184331797235023 0.0225988700564972 0.0232558139534884 0.0300751879699248 0.0300751879699248 0.0373134328358209 0.0392156862745098 0.0392156862745098 0.043956043956044 0.0294117647058824 0.0283687943262411 0.0392156862745098 0.0980392156862745 0.0298507462686567 0.0300751879699248 0.075187969924812 0.0290697674418605 0.0564971751412429 0.115207373271889 0.497512437810945]);
+
+i = stringmatch('InLane', names)+ss;
+bnet.CPD{i} = tabular_CPD(bnet, i, [0.5 0.3 0.5 0.3 0.5 0.3 0.9 0.01 0.5 0.3 0.5 0.3 0.5 0.3 0.5 0.7 0.5 0.7 0.5 0.7 0.1 0.99 0.5 0.7 0.5 0.7 0.5 0.7]);
+
+i = stringmatch('FwdAct', names)+ss;
+bnet.CPD{i} = tabular_CPD(bnet, i, [0.4 0.4 0.4 0.949050949050949 0.949050949050949 0.949050949050949 0.4 0.4 0.4 0.6 0.1 0.1 0.949050949050949 0.949050949050949 0.949050949050949 0.05 0.05 0.05 0.4 0.4 0.4 0.949050949050949 0.949050949050949 0.949050949050949 0.4 0.4 0.4 0.4 0.4 0.4 0.04995004995005 0.04995004995005 0.04995004995005 0.4 0.4 0.4 0.3 0.8 0.3 0.04995004995005 0.04995004995005 0.04995004995005 0.7 0.7 0.7 0.4 0.4 0.4 0.04995004995005 0.04995004995005 0.04995004995005 0.4 0.4 0.4 0.2 0.2 0.2 0.000999000999000999 0.000999000999000999 0.000999000999000999 0.2 0.2 0.2 0.1 0.1 0.6 0.000999000999000999 0.000999000999000999 0.000999000999000999 0.25 0.25 0.25 0.2 0.2 0.2 0.000999000999000999 0.000999000999000999 0.000999000999000999 0.2 0.2 0.2]);
+
+i = stringmatch('Ydot', names)+ss;
+bnet.CPD{i} = tabular_CPD(bnet, i, [0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.999880014398272 0.72463768115942 0.595238095238095 0.230414746543779 0.0442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00460829493087558 0.595238095238095 0.230414746543779 0.0442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00460829493087558 0.00595238095238095 0.230414746543779 0.0442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00460829493087558 0.00595238095238095 0.0144927536231884 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 9.99880014398272e-005 0.144927536231884 0.297619047619048 0.460829493087558 0.221238938053097 0.0442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00460829493087558 0.297619047619048 0.460829493087558 0.221238938053097 0.0442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00460829493087558 0.00595238095238095 0.460829493087558 0.221238938053097 0.0442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00460829493087558 0.00595238095238095 0.0144927536231884 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 0.0144927536231884 0.0595238095238095 0.230414746543779 0.442477876106195 0.221238938053097 0.0442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00460829493087558 0.0595238095238095 0.230414746543779 0.442477876106195 0.221238938053097 0.0442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00460829493087558 0.00595238095238095 0.230414746543779 0.442477876106195 0.221238938053097 0.0442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00460829493087558 0.00595238095238095 0.0144927536231884 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 9.99880014398272e-006 0.0144927536231884 0.00595238095238095 0.0460829493087558 0.221238938053097 0.442477876106195 0.221238938053097 0.0442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00460829493087558 0.00595238095238095 0.0460829493087558 0.221238938053097 0.442477876106195 0.221238938053097 0.0442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00460829493087558 0.00595238095238095 0.0460829493087558 0.221238938053097 0.442477876106195 0.221238938053097 0.0442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00460829493087558 0.00595238095238095 0.0144927536231884 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0144927536231884 0.00595238095238095 0.00460829493087558 0.0442477876106195 0.221238938053097 0.442477876106195 0.221238938053097 0.0442477876106195 0.00442477876106195 0.00442477876106195 0.00460829493087558 0.00595238095238095 0.00460829493087558 0.0442477876106195 0.221238938053097 0.442477876106195 0.221238938053097 0.0442477876106195 0.00442477876106195 0.00442477876106195 0.00460829493087558 0.00595238095238095 0.00460829493087558 0.0442477876106195 0.221238938053097 0.442477876106195 0.221238938053097 0.0442477876106195 0.00442477876106195 0.00442477876106195 0.00460829493087558 0.00595238095238095 0.0144927536231884 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0144927536231884 0.00595238095238095 0.00460829493087558 0.00442477876106195 0.0442477876106195 0.221238938053097 0.442477876106195 0.221238938053097 0.0442477876106195 0.00442477876106195 0.00460829493087558 0.00595238095238095 0.00460829493087558 0.00442477876106195 0.0442477876106195 0.221238938053097 0.442477876106195 0.221238938053097 0.0442477876106195 0.00442477876106195 0.00460829493087558 0.00595238095238095 0.00460829493087558 0.00442477876106195 0.0442477876106195 0.221238938053097 0.442477876106195 0.221238938053097 0.0442477876106195 0.00442477876106195 0.00460829493087558 0.00595238095238095 0.0144927536231884 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0144927536231884 0.00595238095238095 0.00460829493087558 0.00442477876106195 0.00442477876106195 0.0442477876106195 0.221238938053097 0.442477876106195 0.221238938053097 0.0442477876106195 0.00460829493087558 0.00595238095238095 0.00460829493087558 0.00442477876106195 0.00442477876106195 0.0442477876106195 0.221238938053097 0.442477876106195 0.221238938053097 0.0442477876106195 0.00460829493087558 0.00595238095238095 0.00460829493087558 0.00442477876106195 0.00442477876106195 0.0442477876106195 0.221238938053097 0.442477876106195 0.221238938053097 0.0442477876106195 0.00460829493087558 0.00595238095238095 0.0144927536231884 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0144927536231884 0.00595238095238095 0.00460829493087558 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.0442477876106195 0.221238938053097 0.442477876106195 0.221238938053097 0.0460829493087558 0.00595238095238095 0.00460829493087558 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.0442477876106195 0.221238938053097 0.442477876106195 0.221238938053097 0.0460829493087558 0.00595238095238095 0.00460829493087558 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.0442477876106195 0.221238938053097 0.442477876106195 0.221238938053097 0.0460829493087558 0.00595238095238095 0.0144927536231884 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0144927536231884 0.00595238095238095 0.00460829493087558 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.0442477876106195 0.221238938053097 0.442477876106195 0.230414746543779 0.00595238095238095 0.00460829493087558 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.0442477876106195 0.221238938053097 0.442477876106195 0.230414746543779 0.0595238095238095 0.00460829493087558 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.0442477876106195 0.221238938053097 0.442477876106195 0.230414746543779 0.0595238095238095 0.0144927536231884 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0144927536231884 0.00595238095238095 0.00460829493087558 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.0442477876106195 0.221238938053097 0.460829493087558 0.00595238095238095 0.00460829493087558 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.0442477876106195 0.221238938053097 0.460829493087558 0.297619047619048 0.00460829493087558 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.0442477876106195 0.221238938053097 0.460829493087558 0.297619047619048 0.144927536231884 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0144927536231884 0.00595238095238095 0.00460829493087558 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.0442477876106195 0.230414746543779 0.00595238095238095 0.00460829493087558 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.0442477876106195 0.230414746543779 0.595238095238095 0.00460829493087558 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.00442477876106195 0.0442477876106195 0.230414746543779 0.595238095238095 0.72463768115942]);
+
+i = stringmatch('Stopped', names)+ss;
+bnet.CPD{i} = tabular_CPD(bnet, i, [0.0 0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0]);
+
+i = stringmatch('EngStatus', names)+ss;
+bnet.CPD{i} = tabular_CPD(bnet, i, [0.9 1.0e-006 0.1 0.999999]);
+
+i = stringmatch('FBStatus', names)+ss;
+bnet.CPD{i} = tabular_CPD(bnet, i, [1.0 0.0 0.0 0.0 0.0 1.0 0.0 1.0 0.0 0.0 1.0 0.0]);
+
+i = stringmatch('SensorValid', names);
+%bnet.CPD{i} = tabular_CPD(bnet, i, [1.0e-004 0.9999]);
+bnet.CPD{i+ss} = tabular_CPD(bnet, i+ss, [1.0e-004 0.9999]);
+
+i = stringmatch('FYdotDiff', names);
+%bnet.CPD{i} = tabular_CPD(bnet, i, [0.908182726364545 0.238095238095238 0.000908182726364545 0.476190476190476 9.08182726364545e-005 0.238095238095238 0.0908182726364545 0.0476190476190476]);
+bnet.CPD{i+ss} = tabular_CPD(bnet, i+ss, [0.908182726364545 0.238095238095238 0.000908182726364545 0.476190476190476 9.08182726364545e-005 0.238095238095238 0.0908182726364545 0.0476190476190476]);
+
+i = stringmatch('FcloseSlow', names);
+%bnet.CPD{i} = tabular_CPD(bnet, i, [1.0 1.0 1.0 1.0 1.0 1.0 0.0 1.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0]);
+bnet.CPD{i+ss} = tabular_CPD(bnet, i+ss, [1.0 1.0 1.0 1.0 1.0 1.0 0.0 1.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0]);
+
+i = stringmatch('Fclr', names);
+%bnet.CPD{i} = tabular_CPD(bnet, i, [0.000499750124937531 0.142857142857143 0.499750124937531 0.285714285714286 0.499750124937531 0.571428571428571]);
+bnet.CPD{i+ss} = tabular_CPD(bnet, i+ss, [0.000499750124937531 0.142857142857143 0.499750124937531 0.285714285714286 0.499750124937531 0.571428571428571]);
+
+i = stringmatch('BXdot', names);
+%bnet.CPD{i} = tabular_CPD(bnet, i, [0.00980392156862745 0.00980392156862745 0.00980392156862745 0.00980392156862745 0.0454545454545455 0.00980392156862745 0.0490196078431373 0.0490196078431373 0.0490196078431373 0.0490196078431373 0.136363636363636 0.0490196078431373 0.196078431372549 0.196078431372549 0.196078431372549 0.196078431372549 0.136363636363636 0.196078431372549 0.392156862745098 0.392156862745098 0.392156862745098 0.392156862745098 0.181818181818182 0.392156862745098 0.196078431372549 0.196078431372549 0.196078431372549 0.196078431372549 0.136363636363636 0.196078431372549 0.0490196078431373 0.0490196078431373 0.0490196078431373 0.0490196078431373 0.136363636363636 0.0490196078431373 0.00980392156862745 0.00980392156862745 0.00980392156862745 0.00980392156862745 0.0454545454545455 0.00980392156862745 0.0980392156862745 0.0980392156862745 0.0980392156862745 0.0980392156862745 0.181818181818182 0.0980392156862745]);
+bnet.CPD{i+ss} = tabular_CPD(bnet, i+ss, [0.00980392156862745 0.00980392156862745 0.00980392156862745 0.00980392156862745 0.0454545454545455 0.00980392156862745 0.0490196078431373 0.0490196078431373 0.0490196078431373 0.0490196078431373 0.136363636363636 0.0490196078431373 0.196078431372549 0.196078431372549 0.196078431372549 0.196078431372549 0.136363636363636 0.196078431372549 0.392156862745098 0.392156862745098 0.392156862745098 0.392156862745098 0.181818181818182 0.392156862745098 0.196078431372549 0.196078431372549 0.196078431372549 0.196078431372549 0.136363636363636 0.196078431372549 0.0490196078431373 0.0490196078431373 0.0490196078431373 0.0490196078431373 0.136363636363636 0.0490196078431373 0.00980392156862745 0.00980392156862745 0.00980392156862745 0.00980392156862745 0.0454545454545455 0.00980392156862745 0.0980392156862745 0.0980392156862745 0.0980392156862745 0.0980392156862745 0.181818181818182 0.0980392156862745]);
+
+i = stringmatch('BcloseFast', names);
+%bnet.CPD{i} = tabular_CPD(bnet, i, [0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0]);
+bnet.CPD{i+ss} = tabular_CPD(bnet, i+ss, [0.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0]);
+
+i = stringmatch('Bclr', names);
+%bnet.CPD{i} = tabular_CPD(bnet, i, [0.142857142857143 0.285714285714286 0.571428571428571]);
+bnet.CPD{i+ss} = tabular_CPD(bnet, i+ss, [0.142857142857143 0.285714285714286 0.571428571428571]);
+
+i = stringmatch('BYdotDiff', names);
+%bnet.CPD{i} = tabular_CPD(bnet, i, [0.238095238095238 0.476190476190476 0.238095238095238 0.0476190476190476]);
+bnet.CPD{i+ss} = tabular_CPD(bnet, i+ss, [0.238095238095238 0.476190476190476 0.238095238095238 0.0476190476190476]);
+
+i = stringmatch('LeftClrSens', names);
+%bnet.CPD{i} = tabular_CPD(bnet, i, [0.909090909090909 0.0909090909090909 0.0909090909090909 0.909090909090909]);
+bnet.CPD{i+ss} = tabular_CPD(bnet, i+ss, [0.909090909090909 0.0909090909090909 0.0909090909090909 0.909090909090909]);
+
+i = stringmatch('RightClrSens', names);
+%bnet.CPD{i} = tabular_CPD(bnet, i, [0.909090909090909 0.0909090909090909 0.0909090909090909 0.909090909090909]);
+bnet.CPD{i+ss} = tabular_CPD(bnet, i+ss, [0.909090909090909 0.0909090909090909 0.0909090909090909 0.909090909090909]);
+
+i = stringmatch('TurnSignalSens', names);
+%bnet.CPD{i} = tabular_CPD(bnet, i, [0.75 0.000998003992015968 0.01 0.24 0.998003992015968 0.24 0.01 0.000998003992015968 0.75]);
+bnet.CPD{i+ss} = tabular_CPD(bnet, i+ss, [0.75 0.000998003992015968 0.01 0.24 0.998003992015968 0.24 0.01 0.000998003992015968 0.75]);
+
+i = stringmatch('XdotSens', names);
+%bnet.CPD{i} = tabular_CPD(bnet, i, [0.142857142857143 0.897666068222621 0.142857142857143 0.0824402308326463 0.142857142857143 0.00818330605564648 0.142857142857143 0.000818330605564648 0.142857142857143 0.000818330605564648 0.142857142857143 0.000824402308326463 0.142857142857143 0.000897666068222621 0.142857142857143 0.0897666068222621 0.142857142857143 0.824402308326463 0.142857142857143 0.0818330605564648 0.142857142857143 0.00818330605564648 0.142857142857143 0.000818330605564648 0.142857142857143 0.000824402308326463 0.142857142857143 0.000897666068222621 0.142857142857143 0.00897666068222621 0.142857142857143 0.0824402308326463 0.142857142857143 0.818330605564648 0.142857142857143 0.0818330605564648 0.142857142857143 0.00818330605564648 0.142857142857143 0.000824402308326463 0.142857142857143 0.000897666068222621 0.142857142857143 0.000897666068222621 0.142857142857143 0.00824402308326463 0.142857142857143 0.0818330605564648 0.142857142857143 0.818330605564648 0.142857142857143 0.0818330605564648 0.142857142857143 0.00824402308326463 0.142857142857143 0.000897666068222621 0.142857142857143 0.000897666068222621 0.142857142857143 0.000824402308326463 0.142857142857143 0.00818330605564648 0.142857142857143 0.0818330605564648 0.142857142857143 0.818330605564648 0.142857142857143 0.0824402308326463 0.142857142857143 0.00897666068222621 0.142857142857143 0.000897666068222621 0.142857142857143 0.000824402308326463 0.142857142857143 0.000818330605564648 0.142857142857143 0.00818330605564648 0.142857142857143 0.0818330605564648 0.142857142857143 0.824402308326463 0.142857142857143 0.0897666068222621 0.142857142857143 0.000897666068222621 0.142857142857143 0.000824402308326463 0.142857142857143 0.000818330605564648 0.142857142857143 0.000818330605564648 0.142857142857143 0.00818330605564648 0.142857142857143 0.0824402308326463 0.142857142857143 0.897666068222621]);
+bnet.CPD{i+ss} = tabular_CPD(bnet, i+ss, [0.142857142857143 0.897666068222621 0.142857142857143 0.0824402308326463 0.142857142857143 0.00818330605564648 0.142857142857143 0.000818330605564648 0.142857142857143 0.000818330605564648 0.142857142857143 0.000824402308326463 0.142857142857143 0.000897666068222621 0.142857142857143 0.0897666068222621 0.142857142857143 0.824402308326463 0.142857142857143 0.0818330605564648 0.142857142857143 0.00818330605564648 0.142857142857143 0.000818330605564648 0.142857142857143 0.000824402308326463 0.142857142857143 0.000897666068222621 0.142857142857143 0.00897666068222621 0.142857142857143 0.0824402308326463 0.142857142857143 0.818330605564648 0.142857142857143 0.0818330605564648 0.142857142857143 0.00818330605564648 0.142857142857143 0.000824402308326463 0.142857142857143 0.000897666068222621 0.142857142857143 0.000897666068222621 0.142857142857143 0.00824402308326463 0.142857142857143 0.0818330605564648 0.142857142857143 0.818330605564648 0.142857142857143 0.0818330605564648 0.142857142857143 0.00824402308326463 0.142857142857143 0.000897666068222621 0.142857142857143 0.000897666068222621 0.142857142857143 0.000824402308326463 0.142857142857143 0.00818330605564648 0.142857142857143 0.0818330605564648 0.142857142857143 0.818330605564648 0.142857142857143 0.0824402308326463 0.142857142857143 0.00897666068222621 0.142857142857143 0.000897666068222621 0.142857142857143 0.000824402308326463 0.142857142857143 0.000818330605564648 0.142857142857143 0.00818330605564648 0.142857142857143 0.0818330605564648 0.142857142857143 0.824402308326463 0.142857142857143 0.0897666068222621 0.142857142857143 0.000897666068222621 0.142857142857143 0.000824402308326463 0.142857142857143 0.000818330605564648 0.142857142857143 0.000818330605564648 0.142857142857143 0.00818330605564648 0.142857142857143 0.0824402308326463 0.142857142857143 0.897666068222621]);
+
+i = stringmatch('YdotSens', names);
+%bnet.CPD{i} = tabular_CPD(bnet, i, [0.0909090909090909 0.894454382826476 0.0909090909090909 0.0821692686935086 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.0894454382826476 0.0909090909090909 0.821692686935086 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.00894454382826476 0.0909090909090909 0.0821692686935086 0.0909090909090909 0.815660685154976 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.00821692686935086 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.815660685154976 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.815660685154976 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.815660685154976 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.815660685154976 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.815660685154976 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.00821692686935086 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.815660685154976 0.0909090909090909 0.0821692686935086 0.0909090909090909 0.00894454382826476 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.821692686935086 0.0909090909090909 0.0894454382826476 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.0821692686935086 0.0909090909090909 0.894454382826476]);
+bnet.CPD{i+ss} = tabular_CPD(bnet, i+ss, [0.0909090909090909 0.894454382826476 0.0909090909090909 0.0821692686935086 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.0894454382826476 0.0909090909090909 0.821692686935086 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.00894454382826476 0.0909090909090909 0.0821692686935086 0.0909090909090909 0.815660685154976 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.00821692686935086 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.815660685154976 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.815660685154976 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.815660685154976 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.815660685154976 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.815660685154976 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.00821692686935086 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.815660685154976 0.0909090909090909 0.0821692686935086 0.0909090909090909 0.00894454382826476 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.0815660685154976 0.0909090909090909 0.821692686935086 0.0909090909090909 0.0894454382826476 0.0909090909090909 0.000894454382826476 0.0909090909090909 0.000821692686935086 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.000815660685154976 0.0909090909090909 0.00815660685154975 0.0909090909090909 0.0821692686935086 0.0909090909090909 0.894454382826476]);
+
+i = stringmatch('FYdotDiffSens', names);
+%bnet.CPD{i} = tabular_CPD(bnet, i, [0.53191206429753 0.00806445109313635 0.0053191206429753 9.9930048965724e-005 0.265956032148765 0.00806445109313635 0.0053191206429753 9.9930048965724e-005 0.132978016074383 0.0806445109313634 0.0053191206429753 9.9930048965724e-005 0.053191206429753 0.806445109313635 0.053191206429753 9.9930048965724e-005 0.0053191206429753 0.0806445109313634 0.132978016074383 9.9930048965724e-005 0.0053191206429753 0.00806445109313635 0.265956032148765 9.9930048965724e-005 0.0053191206429753 0.00806445109313635 0.53191206429753 9.9930048965724e-005 5.3191206429753e-006 8.06445109313635e-006 5.3191206429753e-006 0.99930048965724]);
+bnet.CPD{i+ss} = tabular_CPD(bnet, i+ss, [0.53191206429753 0.00806445109313635 0.0053191206429753 9.9930048965724e-005 0.265956032148765 0.00806445109313635 0.0053191206429753 9.9930048965724e-005 0.132978016074383 0.0806445109313634 0.0053191206429753 9.9930048965724e-005 0.053191206429753 0.806445109313635 0.053191206429753 9.9930048965724e-005 0.0053191206429753 0.0806445109313634 0.132978016074383 9.9930048965724e-005 0.0053191206429753 0.00806445109313635 0.265956032148765 9.9930048965724e-005 0.0053191206429753 0.00806445109313635 0.53191206429753 9.9930048965724e-005 5.3191206429753e-006 8.06445109313635e-006 5.3191206429753e-006 0.99930048965724]);
+
+i = stringmatch('FclrSens', names);
+%bnet.CPD{i} = tabular_CPD(bnet, i, [0.472366556447804 0.0044762757385855 6.20655412115194e-005 0.472366556447804 0.044762757385855 6.20655412115194e-005 0.0472366556447804 0.44762757385855 0.000620655412115194 0.000472366556447804 0.44762757385855 0.00620655412115194 0.000472366556447804 0.044762757385855 0.0620655412115194 0.000472366556447804 0.0044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194]);
+bnet.CPD{i+ss} = tabular_CPD(bnet, i+ss, [0.472366556447804 0.0044762757385855 6.20655412115194e-005 0.472366556447804 0.044762757385855 6.20655412115194e-005 0.0472366556447804 0.44762757385855 0.000620655412115194 0.000472366556447804 0.44762757385855 0.00620655412115194 0.000472366556447804 0.044762757385855 0.0620655412115194 0.000472366556447804 0.0044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194]);
+
+i = stringmatch('BXdotSens', names);
+%bnet.CPD{i} = tabular_CPD(bnet, i, [0.689655172413793 0.172413793103448 0.0546448087431694 0.00546448087431694 0.00546448087431694 0.00546448087431694 0.00574712643678161 0.00689655172413793 0.206896551724138 0.574712643678161 0.163934426229508 0.0546448087431694 0.00546448087431694 0.00546448087431694 0.00574712643678161 0.00689655172413793 0.0689655172413793 0.172413793103448 0.546448087431694 0.163934426229508 0.0546448087431694 0.00546448087431694 0.00574712643678161 0.00689655172413793 0.00689655172413793 0.0574712643678161 0.163934426229508 0.546448087431694 0.163934426229508 0.0546448087431694 0.00574712643678161 0.00689655172413793 0.00689655172413793 0.00574712643678161 0.0546448087431694 0.163934426229508 0.546448087431694 0.163934426229508 0.0574712643678161 0.00689655172413793 0.00689655172413793 0.00574712643678161 0.00546448087431694 0.0546448087431694 0.163934426229508 0.546448087431694 0.172413793103448 0.0689655172413793 0.00689655172413793 0.00574712643678161 0.00546448087431694 0.00546448087431694 0.0546448087431694 0.163934426229508 0.574712643678161 0.206896551724138 0.00689655172413793 0.00574712643678161 0.00546448087431694 0.00546448087431694 0.00546448087431694 0.0546448087431694 0.172413793103448 0.689655172413793]);
+bnet.CPD{i+ss} = tabular_CPD(bnet, i+ss, [0.689655172413793 0.172413793103448 0.0546448087431694 0.00546448087431694 0.00546448087431694 0.00546448087431694 0.00574712643678161 0.00689655172413793 0.206896551724138 0.574712643678161 0.163934426229508 0.0546448087431694 0.00546448087431694 0.00546448087431694 0.00574712643678161 0.00689655172413793 0.0689655172413793 0.172413793103448 0.546448087431694 0.163934426229508 0.0546448087431694 0.00546448087431694 0.00574712643678161 0.00689655172413793 0.00689655172413793 0.0574712643678161 0.163934426229508 0.546448087431694 0.163934426229508 0.0546448087431694 0.00574712643678161 0.00689655172413793 0.00689655172413793 0.00574712643678161 0.0546448087431694 0.163934426229508 0.546448087431694 0.163934426229508 0.0574712643678161 0.00689655172413793 0.00689655172413793 0.00574712643678161 0.00546448087431694 0.0546448087431694 0.163934426229508 0.546448087431694 0.172413793103448 0.0689655172413793 0.00689655172413793 0.00574712643678161 0.00546448087431694 0.00546448087431694 0.0546448087431694 0.163934426229508 0.574712643678161 0.206896551724138 0.00689655172413793 0.00574712643678161 0.00546448087431694 0.00546448087431694 0.00546448087431694 0.0546448087431694 0.172413793103448 0.689655172413793]);
+
+i = stringmatch('BclrSens', names);
+%bnet.CPD{i} = tabular_CPD(bnet, i, [0.472366556447804 0.0044762757385855 6.20655412115194e-005 0.472366556447804 0.044762757385855 6.20655412115194e-005 0.0472366556447804 0.44762757385855 0.000620655412115194 0.000472366556447804 0.44762757385855 0.00620655412115194 0.000472366556447804 0.044762757385855 0.0620655412115194 0.000472366556447804 0.0044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194]);
+bnet.CPD{i+ss} = tabular_CPD(bnet, i+ss, [0.472366556447804 0.0044762757385855 6.20655412115194e-005 0.472366556447804 0.044762757385855 6.20655412115194e-005 0.0472366556447804 0.44762757385855 0.000620655412115194 0.000472366556447804 0.44762757385855 0.00620655412115194 0.000472366556447804 0.044762757385855 0.0620655412115194 0.000472366556447804 0.0044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194 0.000472366556447804 0.00044762757385855 0.0620655412115194]);
+
+i = stringmatch('BYdotDiffSens', names);
+%bnet.CPD{i} = tabular_CPD(bnet, i, [0.53191206429753 0.00806445109313635 0.0053191206429753 9.9930048965724e-005 0.265956032148765 0.00806445109313635 0.0053191206429753 9.9930048965724e-005 0.132978016074383 0.0806445109313634 0.0053191206429753 9.9930048965724e-005 0.053191206429753 0.806445109313635 0.053191206429753 9.9930048965724e-005 0.0053191206429753 0.0806445109313634 0.132978016074383 9.9930048965724e-005 0.0053191206429753 0.00806445109313635 0.265956032148765 9.9930048965724e-005 0.0053191206429753 0.00806445109313635 0.53191206429753 9.9930048965724e-005 5.3191206429753e-006 8.06445109313635e-006 5.3191206429753e-006 0.99930048965724]);
+bnet.CPD{i+ss} = tabular_CPD(bnet, i+ss, [0.53191206429753 0.00806445109313635 0.0053191206429753 9.9930048965724e-005 0.265956032148765 0.00806445109313635 0.0053191206429753 9.9930048965724e-005 0.132978016074383 0.0806445109313634 0.0053191206429753 9.9930048965724e-005 0.053191206429753 0.806445109313635 0.053191206429753 9.9930048965724e-005 0.0053191206429753 0.0806445109313634 0.132978016074383 9.9930048965724e-005 0.0053191206429753 0.00806445109313635 0.265956032148765 9.9930048965724e-005 0.0053191206429753 0.00806445109313635 0.53191206429753 9.9930048965724e-005 5.3191206429753e-006 8.06445109313635e-006 5.3191206429753e-006 0.99930048965724]);
+%BIF2BNT added a bunch of zeros at the end of this cpd. Hopefully the only occurence of this bug!  0 0 0 0 0 0 0 0]);
\ No newline at end of file
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/mk_orig_water_dbn.m b/sourcecodes/bnt-master/BNT/examples/dynamic/mk_orig_water_dbn.m
new file mode 100644
index 00000000..67a4e24a
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/mk_orig_water_dbn.m
@@ -0,0 +1,121 @@
+function dbn = mk_orig_water_dbn
+% Converted by Frank Hutter:
+%   Provided in Phrog format by Xavier Boyen.
+%   Manually converted into BIF.
+%   Converted to BNT from BIF by Web-based bif2bnt (2004-01-30T05:28:10)
+%   Manually converted into function creating DBN.
+%   Manually changed the node numbering s.t. A-B-C-D-E-F-G-H from the BK paper correspond to 1-2-3-4-5-6-7-8
+
+node = struct('C_NI_12_ANT', 1, ...
+              'CKNI_12_ANT', 2, ...
+              'CBODD_12_ANT', 3, ...
+              'CNOD_12_ANT', 4, ...
+              'CBODN_12_ANT', 5, ...
+              'CNON_12_ANT', 6, ...
+              'CKND_12_ANT', 7, ...
+              'CKNN_12_ANT', 8, ...
+              'C_NI_12_OBS', 9, ...
+              'CKNI_12_OBS', 10, ...
+              'CBODD_12_OBS', 11, ...
+              'CNOD_12_OBS', 12, ...
+              'CBODN_12_OBS', 13, ...
+              'CNON_12_OBS', 14, ...
+              'CKND_12_OBS', 15, ...
+              'CKNN_12_OBS', 16, ...
+              'C_NI_12_ULT', 17, ...
+              'CKNI_12_ULT', 18, ...
+              'CBODD_12_ULT', 19, ...
+              'CNOD_12_ULT', 20, ...
+              'CBODN_12_ULT', 21, ...
+              'CNON_12_ULT', 22, ...
+              'CKND_12_ULT', 23, ...
+              'CKNN_12_ULT', 24);
+
+adjacency = zeros(24);
+adjacency([node.C_NI_12_ANT], node.C_NI_12_OBS) = 1;
+adjacency([node.CKNI_12_ANT], node.CKNI_12_OBS) = 1;
+adjacency([node.CBODD_12_ANT], node.CBODD_12_OBS) = 1;
+adjacency([node.CKND_12_ANT], node.CKND_12_OBS) = 1;
+adjacency([node.CNOD_12_ANT], node.CNOD_12_OBS) = 1;
+adjacency([node.CBODN_12_ANT], node.CBODN_12_OBS) = 1;
+adjacency([node.CKNN_12_ANT], node.CKNN_12_OBS) = 1;
+adjacency([node.CNON_12_ANT], node.CNON_12_OBS) = 1;
+adjacency([node.C_NI_12_ANT], node.C_NI_12_ULT) = 1;
+adjacency([node.CKNI_12_ANT], node.CKNI_12_ULT) = 1;
+adjacency([node.CBODN_12_ANT node.CNOD_12_ANT node.CBODD_12_ANT node.CKNI_12_ANT node.C_NI_12_ANT], node.CBODD_12_ULT) = 1;
+adjacency([node.CKNN_12_ANT node.CKND_12_ANT node.CKNI_12_ANT], node.CKND_12_ULT) = 1;
+adjacency([node.CNON_12_ANT node.CNOD_12_ANT node.CBODD_12_ANT], node.CNOD_12_ULT) = 1;
+adjacency([node.CNON_12_ANT node.CBODN_12_ANT node.CBODD_12_ANT], node.CBODN_12_ULT) = 1;
+adjacency([node.CKNN_12_ANT node.CKND_12_ANT], node.CKNN_12_ULT) = 1;
+adjacency([node.CNON_12_ANT node.CKNN_12_ANT node.CBODN_12_ANT node.CNOD_12_ANT], node.CNON_12_ULT) = 1;
+
+ss = 16;
+dnodes = 1:ss;
+ant = 1:8;
+onodes = 9:16;
+ult = 17:24;
+intra = adjacency(1:ss, 1:ss);
+inter_real = adjacency(ant, ult);
+inter = zeros(ss);
+inter(ant,1:length(ult)) = inter_real;
+
+eclass1 = 1:16;
+eclass2 = [17:24 9:16];
+
+value = {{'zz3num'; 'zz4num'; 'zz5num'; 'zz6num'}, ...
+         {'zz20mgl'; 'zz30mgl'; 'zz40mgl'}, ...
+         {'zz15mgl'; 'zz20mgl'; 'zz25mgl'; 'zz30mgl'}, ...
+         {'zz05mgl'; 'zz1mgl'; 'zz2mgl'; 'zz4mgl'}, ...
+         {'zz5mgl'; 'zz10mgl'; 'zz15mgl'; 'zz20mgl'}, ...
+         {'zz2mgl'; 'zz4mgl'; 'zz6mgl'; 'zz10mgl'}, ...
+         {'zz2mgl'; 'zz4mgl'; 'zz6mgl'}, ...
+         {'zz05mgl'; 'zz1mgl'; 'zz2mgl'}, ...
+         {'zz3num'; 'zz4num'; 'zz5num'; 'zz6num'}, ...
+         {'zz20mgl'; 'zz30mgl'; 'zz40mgl'}, ...
+         {'zz15mgl'; 'zz20mgl'; 'zz25mgl'; 'zz30mgl'}, ...
+         {'zz05mgl'; 'zz1mgl'; 'zz2mgl'; 'zz4mgl'}, ...
+         {'zz5mgl'; 'zz10mgl'; 'zz15mgl'; 'zz20mgl'}, ...
+         {'zz2mgl'; 'zz4mgl'; 'zz6mgl'; 'zz10mgl'}, ...
+         {'zz2mgl'; 'zz4mgl'; 'zz6mgl'}, ...
+         {'zz05mgl'; 'zz1mgl'; 'zz2mgl'}, ...
+         {'zz3num'; 'zz4num'; 'zz5num'; 'zz6num'}, ...
+         {'zz20mgl'; 'zz30mgl'; 'zz40mgl'}, ...
+         {'zz15mgl'; 'zz20mgl'; 'zz25mgl'; 'zz30mgl'}, ...
+         {'zz05mgl'; 'zz1mgl'; 'zz2mgl'; 'zz4mgl'}, ...
+         {'zz5mgl'; 'zz10mgl'; 'zz15mgl'; 'zz20mgl'}, ...
+         {'zz2mgl'; 'zz4mgl'; 'zz6mgl'; 'zz10mgl'}, ...
+         {'zz2mgl'; 'zz4mgl'; 'zz6mgl'}, ...
+         {'zz05mgl'; 'zz1mgl'; 'zz2mgl'}};
+          
+ns = zeros(1,24);
+for i=1:24
+    ns(i) = length(value{i});
+end
+
+dbn = mk_dbn(intra, inter, ns, 'discrete', dnodes, 'eclass1', eclass1, 'eclass2', eclass2, ...
+	      'observed', onodes);
+
+dbn.CPD{node.C_NI_12_ANT} = tabular_CPD(dbn, node.C_NI_12_ANT, 1/ns(1) * ones(1,ns(1)));
+dbn.CPD{node.CKNI_12_ANT} = tabular_CPD(dbn, node.CKNI_12_ANT, 1/ns(2) * ones(1,ns(2)));
+dbn.CPD{node.CBODD_12_ANT} = tabular_CPD(dbn, node.CBODD_12_ANT, 1/ns(3) * ones(1,ns(3)));
+dbn.CPD{node.CNOD_12_ANT} = tabular_CPD(dbn, node.CNOD_12_ANT, 1/ns(4) * ones(1,ns(4)));
+dbn.CPD{node.CBODN_12_ANT} = tabular_CPD(dbn, node.CBODN_12_ANT, 1/ns(5) * ones(1,ns(5)));
+dbn.CPD{node.CNON_12_ANT} = tabular_CPD(dbn, node.CNON_12_ANT, 1/ns(6) * ones(1,ns(6)));
+dbn.CPD{node.CKND_12_ANT} = tabular_CPD(dbn, node.CKND_12_ANT, 1/ns(7) * ones(1,ns(7)));
+dbn.CPD{node.CKNN_12_ANT} = tabular_CPD(dbn, node.CKNN_12_ANT, 1/ns(8) * ones(1,ns(8)));
+dbn.CPD{node.C_NI_12_OBS} = tabular_CPD(dbn, node.C_NI_12_OBS, [0.7 0.1 0.1 0.1 0.1 0.7 0.1 0.1 0.1 0.1 0.7 0.1 0.1 0.1 0.1 0.7]);
+dbn.CPD{node.CKNI_12_OBS} = tabular_CPD(dbn, node.CKNI_12_OBS, [0.8 0.1 0.1 0.1 0.8 0.1 0.1 0.1 0.8]);
+dbn.CPD{node.CBODD_12_OBS} = tabular_CPD(dbn, node.CBODD_12_OBS, [0.7 0.1 0.1 0.1 0.1 0.7 0.1 0.1 0.1 0.1 0.7 0.1 0.1 0.1 0.1 0.7]);
+dbn.CPD{node.CKND_12_OBS} = tabular_CPD(dbn, node.CKND_12_OBS, [0.8 0.1 0.1 0.1 0.8 0.1 0.1 0.1 0.8]);
+dbn.CPD{node.CNOD_12_OBS} = tabular_CPD(dbn, node.CNOD_12_OBS, [0.7 0.1 0.1 0.1 0.1 0.7 0.1 0.1 0.1 0.1 0.7 0.1 0.1 0.1 0.1 0.7]);
+dbn.CPD{node.CBODN_12_OBS} = tabular_CPD(dbn, node.CBODN_12_OBS, [0.7 0.1 0.1 0.1 0.1 0.7 0.1 0.1 0.1 0.1 0.7 0.1 0.1 0.1 0.1 0.7]);
+dbn.CPD{node.CKNN_12_OBS} = tabular_CPD(dbn, node.CKNN_12_OBS, [0.8 0.1 0.1 0.1 0.8 0.1 0.1 0.1 0.8]);
+dbn.CPD{node.CNON_12_OBS} = tabular_CPD(dbn, node.CNON_12_OBS, [0.7 0.1 0.1 0.1 0.1 0.7 0.1 0.1 0.1 0.1 0.7 0.1 0.1 0.1 0.1 0.7]);
+dbn.CPD{node.C_NI_12_ULT} = tabular_CPD(dbn, node.C_NI_12_ULT, [0.5 0.2 0.1 0 0.4 0.55 0.3 0.15 0.1 0.2 0.5 0.25 0 0.05 0.1 0.6]);
+dbn.CPD{node.CKNI_12_ULT} = tabular_CPD(dbn, node.CKNI_12_ULT, [0.48 0.2 0.04 0.48 0.6 0.48 0.04 0.2 0.48]);
+dbn.CPD{node.CBODD_12_ULT} = tabular_CPD(dbn, node.CBODD_12_ULT, [1 1 0.9791 0.9473 0.9949 0.9473 0.8997 0.8521 0.9473 0.8838 0.8203 0.7568 0.0903 0.0585 0.0268 0 0.0426 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0.9951 0.9634 1 0.9634 0.9158 0.8681 0.9634 0.8999 0.8364 0.7729 0.109 0.0773 0.0455 0.0138 0.0614 0.0138 0 0 0.0138 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0.9762 1 0.9762 0.9286 0.881 0.9762 0.9127 0.8493 0.7858 0.124 0.0923 0.0605 0.0288 0.0764 0.0288 0 0 0.0288 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0.9848 1 0.9848 0.9372 0.8896 0.9848 0.9213 0.8578 0.7943 0.134 0.1023 0.0705 0.0388 0.0864 0.0388 0 0 0.0388 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0.9791 0.9473 0.9156 0.9632 0.9156 0.8679 0.8203 0.9156 0.8521 0.7886 0.7251 0.0585 0.0268 0 0 0.0109 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0.9951 0.9634 0.9316 0.9793 0.9316 0.884 0.8364 0.9316 0.8681 0.8046 0.7412 0.0773 0.0455 0.0138 0 0.0296 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0.9762 0.9445 0.9921 0.9445 0.8969 0.8493 0.9445 0.881 0.8175 0.754 0.0923 0.0605 0.0288 0 0.0446 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0.9848 0.9531 1 0.9531 0.9054 0.8578 0.9531 0.8896 0.8261 0.7626 0.1023 0.0705 0.0388 0.007 0.0546 0.007 0 0 0.007 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.9791 0.9473 0.9156 0.8838 0.9314 0.8838 0.8362 0.7886 0.8838 0.8203 0.7568 0.6933 0.0268 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.9951 0.9634 0.9316 0.8999 0.9475 0.8999 0.8523 0.8046 0.8999 0.8364 0.7729 0.7094 0.0455 0.0138 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0.9762 0.9445 0.9127 0.9604 0.9127 0.8651 0.8175 0.9127 0.8493 0.7858 0.7223 0.0605 0.0288 0 0 0.0129 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0.9848 0.9531 0.9213 0.9689 0.9213 0.8737 0.8261 0.9213 0.8578 0.7943 0.7308 0.0705 0.0388 0.007 0 0.0229 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.9473 0.9156 0.8838 0.8521 0.8997 0.8521 0.8045 0.7568 0.8521 0.7886 0.7251 0.6616 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.9634 0.9316 0.8999 0.8681 0.9158 0.8681 0.8205 0.7729 0.8681 0.8046 0.7412 0.6777 0.0138 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.9762 0.9445 0.9127 0.881 0.9286 0.881 0.8334 0.7858 0.881 0.8175 0.754 0.6905 0.0288 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.9848 0.9531 0.9213 0.8896 0.9372 0.8896 0.842 0.7943 0.8896 0.8261 0.7626 0.6991 0.0388 0.007 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0209 0.0527 0.0051 0.0527 0.1003 0.1479 0.0527 0.1162 0.1797 0.2432 0.9097 0.9415 0.9732 0.995 0.9574 0.995 0.9474 0.8998 0.995 0.9315 0.868 0.8045 0.1362 0.1045 0.0727 0.041 0.0886 0.041 0 0 0.041 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0049 0.0366 0 0.0366 0.0842 0.1319 0.0366 0.1001 0.1636 0.2271 0.891 0.9227 0.9545 0.9862 0.9386 0.9862 0.9662 0.9185 0.9862 0.9503 0.8868 0.8233 0.157 0.1253 0.0935 0.0618 0.1094 0.0618 0.0142 0 0.0618 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0238 0 0.0238 0.0714 0.119 0.0238 0.0873 0.1507 0.2142 0.876 0.9077 0.9395 0.9712 0.9236 0.9712 0.9812 0.9335 0.9712 0.9653 0.9018 0.8383 0.1737 0.142 0.1102 0.0785 0.1261 0.0785 0.0308 0 0.0785 0.015 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0152 0 0.0152 0.0628 0.1104 0.0152 0.0787 0.1422 0.2057 0.866 0.8977 0.9295 0.9612 0.9136 0.9612 0.9912 0.9435 0.9612 0.9753 0.9118 0.8483 0.1848 0.1531 0.1213 0.0896 0.1372 0.0896 0.042 0 0.0896 0.0261 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0209 0.0527 0.0844 0.0368 0.0844 0.1321 0.1797 0.0844 0.1479 0.2114 0.2749 0.9415 0.9732 0.995 0.9633 0.9891 0.9633 0.9157 0.868 0.9633 0.8998 0.8363 0.7728 0.1045 0.0727 0.041 0.0092 0.0568 0.0092 0 0 0.0092 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0049 0.0366 0.0684 0.0207 0.0684 0.116 0.1636 0.0684 0.1319 0.1954 0.2588 0.9227 0.9545 0.9862 0.982 0.9704 0.982 0.9344 0.8868 0.982 0.9185 0.855 0.7916 0.1253 0.0935 0.0618 0.03 0.0777 0.03 0 0 0.03 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0238 0.0555 0.0079 0.0555 0.1031 0.1507 0.0555 0.119 0.1825 0.246 0.9077 0.9395 0.9712 0.997 0.9554 0.997 0.9494 0.9018 0.997 0.9335 0.87 0.8066 0.142 0.1102 0.0785 0.0467 0.0943 0.0467 0 0 0.0467 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0152 0.0469 0 0.0469 0.0946 0.1422 0.0469 0.1104 0.1739 0.2374 0.8977 0.9295 0.9612 0.993 0.9454 0.993 0.9594 0.9118 0.993 0.9435 0.88 0.8166 0.1531 0.1213 0.0896 0.0578 0.1054 0.0578 0.0102 0 0.0578 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0209 0.0527 0.0844 0.1162 0.0686 0.1162 0.1638 0.2114 0.1162 0.1797 0.2432 0.3067 0.9732 0.995 0.9633 0.9315 0.9792 0.9315 0.8839 0.8363 0.9315 0.868 0.8045 0.7411 0.0727 0.041 0.0092 0 0.0251 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0049 0.0366 0.0684 0.1001 0.0525 0.1001 0.1477 0.1954 0.1001 0.1636 0.2271 0.2906 0.9545 0.9862 0.982 0.9503 0.9979 0.9503 0.9027 0.855 0.9503 0.8868 0.8233 0.7598 0.0935 0.0618 0.03 0 0.0459 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0238 0.0555 0.0873 0.0396 0.0873 0.1349 0.1825 0.0873 0.1507 0.2142 0.2777 0.9395 0.9712 0.997 0.9653 0.9871 0.9653 0.9177 0.87 0.9653 0.9018 0.8383 0.7748 0.1102 0.0785 0.0467 0.015 0.0626 0.015 0 0 0.015 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0152 0.0469 0.0787 0.0311 0.0787 0.1263 0.1739 0.0787 0.1422 0.2057 0.2692 0.9295 0.9612 0.993 0.9753 0.9771 0.9753 0.9277 0.88 0.9753 0.9118 0.8483 0.7848 0.1213 0.0896 0.0578 0.0261 0.0737 0.0261 0 0 0.0261 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0527 0.0844 0.1162 0.1479 0.1003 0.1479 0.1955 0.2432 0.1479 0.2114 0.2749 0.3384 0.995 0.9633 0.9315 0.8998 0.9474 0.8998 0.8522 0.8045 0.8998 0.8363 0.7728 0.7093 0.041 0.0092 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0366 0.0684 0.1001 0.1319 0.0842 0.1319 0.1795 0.2271 0.1319 0.1954 0.2588 0.3223 0.9862 0.982 0.9503 0.9185 0.9662 0.9185 0.8709 0.8233 0.9185 0.855 0.7916 0.7281 0.0618 0.03 0 0 0.0142 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0238 0.0555 0.0873 0.119 0.0714 0.119 0.1666 0.2142 0.119 0.1825 0.246 0.3095 0.9712 0.997 0.9653 0.9335 0.9812 0.9335 0.8859 0.8383 0.9335 0.87 0.8066 0.7431 0.0785 0.0467 0.015 0 0.0308 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0152 0.0469 0.0787 0.1104 0.0628 0.1104 0.158 0.2057 0.1104 0.1739 0.2374 0.3009 0.9612 0.993 0.9753 0.9435 0.9912 0.9435 0.8959 0.8483 0.9435 0.88 0.8166 0.7531 0.0896 0.0578 0.0261 0 0.042 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.005 0 0.005 0.0526 0.1002 0.005 0.0685 0.132 0.1955 0.8638 0.8955 0.9273 0.959 0.9114 0.959 0.9933 0.9457 0.959 0.9775 0.914 0.8505 0.1809 0.1491 0.1174 0.0856 0.1333 0.0856 0.038 0 0.0856 0.0221 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0338 0.0815 0 0.0497 0.1132 0.1767 0.843 0.8747 0.9065 0.9382 0.8906 0.9382 0.9858 0.9666 0.9382 0.9983 0.9348 0.8713 0.2034 0.1716 0.1399 0.1081 0.1558 0.1081 0.0605 0.0129 0.1081 0.0446 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0188 0.0665 0 0.0347 0.0982 0.1617 0.8263 0.858 0.8898 0.9215 0.8739 0.9215 0.9692 0.9832 0.9215 0.985 0.9515 0.888 0.2214 0.1896 0.1579 0.1261 0.1738 0.1261 0.0785 0.0309 0.1261 0.0626 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0088 0.0565 0 0.0247 0.0882 0.1517 0.8152 0.8469 0.8787 0.9104 0.8628 0.9104 0.958 0.9943 0.9104 0.9739 0.9626 0.8991 0.2334 0.2016 0.1699 0.1381 0.1858 0.1381 0.0905 0.0429 0.1381 0.0746 0.0112 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.005 0.0367 0 0.0367 0.0843 0.132 0.0367 0.1002 0.1637 0.2272 0.8955 0.9273 0.959 0.9908 0.9432 0.9908 0.9616 0.914 0.9908 0.9457 0.8822 0.8187 0.1491 0.1174 0.0856 0.0539 0.1015 0.0539 0.0063 0 0.0539 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.018 0 0.018 0.0656 0.1132 0.018 0.0815 0.145 0.2084 0.8747 0.9065 0.9382 0.97 0.9223 0.97 0.9824 0.9348 0.97 0.9666 0.9031 0.8396 0.1716 0.1399 0.1081 0.0764 0.124 0.0764 0.0288 0 0.0764 0.0129 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.003 0 0.003 0.0506 0.0982 0.003 0.0665 0.13 0.1934 0.858 0.8898 0.9215 0.9533 0.9057 0.9533 0.9991 0.9515 0.9533 0.9832 0.9197 0.8562 0.1896 0.1579 0.1261 0.0944 0.142 0.0944 0.0468 0 0.0944 0.0309 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0406 0.0882 0 0.0565 0.12 0.1834 0.8469 0.8787 0.9104 0.9422 0.8946 0.9422 0.9898 0.9626 0.9422 0.9943 0.9308 0.8673 0.2016 0.1699 0.1381 0.1064 0.154 0.1064 0.0588 0.0112 0.1064 0.0429 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.005 0.0367 0.0685 0.0208 0.0685 0.1161 0.1637 0.0685 0.132 0.1955 0.2589 0.9273 0.959 0.9908 0.9775 0.9749 0.9775 0.9298 0.8822 0.9775 0.914 0.8505 0.787 0.1174 0.0856 0.0539 0.0221 0.0698 0.0221 0 0 0.0221 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.018 0.0497 0.0021 0.0497 0.0973 0.145 0.0497 0.1132 0.1767 0.2402 0.9065 0.9382 0.97 0.9983 0.9541 0.9983 0.9507 0.9031 0.9983 0.9348 0.8713 0.8078 0.1399 0.1081 0.0764 0.0446 0.0923 0.0446 0 0 0.0446 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.003 0.0347 0 0.0347 0.0823 0.13 0.0347 0.0982 0.1617 0.2252 0.8898 0.9215 0.9533 0.985 0.9374 0.985 0.9673 0.9197 0.985 0.9515 0.888 0.8245 0.1579 0.1261 0.0944 0.0626 0.1103 0.0626 0.015 0 0.0626 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0247 0 0.0247 0.0723 0.12 0.0247 0.0882 0.1517 0.2152 0.8787 0.9104 0.9422 0.9739 0.9263 0.9739 0.9785 0.9308 0.9739 0.9626 0.8991 0.8356 0.1699 0.1381 0.1064 0.0746 0.1223 0.0746 0.027 0 0.0746 0.0112 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.005 0.0367 0.0685 0.1002 0.0526 0.1002 0.1478 0.1955 0.1002 0.1637 0.2272 0.2907 0.959 0.9908 0.9775 0.9457 0.9933 0.9457 0.8981 0.8505 0.9457 0.8822 0.8187 0.7552 0.0856 0.0539 0.0221 0 0.038 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.018 0.0497 0.0815 0.0338 0.0815 0.1291 0.1767 0.0815 0.145 0.2084 0.2719 0.9382 0.97 0.9983 0.9666 0.9858 0.9666 0.9189 0.8713 0.9666 0.9031 0.8396 0.7761 0.1081 0.0764 0.0446 0.0129 0.0605 0.0129 0 0 0.0129 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.003 0.0347 0.0665 0.0188 0.0665 0.1141 0.1617 0.0665 0.13 0.1934 0.2569 0.9215 0.9533 0.985 0.9832 0.9692 0.9832 0.9356 0.888 0.9832 0.9197 0.8562 0.7927 0.1261 0.0944 0.0626 0.0309 0.0785 0.0309 0 0 0.0309 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0247 0.0565 0.0088 0.0565 0.1041 0.1517 0.0565 0.12 0.1834 0.2469 0.9104 0.9422 0.9739 0.9943 0.958 0.9943 0.9467 0.8991 0.9943 0.9308 0.8673 0.8039 0.1381 0.1064 0.0746 0.0429 0.0905 0.0429 0 0 0.0429 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0067 0.0543 0 0.0225 0.086 0.1495 0.8191 0.8509 0.8826 0.9144 0.8667 0.9144 0.962 1 0.9144 0.9779 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0334 0 0.0017 0.0652 0.1287 0.7966 0.8284 0.8601 0.8919 0.8442 0.8919 0.9395 0.9871 0.8919 0.9554 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0168 0 0 0.0485 0.112 0.7786 0.8104 0.8421 0.8739 0.8262 0.8739 0.9215 0.9691 0.8739 0.9374 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0057 0 0 0.0374 0.1009 0.7666 0.7984 0.8301 0.8619 0.8142 0.8619 0.9095 0.9571 0.8619 0.9254 0.9888 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0384 0.086 0 0.0543 0.1178 0.1813 0.8509 0.8826 0.9144 0.9461 0.8985 0.9461 0.9937 1 0.9461 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0176 0.0652 0 0.0334 0.0969 0.1604 0.8284 0.8601 0.8919 0.9236 0.876 0.9236 0.9712 1 0.9236 0.9871 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0009 0.0485 0 0.0168 0.0803 0.1438 0.8104 0.8421 0.8739 0.9056 0.858 0.9056 0.9532 1 0.9056 0.9691 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0374 0 0.0057 0.0692 0.1327 0.7984 0.8301 0.8619 0.8936 0.846 0.8936 0.9412 0.9888 0.8936 0.9571 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0225 0 0.0225 0.0702 0.1178 0.0225 0.086 0.1495 0.213 0.8826 0.9144 0.9461 0.9779 0.9302 0.9779 1 1 0.9779 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0017 0 0.0017 0.0493 0.0969 0.0017 0.0652 0.1287 0.1922 0.8601 0.8919 0.9236 0.9554 0.9077 0.9554 1 1 0.9554 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0327 0.0803 0 0.0485 0.112 0.1755 0.8421 0.8739 0.9056 0.9374 0.8897 0.9374 0.985 1 0.9374 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0215 0.0692 0 0.0374 0.1009 0.1644 0.8301 0.8619 0.8936 0.9254 0.8777 0.9254 0.973 1 0.9254 0.9888 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0225 0.0543 0.0067 0.0543 0.1019 0.1495 0.0543 0.1178 0.1813 0.2448 0.9144 0.9461 0.9779 1 0.962 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0017 0.0334 0 0.0334 0.0811 0.1287 0.0334 0.0969 0.1604 0.2239 0.8919 0.9236 0.9554 0.9871 0.9395 0.9871 1 1 0.9871 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0168 0 0.0168 0.0644 0.112 0.0168 0.0803 0.1438 0.2073 0.8739 0.9056 0.9374 0.9691 0.9215 0.9691 1 1 0.9691 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0057 0 0.0057 0.0533 0.1009 0.0057 0.0692 0.1327 0.1961 0.8619 0.8936 0.9254 0.9571 0.9095 0.9571 1 1 0.9571 1 1 1]);
+dbn.CPD{node.CKND_12_ULT} = tabular_CPD(dbn, node.CKND_12_ULT, [0.9524 0.9127 0.873 0 0 0 0 0 0 0.9444 0.9048 0.8651 0 0 0 0 0 0 0.9286 0.8889 0.8492 0 0 0 0 0 0 0.0476 0.0873 0.127 0.9921 0.9524 0.9127 0.0317 0 0 0.0556 0.0952 0.1349 0.9841 0.9444 0.9048 0.0238 0 0 0.0714 0.1111 0.1508 0.9683 0.9286 0.8889 0.0079 0 0 0 0 0 0.0079 0.0476 0.0873 0.9683 1 1 0 0 0 0.0159 0.0556 0.0952 0.9762 1 1 0 0 0 0.0317 0.0714 0.1111 0.9921 1 1]);
+dbn.CPD{node.CNOD_12_ULT} = tabular_CPD(dbn, node.CNOD_12_ULT, [1 1 1 1 0.3675 0.4905 0.5862 0.6627 0 0 0 0 0 0 0 0 1 1 1 1 0.2405 0.3635 0.4592 0.5358 0 0 0 0 0 0 0 0 0.8893 0.9816 1 1 0.1135 0.2366 0.3322 0.4088 0 0 0 0 0 0 0 0 0.6354 0.7276 0.7994 0.8568 0 0 0.0783 0.1548 0 0 0 0 0 0 0 0 0 0 0 0 0.6325 0.5095 0.4138 0.3373 0.2972 0.3711 0.4285 0.4744 0 0 0 0 0 0 0 0 0.7595 0.6365 0.5408 0.4642 0.2338 0.3076 0.365 0.4109 0 0 0 0 0.1107 0.0184 0 0 0.8865 0.7634 0.6678 0.5912 0.1703 0.2441 0.3015 0.3474 0 0 0 0 0.3646 0.2724 0.2006 0.1432 0.9298 0.9913 0.9217 0.8452 0.0433 0.1171 0.1745 0.2204 0 0 0 0 0 0 0 0 0 0 0 0 0.7028 0.6289 0.5715 0.5256 0.2129 0.2539 0.2858 0.3113 0 0 0 0 0 0 0 0 0.7662 0.6924 0.635 0.5891 0.1812 0.2222 0.2541 0.2796 0 0 0 0 0 0 0 0 0.8297 0.7559 0.6985 0.6526 0.1494 0.1904 0.2223 0.2478 0 0 0 0 0.0702 0.0087 0 0 0.9567 0.8829 0.8255 0.7796 0.0859 0.1269 0.1588 0.1843 0 0 0 0 0 0 0 0 0 0 0 0 0.7871 0.7461 0.7142 0.6887 0 0 0 0 0 0 0 0 0 0 0 0 0.8188 0.7778 0.7459 0.7204 0 0 0 0 0 0 0 0 0 0 0 0 0.8506 0.8096 0.7777 0.7522 0 0 0 0 0 0 0 0 0 0 0 0 0.9141 0.8731 0.8412 0.8157]);
+dbn.CPD{node.CBODN_12_ULT} = tabular_CPD(dbn, node.CBODN_12_ULT, [0.9557 0.9067 0.8577 0.8087 0.0406 0 0 0 0 0 0 0 0 0 0 0 0.9561 0.9071 0.8581 0.809 0.0412 0 0 0 0 0 0 0 0 0 0 0 0.9562 0.9072 0.8582 0.8092 0.0414 0 0 0 0 0 0 0 0 0 0 0 0.9564 0.9073 0.8583 0.8093 0.0416 0 0 0 0 0 0 0 0 0 0 0 0.0443 0.0933 0.1423 0.1913 0.9594 0.9916 0.9426 0.8936 0.1152 0.0662 0.0172 0 0 0 0 0 0.0439 0.0929 0.1419 0.191 0.9588 0.9922 0.9432 0.8942 0.116 0.067 0.018 0 0 0 0 0 0.0438 0.0928 0.1418 0.1908 0.9586 0.9924 0.9434 0.8944 0.1163 0.0673 0.0183 0 0 0 0 0 0.0436 0.0927 0.1417 0.1907 0.9584 0.9926 0.9436 0.8946 0.1166 0.0676 0.0185 0 0 0 0 0 0 0 0 0 0 0.0084 0.0574 0.1064 0.8848 0.9338 0.9828 0.9682 0.1835 0.1344 0.0854 0.0364 0 0 0 0 0 0.0078 0.0568 0.1058 0.884 0.933 0.982 0.969 0.1844 0.1354 0.0863 0.0373 0 0 0 0 0 0.0076 0.0566 0.1056 0.8837 0.9327 0.9817 0.9693 0.1847 0.1357 0.0867 0.0377 0 0 0 0 0 0.0074 0.0564 0.1054 0.8834 0.9324 0.9815 0.9695 0.185 0.136 0.087 0.038 0 0 0 0 0 0 0 0 0 0 0 0.0318 0.8165 0.8656 0.9146 0.9636 0 0 0 0 0 0 0 0 0 0 0 0.031 0.8156 0.8646 0.9137 0.9627 0 0 0 0 0 0 0 0 0 0 0 0.0307 0.8153 0.8643 0.9133 0.9623 0 0 0 0 0 0 0 0 0 0 0 0.0305 0.815 0.864 0.913 0.962]);
+dbn.CPD{node.CKNN_12_ULT} = tabular_CPD(dbn, node.CKNN_12_ULT, [1 1 0.8234 0.4459 0.2499 0.0538 0 0 0 0 0 0.1766 0.5541 0.7501 0.9462 0.3627 0.2646 0.1666 0 0 0 0 0 0 0.6373 0.7354 0.8334]);
+dbn.CPD{node.CNON_12_ULT} = tabular_CPD(dbn, node.CNON_12_ULT, [0.9555 0.9432 0.9187 0.8697 0.9618 0.9495 0.925 0.876 0.9662 0.954 0.9295 0.8804 0.9696 0.9573 0.9328 0.8838 0.9102 0.8979 0.8734 0.8244 0.9164 0.9042 0.8797 0.8306 0.9209 0.9086 0.8841 0.8351 0.9243 0.912 0.8875 0.8385 0.8648 0.8526 0.8281 0.779 0.8711 0.8588 0.8343 0.7853 0.8756 0.8633 0.8388 0.7898 0.8789 0.8667 0.8422 0.7931 0.0056 0 0 0 0.0125 0.0003 0 0 0.0175 0.0052 0 0 0.0212 0.009 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0445 0.0568 0.0813 0.1303 0.0382 0.0505 0.075 0.124 0.0338 0.046 0.0705 0.1196 0.0304 0.0427 0.0672 0.1162 0.0898 0.1021 0.1266 0.1756 0.0836 0.0958 0.1203 0.1694 0.0791 0.0914 0.1159 0.1649 0.0757 0.088 0.1125 0.1615 0.1352 0.1474 0.1719 0.221 0.1289 0.1412 0.1657 0.2147 0.1244 0.1367 0.1612 0.2102 0.1211 0.1333 0.1578 0.2069 0.9944 0.9933 0.9688 0.9198 0.9875 0.9997 0.9758 0.9267 0.9825 0.9948 0.9807 0.9317 0.9788 0.991 0.9845 0.9354 0.9602 0.948 0.9235 0.8744 0.9672 0.9549 0.9304 0.8814 0.9722 0.9599 0.9354 0.8864 0.9759 0.9636 0.9391 0.8901 0.9149 0.9026 0.8781 0.8291 0.9219 0.9096 0.8851 0.8361 0.9268 0.9146 0.8901 0.841 0.9306 0.9183 0.8938 0.8448 0.055 0.0427 0.0182 0 0.0622 0.05 0.0254 0 0.0674 0.0551 0.0306 0 0.0712 0.059 0.0345 0 0.0096 0 0 0 0.0169 0.0046 0 0 0.022 0.0098 0 0 0.0259 0.0137 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0067 0.0312 0.0802 0 0 0.0242 0.0733 0 0 0.0193 0.0683 0 0 0.0155 0.0646 0.0398 0.052 0.0765 0.1256 0.0328 0.0451 0.0696 0.1186 0.0278 0.0401 0.0646 0.1136 0.0241 0.0364 0.0609 0.1099 0.0851 0.0974 0.1219 0.1709 0.0781 0.0904 0.1149 0.1639 0.0732 0.0854 0.1099 0.159 0.0694 0.0817 0.1062 0.1552 0.945 0.9573 0.9818 0.9846 0.9378 0.95 0.9746 0.9882 0.9326 0.9449 0.9694 0.9908 0.9288 0.941 0.9655 0.9927 0.9904 0.9987 0.9864 0.9619 0.9831 0.9954 0.9901 0.9655 0.978 0.9902 0.9926 0.9681 0.9741 0.9863 0.9946 0.9701 0.9822 0.976 0.9638 0.9393 0.9858 0.9796 0.9674 0.9429 0.9884 0.9822 0.97 0.9455 0.9903 0.9842 0.9719 0.9474 0.0767 0.0706 0.0583 0.0338 0.0804 0.0743 0.062 0.0375 0.0831 0.0769 0.0647 0.0402 0.0851 0.0789 0.0667 0.0422 0.054 0.0479 0.0356 0.0111 0.0577 0.0516 0.0394 0.0149 0.0604 0.0543 0.042 0.0175 0.0624 0.0563 0.044 0.0195 0.0313 0.0252 0.013 0 0.0351 0.0289 0.0167 0 0.0377 0.0316 0.0194 0 0.0397 0.0336 0.0214 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0154 0 0 0 0.0118 0 0 0 0.0092 0 0 0 0.0073 0 0.0013 0.0136 0.0381 0 0 0.0099 0.0345 0 0 0.0074 0.0319 0 0 0.0054 0.0299 0.0178 0.024 0.0362 0.0607 0.0142 0.0204 0.0326 0.0571 0.0116 0.0178 0.03 0.0545 0.0097 0.0158 0.0281 0.0526 0.9233 0.9294 0.9417 0.9662 0.9196 0.9257 0.938 0.9625 0.9169 0.9231 0.9353 0.9598 0.9149 0.9211 0.9333 0.9578 0.946 0.9521 0.9644 0.9889 0.9423 0.9484 0.9606 0.9851 0.9396 0.9457 0.958 0.9825 0.9376 0.9437 0.956 0.9805 0.9687 0.9748 0.987 1 0.9649 0.9711 0.9833 1 0.9623 0.9684 0.9806 1 0.9603 0.9664 0.9786 1]);
\ No newline at end of file
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/mk_ps_from_clqs.m b/sourcecodes/bnt-master/BNT/examples/dynamic/mk_ps_from_clqs.m
new file mode 100644
index 00000000..6e469446
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/mk_ps_from_clqs.m
@@ -0,0 +1,44 @@
+function mk_ps_from_clqs(dbn, T, cliques, dir)
+
+% Draw multiple copies of the DBN,
+% and indicate the nodes in each clique by shading the nodes.
+% Generate a series of color postscript files,
+% or, if dir=[], displays them to the screen and pauses.
+
+if isempty(dir)
+  print_to_file = 0;
+else
+  print_to_file = 1;
+end
+
+if print_to_file, cd(dir), end
+flip = 1;
+clf;
+[dummyx, dummyy, h] = draw_dbn(dbn.intra, dbn.inter, flip, T, -1);
+
+C = length(cliques);
+
+% nodes = [];
+% for i=1:C
+%   cl = cliques{i};
+%   nodes = [nodes cl(:)'];
+% end
+%nodes = unique(nodes);
+ss = length(dbn.intra);
+nodes = 1:(ss*T);
+
+for c=1:C
+  for i=cliques{c}
+    set(h(i,2), 'facecolor', 'r'); 
+  end
+  rest = mysetdiff(nodes, cliques{c});
+  for i=rest
+    set(h(i,2), 'facecolor', 'w'); 
+  end
+  if print_to_file
+    print(gcf, '-depsc', sprintf('clq%d.ps', c))
+  else
+   disp(['clique ' num2str(c) ' = ' num2str(cliques{c}) '; hit key for next'])
+    pause
+  end
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/mk_uffe_dbn.m b/sourcecodes/bnt-master/BNT/examples/dynamic/mk_uffe_dbn.m
new file mode 100644
index 00000000..2e881dc1
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/mk_uffe_dbn.m
@@ -0,0 +1,14 @@
+function bnet = mk_uffe_dbn()
+
+% Make the Uffe DBN from fig 3.4 p55 of my thesis
+
+ss = 4;
+intra = zeros(ss,ss);
+intra(1,[2 3])=1;
+intra(2,3)=1;
+intra(3,4)=1;
+inter = zeros(ss,ss);
+inter(1,1)=1;
+inter(4,4)=1;
+ns = 2*ones(1,ss);
+bnet = mk_dbn(intra, inter, ns);
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/mk_water_dbn.m b/sourcecodes/bnt-master/BNT/examples/dynamic/mk_water_dbn.m
new file mode 100644
index 00000000..38cc5124
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/mk_water_dbn.m
@@ -0,0 +1,68 @@
+function bnet = mk_water_dbn(discrete_obs, obs_leaves)
+% MK_WATER_DBN
+% bnet = mk_water_dbn(discrete_obs, obs_leaves)
+%
+% If discrete_obs = 1 (default), the leaves are binary, else scalar Gaussians
+% If obs_leaves = 1, all the leaves are observed, otherwise rnd nodes are observed
+%
+% This is a model of the biological processes of a water purification plant, developed
+% by Finn V. Jensen, Uffe Kjærulff, Kristian G. Olesen, and Jan Pedersen.
+% See http://www-nt.cs.berkeley.edu/home/nir/public_html/Repository/water.htm
+% See also Boyen and Koller, "Tractable Inference for Complex Stochastic Processes", UAI98
+
+if nargin < 1, discrete_obs = 1; end
+if nargin < 1, obs_leaves = 1; end
+
+ss = 12;
+intra = zeros(ss);
+intra(1,9) = 1;
+intra(3,10) = 1;
+intra(4,11) = 1;
+intra(8,12) = 1;
+
+inter = zeros(ss);
+inter(1, [1 3]) = 1;
+inter(2, [2 3 7]) = 1;
+inter(3, [3 4 5]) = 1;
+inter(4, [3 4 6]) = 1;
+inter(5, [3 5 6]) = 1;
+inter(6, [4 5 6]) = 1;
+inter(7, [7 8]) = 1;
+inter(8, [6 7 8]) = 1;
+
+if obs_leaves
+  onodes = 9:12; % leaves
+else
+  onodes = [1 5 9:12]; % throw in some other nodes
+end
+hnodes = 1:8;
+if discrete_obs
+  ns = 2*ones(1 ,ss);
+  dnodes = 1:ss;
+else
+  ns = [2*ones(1,length(hnodes)) 1*ones(length(onodes))];
+  dnodes = hnodes;
+end
+
+eclass1 = 1:12;
+eclass2 = [13:20 9:12];
+bnet = mk_dbn(intra, inter, ns, 'discrete', dnodes, 'eclass1', eclass1, 'eclass2', eclass2, ...
+	      'observed', onodes);
+if discrete_obs
+  for i=1:max(eclass2)
+    bnet.CPD{i} = tabular_CPD(bnet, i);
+  end
+else
+  for i=hnodes(:)'
+    bnet.CPD{i} = tabular_CPD(bnet, i);
+  end
+  for i=onodes(:)'
+    bnet.CPD{i} = gaussian_CPD(bnet, i);
+  end
+  for i=hnodes(:)'+ss
+    bnet.CPD{i} = tabular_CPD(bnet, i);
+  end
+end
+
+
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/orig_water1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/orig_water1.m
new file mode 100644
index 00000000..7daa533c
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/orig_water1.m
@@ -0,0 +1,28 @@
+% Compare the speeds of various inference engines on the water DBN
+seed = 0;
+rand('state', seed);
+randn('state', seed);
+
+%bnet = mk_water_dbn;
+bnet = mk_orig_water_dbn;
+
+T = 3;
+engine = {};
+%engine{end+1} = smoother_engine(jtree_2TBN_inf_engine(bnet));
+%engine{end+1} = smoother_engine(hmm_2TBN_inf_engine(bnet));
+%engine{end+1} = jtree_dbn_inf_engine(bnet);
+engine{end+1} = jtree_unrolled_dbn_inf_engine(bnet, T);
+engine{end+1} = cbk_inf_engine(bnet, 'clusters', {[1],[2],[3],[4],[5],[6],[7],[8]}); %ff
+engine{end+1} = cbk_inf_engine(bnet, 'clusters', {[1 2],[3 4 5 6],[7 8]}); %manually designed marginally independent by BK
+engine{end+1} = cbk_inf_engine(bnet, 'clusters', {[1:5], [3:7], [7:8]}); %manually designed conditionally independent by BK
+engine{end+1} = cbk_inf_engine(bnet, 'clusters', {[1 3], [2 3 7], [3 5], [3 4 7], [6 7 8]}); %automatically found using TJTs offline 
+engine{end+1} = cbk_inf_engine(bnet, 'clusters', {[1 3 5], [2 3 5 7], [3 4 7], [4 6 7], [6 7 8]}); %automatically found using TJTs offline 
+engine{end+1} = cbk_inf_engine(bnet, 'clusters', {[1 3 4 5], [2 3 4 7 8], [4 6 7 8]}); %automatically found using TJTs offline 
+
+% bk_inf_engine yields exactly the same results for the marginally independent cases. 
+%engine{end+1} = bk_inf_engine(bnet, 'clusters', 'ff');
+%engine{end+1} = bk_inf_engine(bnet, 'clusters', { [1 2], [3 4 5 6], [7 8] });
+
+
+inf_time = cmp_inference_dbn(bnet, engine, T, 'exact', 1)
+learning_time = cmp_learning_dbn(bnet, engine, T, 'exact', 1)
\ No newline at end of file
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/reveal1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/reveal1.m
new file mode 100644
index 00000000..938f4b46
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/reveal1.m
@@ -0,0 +1,73 @@
+% Make a DBN with the following inter-connectivity matrix
+%    1
+%   /  \
+%  2   3
+%   \ /
+%    4 
+%    |
+%    5
+% where all arcs point down. In addition, there are persistence arcs from each node to itself.
+% There are no intra-slice connections.
+% Nodes have noisy-or CPDs.
+% Node 1 turns on spontaneously due to its leaky source.
+% This effect trickles down to the other nodes in the order shown.
+% All the other nodes inhibit their leaks.
+% None of the nodes inhibit the connection from themselves, so that once they are on, they remain
+% on (persistence).
+%
+% This model was used in the experiments reported in
+% - "Learning the structure of DBNs", Friedman, Murphy and Russell, UAI 1998.
+% where the structure was learned even in the presence of missing data.
+% In that paper, we used the structural EM algorithm.
+% Here, we assume full observability and tabular CPDs for the learner, so we can use a much
+% simpler learning algorithm.
+
+ss = 5;
+
+inter = eye(ss);
+inter(1,[2 3]) = 1;
+inter(2,4)=1;
+inter(3,4)=1;
+inter(4,5)=1;
+
+intra = zeros(ss);
+ns = 2*ones(1,ss);
+
+bnet = mk_dbn(intra, inter, ns);
+
+% All nodes start out off
+for i=1:ss
+  bnet.CPD{i} = tabular_CPD(bnet, i, [1.0 0.0]');
+end
+
+% The following params correspond to Fig 4a in the UAI 98 paper
+% The first arg is the leak inhibition prob.
+% The vector contains the inhib probs from the parents in the previous slice;
+% the last element is self, which is never inhibited.
+bnet.CPD{1+ss} = noisyor_CPD(bnet, 1+ss, 0.8, 0);
+bnet.CPD{2+ss} = noisyor_CPD(bnet, 2+ss, 1, [0.9 0]);
+bnet.CPD{3+ss} = noisyor_CPD(bnet, 3+ss, 1, [0.8 0]);
+bnet.CPD{4+ss} = noisyor_CPD(bnet, 4+ss, 1, [0.7 0.6 0]);
+bnet.CPD{5+ss} = noisyor_CPD(bnet, 5+ss, 1, [0.5 0]);
+
+
+% Generate some training data
+
+nseqs = 20;
+seqs = cell(1,nseqs);
+T = 30;
+for i=1:nseqs
+  seqs{i} = sample_dbn(bnet, T);
+end
+
+max_fan_in = 3; % let's cheat a little here
+
+% computing num. incorrect edges as a fn of the size of the training set
+%sz = [5 10 15 20];    
+sz = [5 10];    
+h = zeros(1, length(sz));
+for i=1:length(sz)
+  inter2 = learn_struct_dbn_reveal(seqs(1:sz(i)), ns, max_fan_in);
+  h(i) = sum(abs(inter(:)-inter2(:))); % hamming distance
+end
+h
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/scg_dbn.m b/sourcecodes/bnt-master/BNT/examples/dynamic/scg_dbn.m
new file mode 100644
index 00000000..7281e58c
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/scg_dbn.m
@@ -0,0 +1,39 @@
+% Test whether stable conditional Gaussian inference works
+% Make a linear dynamical system
+%   X1 -> X2
+%   |     | 
+%   v     v
+%   Y1    Y2 
+
+intra = zeros(2);
+intra(1,2) = 1;
+inter = zeros(2);
+inter(1,1) = 1;
+n = 2;
+
+X = 2; % size of hidden state
+Y = 2; % size of observable state
+
+ns = [X Y];
+bnet = mk_dbn(intra, inter, ns, 'discrete', [], 'observed', 2);
+
+x0 = rand(X,1);
+V0 = eye(X);
+C0 = rand(Y,X);
+R0 = eye(Y);
+A0 = rand(X,X);
+Q0 = eye(X);
+
+bnet.CPD{1} = gaussian_CPD(bnet, 1, 'mean', x0, 'cov', V0);
+bnet.CPD{2} = gaussian_CPD(bnet, 2, 'mean', zeros(Y,1), 'cov', R0, 'weights', C0);
+bnet.CPD{3} = gaussian_CPD(bnet, 3, 'mean', zeros(X,1), 'cov', Q0, 'weights', A0);
+
+
+T = 5; % fixed length sequences
+
+engine = {};
+engine{end+1} = kalman_inf_engine(bnet);
+engine{end+1} = scg_unrolled_dbn_inf_engine(bnet, T);
+engine{end+1} = jtree_unrolled_dbn_inf_engine(bnet, T);
+
+inf_time = cmp_inference_dbn(bnet, engine, T, 'check_ll', 0);
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/skf_data_assoc_gmux.m b/sourcecodes/bnt-master/BNT/examples/dynamic/skf_data_assoc_gmux.m
new file mode 100644
index 00000000..31fdeda9
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/skf_data_assoc_gmux.m
@@ -0,0 +1,139 @@
+% We consider a switching Kalman filter of the kind studied
+% by Zoubin Ghahramani, i.e., where the switch node determines
+% which of the hidden chains we get to observe (data association).
+% e.g., for n=2 chains
+% 
+% X1 -> X1
+% | X2 -> X2
+% \ |
+%  v
+%  Y
+%  ^
+%  |
+%  S
+%
+% Y is a gmux (multiplexer) node, where S switches in one of the parents.
+% We differ from Zoubin by not connecting the S nodes over time (which
+% doesn't make sense for data association).
+% Indeed, we assume the S nodes are always observed.
+% 
+%
+% We will track 2 objects (points) moving in the plane, as in BNT/Kalman/tracking_demo.
+% We will alternate between observing them.
+
+nobj = 2;
+N = nobj+2;
+Xs = 1:nobj;
+S = nobj+1;
+Y = nobj+2;
+
+intra = zeros(N,N);
+inter = zeros(N,N);
+intra([Xs S], Y) =1;
+for i=1:nobj
+  inter(Xs(i), Xs(i))=1;
+end
+
+Xsz = 4; % state space = (x y xdot ydot)
+Ysz = 2;
+ns = zeros(1,N);
+ns(Xs) = Xsz;
+ns(Y) = Ysz;
+ns(S) = n;
+
+bnet = mk_dbn(intra, inter, ns, 'discrete', S, 'observed', [S Y]);
+
+% For each object, we have
+% X(t+1) = F X(t) + noise(Q)
+% Y(t) = H X(t) + noise(R)
+F = [1 0 1 0; 0 1 0 1; 0 0 1 0; 0 0 0 1];
+H = [1 0 0 0; 0 1 0 0];
+Q = 1e-3*eye(Xsz);
+%R = 1e-3*eye(Ysz);
+R = eye(Ysz);
+
+% We initialise object 1 moving to the right, and object 2 moving to the left
+% (Here, we assume nobj=2)
+init_state{1} = [10 10 1 0]';
+init_state{2} = [10 -10 -1 0]';
+
+for i=1:nobj
+  bnet.CPD{Xs(i)} = gaussian_CPD(bnet, Xs(i), 'mean', init_state{i}, 'cov', 1e-4*eye(Xsz));
+end
+bnet.CPD{S} = root_CPD(bnet, S); % always observed
+bnet.CPD{Y} = gmux_CPD(bnet, Y, 'cov', repmat(R, [1 1 nobj]), 'weights', repmat(H, [1 1 nobj]));
+% slice 2
+eclass = bnet.equiv_class;
+for i=1:nobj
+  bnet.CPD{eclass(Xs(i), 2)} = gaussian_CPD(bnet, Xs(i)+N, 'mean', zeros(Xsz,1), 'cov', Q, 'weights', F);
+end
+
+% Observe objects at random
+T = 10;
+evidence = cell(N, T);
+data_assoc = sample_discrete(normalise(ones(1,nobj)), 1, T);
+evidence(S,:) = num2cell(data_assoc);
+evidence = sample_dbn(bnet, 'evidence', evidence);
+
+% plot the data
+true_state = cell(1,nobj);
+for i=1:nobj
+  true_state{i} = cell2num(evidence(Xs(i), :)); % true_state{i}(:,t) = [x y xdot ydot]'
+end
+obs_pos = cell2num(evidence(Y,:));
+figure(1)
+clf
+hold on
+styles = {'rx', 'go', 'b+', 'k*'};
+for i=1:nobj
+  plot(true_state{i}(1,:), true_state{i}(2,:), styles{i});
+end
+for t=1:T
+  text(obs_pos(1,t), obs_pos(2,t), sprintf('%d', t));
+end
+hold off
+relax_axes(0.1)
+
+
+% Inference
+ev = cell(N,T);
+ev(bnet.observed,:) = evidence(bnet.observed, :);
+
+engines = {};
+engines{end+1} = jtree_dbn_inf_engine(bnet);
+%engines{end+1} = scg_unrolled_dbn_inf_engine(bnet, T);
+engines{end+1} = pearl_unrolled_dbn_inf_engine(bnet);
+E = length(engines);
+
+inferred_state = cell(nobj,E); % inferred_state{i,e}(:,t)
+for e=1:E
+  engines{e} = enter_evidence(engines{e}, ev);
+  for i=1:nobj
+    inferred_state{i,e} = zeros(4, T);
+    for t=1:T
+      m = marginal_nodes(engines{e}, Xs(i), t);
+      inferred_state{i,e}(:,t) = m.mu;
+    end
+  end
+end
+inferred_state{1,1}
+inferred_state{1,2}
+
+% Plot results
+figure(2)
+clf
+hold on
+styles = {'rx', 'go', 'b+', 'k*'};
+nstyles = length(styles);
+c = 1;
+for e=1:E
+  for i=1:nobj
+    plot(inferred_state{i,e}(1,:), inferred_state{i,e}(2,:), styles{mod(c-1,nstyles)+1});
+    c = c + 1;
+  end
+end
+for t=1:T
+  text(obs_pos(1,t), obs_pos(2,t), sprintf('%d', t));
+end
+hold off
+relax_axes(0.1)
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/viterbi1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/viterbi1.m
new file mode 100644
index 00000000..6ad07d91
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/viterbi1.m
@@ -0,0 +1,47 @@
+% Compute Viterbi path discrete HMM by different methods
+
+intra = zeros(2);
+intra(1,2) = 1;
+inter = zeros(2);
+inter(1,1) = 1;
+n = 2;
+
+Q = 2; % num hidden states
+O = 2; % num observable symbols
+
+ns = [Q O];
+dnodes = 1:2;
+onodes = [2];
+eclass1 = [1 2];
+eclass2 = [3 2];
+bnet = mk_dbn(intra, inter, ns, 'discrete', dnodes, 'eclass1', eclass1, 'eclass2', eclass2, ...
+	      'observed', onodes);
+
+for seed=1:10
+rand('state', seed);
+prior = normalise(rand(Q,1));
+transmat = mk_stochastic(rand(Q,Q));
+obsmat = mk_stochastic(rand(Q,O));
+bnet.CPD{1} = tabular_CPD(bnet, 1, prior);
+bnet.CPD{2} = tabular_CPD(bnet, 2, obsmat);
+bnet.CPD{3} = tabular_CPD(bnet, 3, transmat);
+
+
+% Create a sequence
+T = 5; 
+ev = sample_dbn(bnet, T);
+evidence = cell(2,T);
+evidence(2,:) = ev(2,:); % extract observed component
+data = cell2num(ev(2,:));
+
+%obslik = mk_dhmm_obs_lik(data, obsmat);
+obslik = multinomial_prob(data, obsmat);
+path = viterbi_path(prior, transmat, obslik);
+
+engine = {};
+engine{end+1} = smoother_engine(jtree_2TBN_inf_engine(bnet));
+
+mpe = find_mpe(engine{1}, evidence);
+
+assert(isequal(cell2num(mpe(1,:)), path)) % extract values of hidden nodes
+end
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/water1.m b/sourcecodes/bnt-master/BNT/examples/dynamic/water1.m
new file mode 100644
index 00000000..7dcf205f
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/water1.m
@@ -0,0 +1,20 @@
+% Compare the speeds of various inference engines on the water DBN
+seed = 0;
+rand('state', seed);
+randn('state', seed);
+
+bnet = mk_water_dbn;
+
+T = 3;
+engine = {};
+engine{end+1} = smoother_engine(jtree_2TBN_inf_engine(bnet));
+engine{end+1} = smoother_engine(hmm_2TBN_inf_engine(bnet));
+engine{end+1} = jtree_dbn_inf_engine(bnet);
+engine{end+1} = jtree_unrolled_dbn_inf_engine(bnet, T); 
+
+%engine{end+1} = bk_inf_engine(bnet, 'ff', onodes);
+%engine{end+1} = bk_inf_engine(bnet, { [1 2], [3 4 5 6], [7 8] }, onodes);
+
+inf_time = cmp_inference_dbn(bnet, engine, T)
+learning_time = cmp_learning_dbn(bnet, engine, T)
+
diff --git a/sourcecodes/bnt-master/BNT/examples/dynamic/water2.m b/sourcecodes/bnt-master/BNT/examples/dynamic/water2.m
new file mode 100644
index 00000000..f7b9a42e
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/examples/dynamic/water2.m
@@ -0,0 +1,22 @@
+% Compare the speeds of various inference engines on the water DBN
+seed = 0;
+rand('state', seed);
+randn('state', seed);
+
+bnet = mk_water_dbn;
+
+T = 3;
+
+engine = {};
+engine{end+1} = smoother_engine(jtree_2TBN_inf_engine(bnet));
+engine{end+1} = smoother_engine(jtree_sparse_2TBN_inf_engine(bnet));
+engine{end+1} = smoother_engine(hmm_2TBN_inf_engine(bnet));
+engine{end+1} = jtree_dbn_inf_engine(bnet);
+%engine{end+1} = jtree_unrolled_dbn_inf_engine(bnet, T); 
+
+%engine{end+1} = bk_inf_engine(bnet, 'ff', onodes);
+%engine{end+1} = bk_inf_engine(bnet, { [1 2], [3 4 5 6], [7 8] }, onodes);
+
+inf_time = cmp_inference_dbn(bnet, engine, T)
+%learning_time = cmp_learning_dbn(bnet, engine, T)
+