-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpst_pfa_sequence_prob.m
More file actions
71 lines (49 loc) · 1.29 KB
/
pst_pfa_sequence_prob.m
File metadata and controls
71 lines (49 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function [SEQP LOGL]=pst_pfa_sequence_prob(PFA,ALPHABET,BOUT,varargin)
%takes a pfa and computes the log likelihood of the sequence
nparams=length(varargin);
if mod(nparams,2)>0
error('Parameters must be specified as parameter/value pairs');
end
for i=1:2:nparams
switch lower(varargin{i})
case 'delimiter'
delimiter=varargin{i+1};
otherwise
end
end
% initialize sbar
% exclude symbols whose P<p_min
% take in the sequence and use the starting state to initialize
% the song, use findparent to locate the parent node and use
% g_sigma_s as the transmission probability
% step through each sequence and calculate the probability of the
% next symbol
SEQP=zeros(length(BOUT),1);
tmp=[];
for i=1:length(BOUT)
seqtmp=BOUT{i};
seq=[];
breakflag=0;
% get the starting state from the first symbol and
% walk the graph to get our likelihoods
for j=1:length(PFA)
if strcmp(PFA(j).label,seqtmp(1))
startnode=j;
break;
end
end
% from the startnode walk along
currnode=PFA(startnode);
% add log(p) along each edge
seqp=[];
for j=2:length(seqtmp)
idx=strfind(currnode.arcs_states,seqtmp(j));
seqp(j-1,1)=currnode.arcs_p(idx);
nextnode=currnode.arcs(idx);
currnode=PFA(nextnode);
end
tmp=[tmp;seqp];
SEQP(i)=sum(log2(seqp));
end
LOGL=sum(log2(tmp+eps))./(length(tmp));
end