about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/update_ess.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/@hhmmF_CPD/update_ess.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/@hhmmF_CPD/update_ess.m')
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/update_ess.m40
1 files changed, 40 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/update_ess.m b/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/update_ess.m
new file mode 100644
index 00000000..cc636520
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/update_ess.m
@@ -0,0 +1,40 @@
+function CPD = update_ess(CPD, fmarginal, evidence, ns, cnodes, hidden_bitv)
+% UPDATE_ESS Update the Expected Sufficient Statistics of a hhmmF node.
+% function CPD = update_ess(CPD, fmarginal, evidence, ns, cnodes, hidden_bitv)
+%
+% We assume the F nodes are always hidden
+
+% Figure out the node numbers associated with each parent
+dom = fmarginal.domain;
+%Fself = dom(end); 
+%Fbelow = dom(CPD.Fbelow_ndx);
+Qself = dom(CPD.Qself_ndx);
+Qps = dom(CPD.Qps_ndx);
+
+Qsz = CPD.Qsz;
+Qpsz = CPD.Qpsz;
+
+if all(hidden_bitv(Qps)) % we assume all are hidden or all are observed
+  k_ndx = 1:Qpsz;
+  eff_Qpsz = Qpsz;
+else
+  k_ndx = subv2ind(Qpsz, cat(1, evidence{Qps}));
+  eff_Qpsz = 1;
+end
+
+if hidden_bitv(Qself)
+  j_ndx = 1:Qsz;
+  eff_Qsz = Qsz;
+else
+  j_ndx = evidence{Qself};
+  eff_Qsz = 1;
+end
+
+% Fmarginal(Qps, Q, Fbelow, F)
+fmarg = myreshape(fmarginal.T, [eff_Qpsz eff_Qsz  2 2]);
+
+counts = zeros(Qpsz, Qsz, 2);
+%counts(k_ndx, j_ndx, :) = sum(fmarginal.T(:, :, :, :), 3); % sum over Fbelow
+counts(k_ndx, j_ndx, :) = fmarg(:, :, 2, :); % Fbelow = 2
+
+CPD.sub_CPD_term = update_ess_simple(CPD.sub_CPD_term, counts);