about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/CPDs/@hhmmQ_CPD/update_CPT.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/CPDs/@hhmmQ_CPD/update_CPT.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/CPDs/@hhmmQ_CPD/update_CPT.m')
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@hhmmQ_CPD/update_CPT.m70
1 files changed, 70 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@hhmmQ_CPD/update_CPT.m b/sourcecodes/bnt-master/BNT/CPDs/@hhmmQ_CPD/update_CPT.m
new file mode 100644
index 00000000..9ed1a352
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@hhmmQ_CPD/update_CPT.m
@@ -0,0 +1,70 @@
+function CPD = update_CPT(CPD)
+% Compute the big CPT for an HHMM Q node (including F parents) given internal transprob and startprob
+% function CPD = update_CPT(CPD)
+
+Qsz = CPD.Qsz;
+Qpsz = CPD.Qpsz;
+
+if ~isempty(CPD.Fbelow_ndx)
+  if ~isempty(CPD.Fself_ndx) % general case
+    % Fb(t-1) Fself(t-1)  P(Q(t)=j| Q(t-1)=i, Qps(t)=k)
+    % ------------------------------------------------------
+    % 1        1         delta(i,j)
+    % 2        1         transprob(i,k,j)
+    % 1        2         impossible
+    % 2        2         startprob(k,j)
+    CPT = zeros(Qsz, 2, 2, Qpsz, Qsz);
+    I = repmat(eye(Qsz), [1 1 Qpsz]); % i,j,k
+    I = permute(I, [1 3 2]); % i,k,j
+    CPT(:, 1, 1, :, :) = I;
+    CPT(:, 2, 1, :, :) = CPD.transprob;
+    CPT(:, 1, 2, :, :) = I;
+    CPT(:, 2, 2, :, :) = repmat(reshape(CPD.startprob, [1 Qpsz Qsz]), ...
+				[Qsz 1 1]); % replicate  over i 
+  else % no F from self, hence no startprob
+    % Fb(t-1) P(Q(t)=j| Q(t-1)=i, Qps(t)=k)
+    % ------------------------------------------------------
+    % 1       delta(i,j)
+    % 2       transprob(i,k,j)
+    
+    nps = length(CPD.dom_sz)-1; % num parents
+    CPT = 0*myones(CPD.dom_sz);
+    %CPT = zeros(Qsz, 2, Qpsz, Qsz); % assumes CPT(Q(t-1), F(t-1), Qps, Q(t))
+    % but a member of Qps may preceed Q(t-1) or F(t-1) in the ordering
+
+    for k=1:CPD.Qpsz
+      Qps_vals = ind2subv(CPD.Qpsizes, k);
+      ndx = mk_multi_index(nps+1, [CPD.Fbelow_ndx CPD.Qps_ndx], [1 Qps_vals]);
+      CPT(ndx{:}) = eye(Qsz); % CPT(:,2,k,:) or CPT(:,k,2,:) etc
+    end
+    ndx = mk_multi_index(nps+1, CPD.Fbelow_ndx, 2);
+    CPT(ndx{:}) = CPD.transprob; % we assume transprob is in topo order
+  end
+else % no F signal from below
+  if ~isempty(CPD.Fself_ndx)
+    % Q(t-1), Fself(t-1), Qps, Q(t)
+    
+    % Fself(t-1)  P(Q(t-1)=i, Qps(t)=k -> Q(t)=j)
+    % ------------------------------------------------------
+    % 1         transprob(i,k,j)
+    % 2         startprob(k,j)
+    
+    nps = length(CPD.dom_sz)-1; % num parents
+    CPT = 0*myones(CPD.dom_sz);
+    ndx = mk_multi_index(nps+1, CPD.Fself_ndx, 1);
+    CPT(ndx{:}) = CPD.transprob;
+    if CPD.fullstartprob
+      ndx = mk_multi_index(nps+1, CPD.Fself_ndx, 2);
+      CPT(ndx{:}) = CPD.startprob;
+    else
+      for i=1:CPD.Qsz
+	ndx = mk_multi_index(nps+1, [CPD.Fself_ndx CPD.old_self_ndx], [2 i]);
+	CPT(ndx{:}) = CPD.startprob;
+      end
+    end
+  else % no F from self
+    error('An hhmmQ node without any F parents is just a tabular_CPD')
+  end
+end
+
+CPD = set_fields(CPD, 'CPT', CPT);