diff options
| author | ziejd2 | 2017-09-28 15:04:40 -0500 |
|---|---|---|
| committer | ziejd2 | 2017-09-28 15:04:40 -0500 |
| commit | 8070dc963753142bb86c4ed698d91fd623ed28e7 (patch) | |
| tree | d0f6dd8fc46a49b819aa55c1a90faa14d8448883 /sourcecodes/bnt-master/BNT/examples/dynamic/HHMM/Map/Old | |
| parent | 7cc31810d53176e805532b2789955f4eedbce6bb (diff) | |
| download | BNW-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/HHMM/Map/Old')
4 files changed, 160 insertions, 0 deletions
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); + + |
