about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/examples/dynamic/mk_chmm.m
diff options
context:
space:
mode:
authorziejd22017-09-28 15:04:40 -0500
committerziejd22017-09-28 15:04:40 -0500
commit8070dc963753142bb86c4ed698d91fd623ed28e7 (patch)
treed0f6dd8fc46a49b819aa55c1a90faa14d8448883 /sourcecodes/bnt-master/BNT/examples/dynamic/mk_chmm.m
parent7cc31810d53176e805532b2789955f4eedbce6bb (diff)
downloadBNW-8070dc963753142bb86c4ed698d91fd623ed28e7.tar.gz
BNW using Octave instead of Matlab.
This version of BNW should perform the same as the original version. The only difference is that it uses Octave instead of Matlab when running BayesNet Toolbox during parameter learning.

I am calling this BNW_1.02. It can be accessed at:
compbio.uthsc.edu/BNW_1.02
Diffstat (limited to 'sourcecodes/bnt-master/BNT/examples/dynamic/mk_chmm.m')
-rw-r--r--sourcecodes/bnt-master/BNT/examples/dynamic/mk_chmm.m103
1 files changed, 103 insertions, 0 deletions
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
+
+