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