From 8070dc963753142bb86c4ed698d91fd623ed28e7 Mon Sep 17 00:00:00 2001 From: ziejd2 Date: Thu, 28 Sep 2017 15:04:40 -0500 Subject: 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 --- .../bnt-master/BNT/CPDs/@hhmmF_CPD/CVS/Entries | 7 ++ .../bnt-master/BNT/CPDs/@hhmmF_CPD/CVS/Repository | 1 + .../bnt-master/BNT/CPDs/@hhmmF_CPD/CVS/Root | 1 + .../bnt-master/BNT/CPDs/@hhmmF_CPD/Old/CVS/Entries | 7 ++ .../BNT/CPDs/@hhmmF_CPD/Old/CVS/Repository | 1 + .../bnt-master/BNT/CPDs/@hhmmF_CPD/Old/CVS/Root | 1 + .../bnt-master/BNT/CPDs/@hhmmF_CPD/Old/hhmmF_CPD.m | 76 ++++++++++++++++++++++ .../bnt-master/BNT/CPDs/@hhmmF_CPD/Old/log_prior.m | 5 ++ .../BNT/CPDs/@hhmmF_CPD/Old/maximize_params.m | 9 +++ .../bnt-master/BNT/CPDs/@hhmmF_CPD/Old/reset_ess.m | 5 ++ .../BNT/CPDs/@hhmmF_CPD/Old/update_CPT.m | 13 ++++ .../BNT/CPDs/@hhmmF_CPD/Old/update_ess.m | 61 +++++++++++++++++ .../bnt-master/BNT/CPDs/@hhmmF_CPD/hhmmF_CPD.m | 73 +++++++++++++++++++++ .../bnt-master/BNT/CPDs/@hhmmF_CPD/log_prior.m | 5 ++ .../BNT/CPDs/@hhmmF_CPD/maximize_params.m | 9 +++ .../bnt-master/BNT/CPDs/@hhmmF_CPD/reset_ess.m | 5 ++ .../bnt-master/BNT/CPDs/@hhmmF_CPD/update_CPT.m | 13 ++++ .../bnt-master/BNT/CPDs/@hhmmF_CPD/update_ess.m | 40 ++++++++++++ 18 files changed, 332 insertions(+) create mode 100644 sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/CVS/Entries create mode 100644 sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/CVS/Repository create mode 100644 sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/CVS/Root create mode 100644 sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/CVS/Entries create mode 100644 sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/CVS/Repository create mode 100644 sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/CVS/Root create mode 100644 sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/hhmmF_CPD.m create mode 100644 sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/log_prior.m create mode 100644 sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/maximize_params.m create mode 100644 sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/reset_ess.m create mode 100644 sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/update_CPT.m create mode 100644 sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/update_ess.m create mode 100644 sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/hhmmF_CPD.m create mode 100644 sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/log_prior.m create mode 100644 sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/maximize_params.m create mode 100644 sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/reset_ess.m create mode 100644 sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/update_CPT.m create mode 100644 sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/update_ess.m (limited to 'sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD') diff --git a/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/CVS/Entries b/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/CVS/Entries new file mode 100644 index 00000000..3e0cc360 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/CVS/Entries @@ -0,0 +1,7 @@ +/hhmmF_CPD.m/1.1.1.1/Mon Jun 24 23:38:24 2002// +/log_prior.m/1.1.1.1/Wed May 29 15:59:54 2002// +/maximize_params.m/1.1.1.1/Wed May 29 15:59:54 2002// +/reset_ess.m/1.1.1.1/Wed May 29 15:59:54 2002// +/update_CPT.m/1.1.1.1/Mon Jun 24 22:45:04 2002// +/update_ess.m/1.1.1.1/Mon Jun 24 23:54:30 2002// +D/Old//// diff --git a/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/CVS/Repository b/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/CVS/Repository new file mode 100644 index 00000000..7c96bc38 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/CVS/Repository @@ -0,0 +1 @@ +FullBNT/BNT/CPDs/@hhmmF_CPD diff --git a/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/CVS/Root b/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/CVS/Root new file mode 100644 index 00000000..f3bd14a6 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/CVS/Root @@ -0,0 +1 @@ +:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt diff --git a/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/CVS/Entries b/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/CVS/Entries new file mode 100644 index 00000000..3ab747df --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/CVS/Entries @@ -0,0 +1,7 @@ +/hhmmF_CPD.m/1.1.1.1/Mon Jun 24 22:35:06 2002// +/log_prior.m/1.1.1.1/Mon Jun 24 22:35:06 2002// +/maximize_params.m/1.1.1.1/Mon Jun 24 22:35:06 2002// +/reset_ess.m/1.1.1.1/Mon Jun 24 22:35:06 2002// +/update_CPT.m/1.1.1.1/Mon Jun 24 22:35:06 2002// +/update_ess.m/1.1.1.1/Mon Jun 24 22:35:06 2002// +D diff --git a/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/CVS/Repository b/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/CVS/Repository new file mode 100644 index 00000000..8981a516 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/CVS/Repository @@ -0,0 +1 @@ +FullBNT/BNT/CPDs/@hhmmF_CPD/Old diff --git a/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/CVS/Root b/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/CVS/Root new file mode 100644 index 00000000..f3bd14a6 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/CVS/Root @@ -0,0 +1 @@ +:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt diff --git a/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/hhmmF_CPD.m b/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/hhmmF_CPD.m new file mode 100644 index 00000000..4fdd9bc9 --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/Old/hhmmF_CPD.m @@ -0,0 +1,76 @@ +function CPD = hhmmF_CPD(bnet, self, Qnodes, d, D, varargin) +% HHMMF_CPD Make the CPD for an F node at depth D of a D-level hierarchical HMM +% CPD = hhmmF_CPD(bnet, self, Qnodes, d, D, ...) +% +% Q(d-1) +% \ +% \ +% F(d) +% / | +% / | +% Q(d) F(d+1) +% +% We assume nodes are ordered (numbered) as follows: +% Q(1), ... Q(d), F(d+1), F(d) +% +% F(d)=2 means level d has finished. The prob this happens depends on Q(d) +% and optionally on Q(d-1), Q(d=1), ..., Q(1). +% Also, level d can only finish if the level below has finished +% (hence the F(d+1) -> F(d) arc). +% +% If d=D, there is no F(d+1), so F(d) is just a regular tabular_CPD. +% If all models always finish in the same state (e.g., their last), +% we don't need to condition on the state of parent models (Q(d-1), ...) +% +% optional args [defaults] +% +% termprob - termprob(k,i,2) = prob finishing given Q(d)=i and Q(1:d-1)=k [ finish in last state ] +% +% hhmmF_CPD is a subclass of tabular_CPD so we inherit inference methods like CPD_to_pot, etc. +% +% We create an isolated tabular_CPD with no F parent to learn termprob +% so we can avail of e.g., entropic or Dirichlet priors. +% +% For details, see "Linear-time inference in hierarchical HMMs", Murphy and Paskin, NIPS'01. + + +ps = parents(bnet.dag, self); +Qps = myintersect(ps, Qnodes); +F = mysetdiff(ps, Qps); +CPD.Q = Qps(end); % Q(d) +assert(CPD.Q == Qnodes(d)); +CPD.Qps = Qps(1:end-1); % all Q parents except Q(d), i.e., calling context + +ns = bnet.node_sizes(:); +CPD.Qsizes = ns(Qnodes); +CPD.d = d; +CPD.D = D; + +Qsz = ns(CPD.Q); +Qpsz = prod(ns(CPD.Qps)); + +% set default arguments +p = 0.9; +%termprob(k,i,t) Might terminate if i=Qsz; will not terminate if i % We sum over the possibilities that F(d+1) = 1 or 2 + +obs_self = ~hidden_bitv(Q); +if obs_self + self_val = evidence{Q}; +end + +if isempty(Qps) % independent of parent context + counts = zeros(Qsz, 2); + %fmarginal.T(Q(d), F(d+1), F(d)) + if obs_self + marg = myreshape(fmarginal.T, [1 2 2]); + counts(self_val,:) = marg(1,2,:); + %counts(self_val,:) = marg(1,1,:) + marg(1,2,:); + else + marg = myreshape(fmarginal.T, [Qsz 2 2]); + counts = squeeze(marg(:,2,:)); + %counts = squeeze(marg(:,2,:)) + squeeze(marg(:,1,:)); + end +else + counts = zeros(Qpsz, Qsz, 2); + %fmarginal.T(Q(1:d-1), Q(d), F(d+1), F(d)) + obs_Qps = ~any(hidden_bitv(Qps)); % we assume that all or none of the Q parents are observed + if obs_Qps + Qps_val = subv2ind(Qpsz, cat(1, evidence{Qps})); + end + if obs_self & obs_Qps + marg = myreshape(fmarginal.T, [1 1 2 2]); + counts(Qps_val, self_val, :) = squeeze(marg(1,1,2,:)); + %counts(Qps_val, self_val, :) = squeeze(marg(1,1,2,:)) + squeeze(marg(1,1,1,:)); + elseif ~obs_self & obs_Qps + marg = myreshape(fmarginal.T, [1 Qsz 2 2]); + counts(Qps_val, :, :) = squeeze(marg(1,:,2,:)); + %counts(Qps_val, :, :) = squeeze(marg(1,:,2,:)) + squeeze(marg(1,:,1,:)); + elseif obs_self & ~obs_Qps + error('not yet implemented') + else + marg = myreshape(fmarginal.T, [Qpsz Qsz 2 2]); + counts(:, :, :) = squeeze(marg(:,:,2,:)); + %counts(:, :, :) = squeeze(marg(:,:,2,:)) + squeeze(marg(:,:,1,:)); + end +end + +CPD.sub_CPD_term = update_ess_simple(CPD.sub_CPD_term, counts); diff --git a/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/hhmmF_CPD.m b/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/hhmmF_CPD.m new file mode 100644 index 00000000..0c15580e --- /dev/null +++ b/sourcecodes/bnt-master/BNT/CPDs/@hhmmF_CPD/hhmmF_CPD.m @@ -0,0 +1,73 @@ +function CPD = hhmmF_CPD(bnet, self, Qself, Fbelow, varargin) +% HHMMF_CPD Make the CPD for an F node in a hierarchical HMM +% CPD = hhmmF_CPD(bnet, self, Qself, Fbelow, ...) +% +% Qps +% \ +% \ +% Fself +% / | +% / | +% Qself Fbelow +% +% We assume nodes are ordered (numbered) as follows: Qps, Q, Fbelow, F +% All nodes numbers should be from slice 1. +% +% If Fbelow if missing, this becomes a regular tabular_CPD. +% Qps may be omitted. +% +% optional args [defaults] +% +% Qps - node numbers. +% termprob - termprob(k,i,2) = prob finishing given Q(d)=i and Q(1:d-1)=k [ finish in last state wp 0.9] +% +% hhmmF_CPD is a subclass of tabular_CPD so we inherit inference methods like CPD_to_pot, etc. +% +% We create an isolated tabular_CPD with no F parent to learn termprob +% so we can avail of e.g., entropic or Dirichlet priors. +% +% For details, see "Linear-time inference in hierarchical HMMs", Murphy and Paskin, NIPS'01. + + + +Qps = []; +% get parents +for i=1:2:length(varargin) + switch varargin{i}, + case 'Qps', Qps = varargin{i+1}; + end +end + +ns = bnet.node_sizes(:); +Qsz = ns(Qself); +Qpsz = prod(ns(Qps)); +CPD.Qsz = Qsz; +CPD.Qpsz = Qpsz; + +ps = parents(bnet.dag, self); +CPD.Fbelow_ndx = find_equiv_posns(Fbelow, ps); +CPD.Qps_ndx = find_equiv_posns(Qps, ps); +CPD.Qself_ndx = find_equiv_posns(Qself, ps); + +% set default arguments +p = 0.9; +%termprob(k,i,t) Might terminate if i=Qsz; will not terminate if i