Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/examples/dynamic/HHMM/Old/motif_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 % Make the following HHMM | |
2 % | |
3 % S1 <----------------------> S2 | |
4 % | | | |
5 % | | | |
6 % M1 -> M2 -> M3 -> end B1 -> end | |
7 % | |
8 % where Mi represents the i'th letter in the motif | |
9 % and B is the background state. | |
10 % Si chooses between running the motif or the background. | |
11 % The Si and B states have self loops (not shown). | |
12 | |
13 if 0 | |
14 seed = 0; | |
15 rand('state', seed); | |
16 randn('state', seed); | |
17 end | |
18 | |
19 chars = ['a', 'c', 'g', 't']; | |
20 Osize = length(chars); | |
21 | |
22 motif_pattern = 'acca'; | |
23 motif_length = length(motif_pattern); | |
24 Qsize = [2 motif_length]; | |
25 Qnodes = 1:2; | |
26 D = 2; | |
27 transprob = cell(1,D); | |
28 termprob = cell(1,D); | |
29 startprob = cell(1,D); | |
30 | |
31 % startprob{d}(k,j), startprob{1}(1,j) | |
32 % transprob{d}(i,k,j), transprob{1}(i,j) | |
33 % termprob{d}(k,j) | |
34 | |
35 | |
36 % LEVEL 1 | |
37 | |
38 startprob{1} = zeros(1, 2); | |
39 startprob{1} = [1 0]; % always start in the background model | |
40 | |
41 % When in the background state, we stay there with high prob | |
42 % When in the motif state, we immediately return to the background state. | |
43 transprob{1} = [0.8 0.2; | |
44 1.0 0.0]; | |
45 | |
46 | |
47 % LEVEL 2 | |
48 startprob{2} = 'leftstart'; % both submodels start in substate 1 | |
49 transprob{2} = zeros(motif_length, 2, motif_length); | |
50 termprob{2} = zeros(2, motif_length); | |
51 | |
52 % In the background model, we only use state 1. | |
53 transprob{2}(1,1,1) = 1; % self loop | |
54 termprob{2}(1,1) = 0.2; % prob transition to end state | |
55 | |
56 % Motif model | |
57 transprob{2}(:,2,:) = mk_leftright_transmat(motif_length, 0); | |
58 termprob{2}(2,end) = 1.0; % last state immediately terminates | |
59 | |
60 | |
61 % OBS LEVEl | |
62 | |
63 obsprob = zeros([Qsize Osize]); | |
64 if 0 | |
65 % uniform background model | |
66 obsprob(1,1,:) = normalise(ones(Osize,1)); | |
67 else | |
68 % deterministic background model (easy to see!) | |
69 m = find(chars=='t'); | |
70 obsprob(1,1,m) = 1.0; | |
71 end | |
72 if 1 | |
73 % initialise with true motif (cheating) | |
74 for i=1:motif_length | |
75 m = find(chars == motif_pattern(i)); | |
76 obsprob(2,i,m) = 1.0; | |
77 end | |
78 end | |
79 | |
80 Oargs = {'CPT', obsprob}; | |
81 | |
82 [bnet, Qnodes, Fnodes, Onode] = mk_hhmm('Qsizes', Qsize, 'Osize', Osize, 'discrete_obs', 1, ... | |
83 'Oargs', Oargs, 'Ops', Qnodes(1:2), ... | |
84 'startprob', startprob, 'transprob', transprob, 'termprob', termprob); | |
85 | |
86 | |
87 Tmax = 20; | |
88 usecell = 0; | |
89 | |
90 for seqi=1:5 | |
91 evidence = sample_dbn(bnet, Tmax, usecell); | |
92 chars(evidence(end,:)) | |
93 %T = size(evidence, 2) | |
94 %pretty_print_hhmm_parse(evidence, Qnodes, Fnodes, Onode, chars); | |
95 end |