Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/examples/dynamic/HHMM/Map/mk_rnd_map_hhmm.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function bnet = mk_rnd_map_hhmm(varargin) | |
2 | |
3 % We copy the deterministic structure of the real HHMM, | |
4 % but randomize the probabilities of the adjustable CPDs. | |
5 % The key trick is that 0s in the real HHMM remain 0 | |
6 % even when multiplied by a randon number. | |
7 | |
8 obs_model = 'unique'; | |
9 | |
10 for i=1:2:length(varargin) | |
11 switch varargin{i}, | |
12 case 'obs_model', obs_model = varargin{i+1}; | |
13 end | |
14 end | |
15 | |
16 | |
17 unique_obs = strcmp(obs_model, 'unique'); | |
18 | |
19 psuccess = 0.9; | |
20 % must be less than 1, so that pfail > 0 | |
21 % otherwise we copy too many 0s | |
22 bnet = mk_map_hhmm('p', psuccess, 'obs_model', obs_model); | |
23 ns = bnet.node_sizes; | |
24 ss = bnet.nnodes_per_slice; | |
25 | |
26 U = 1; A = 2; C = 3; F = 4; | |
27 %unique_obs = (bnet.nnodes_per_slice == 5); | |
28 if unique_obs | |
29 onodes = 5; | |
30 else | |
31 north = 5; east = 6; south = 7; west = 8; | |
32 onodes = [north east south west]; | |
33 end | |
34 | |
35 eclass = bnet.equiv_class; | |
36 S=struct(bnet.CPD{eclass(F,1)}); | |
37 CPT = mk_stochastic(rand(size(S.CPT)) .* S.CPT); | |
38 bnet.CPD{eclass(F,1)} = tabular_CPD(bnet, F, 'CPT', CPT); | |
39 | |
40 | |
41 % Observation model | |
42 if unique_obs | |
43 CPT = zeros(ns(A), ns(C), 5); | |
44 CPT(1,1,1)=1; % Theo state 4 | |
45 CPT(1,2,2)=1; % Theo state 5 | |
46 CPT(1,3,3)=1; % Theo state 6 | |
47 CPT(2,1,4)=1; % Theo state 9 | |
48 CPT(2,2,5)=1; % Theo state 10 | |
49 %CPT(2,3,:) undefined | |
50 O = onodes(1); | |
51 bnet.CPD{eclass(O,1)} = tabular_CPD(bnet, O, 'CPT', CPT); | |
52 else | |
53 for i=[north east south west] | |
54 CPT = mk_stochastic(rand(ns(A), ns(C), 2)); | |
55 bnet.CPD{eclass(i,1)} = tabular_CPD(bnet, i, 'CPT', CPT); | |
56 end | |
57 end | |
58 | |
59 % Define the CPDs for slice 2 | |
60 | |
61 startprob = zeros(ns(U), ns(A)); | |
62 S = struct(bnet.CPD{eclass(A,2)}); | |
63 transprob = mk_stochastic(rand(size(S.transprob)) .* S.transprob); | |
64 bnet.CPD{eclass(A,2)} = hhmm2Q_CPD(bnet, A+ss, 'Fbelow', F, ... | |
65 'startprob', startprob, 'transprob', transprob); | |
66 | |
67 S = struct(bnet.CPD{eclass(C,2)}); | |
68 transprob = mk_stochastic(rand(size(S.transprob)) .* S.transprob); | |
69 startprob = mk_stochastic(rand(size(S.startprob)) .* S.startprob); | |
70 bnet.CPD{eclass(C,2)} = hhmm2Q_CPD(bnet, C+ss, 'Fself', F, ... | |
71 'startprob', startprob, 'transprob', transprob); | |
72 | |
73 |