Final commit
[GMM_FEL.git] / code / get_prob.m
blob6b92959f26932b5581022b2adef12c46fe795d40
1 % get_prob - implementation of p(x,s)
3 % usage
4 %        [value index]=get_prob(x,features,sigma)
5 % input
6 %       s - natural number, a height value for which the probability is
7 %       computed
8 %       features - parameters of the underlying distribution - odd items
9 %       are mu_i, even are k_i
10 %       sigma - variance of a single part of the underlying distribution
12 % output
13 %       value - value=max{k_i*N(mu_i,sigma)} over all i's, where
14 %               N denotes normal distribution
15 %               k_i are even items of vector 'features',
16 %               mu_i are odd items of vector 'features' and
17 %               sigma is the variance of a single gaussian
18 %       index - index=argmax{k_i*N(mu_i,sigma)} over all i's, where all the
19 %       symbols have the same meaning as they have for the previous output
20 %       variable
22 function[value index]=get_prob(s,features,sigma)
23 %value=0;
24 %index=0;
25 %features1=features;
26 features=features(features>0);
27 if(isempty(features))
28   index=0;
29   value=1;  
30 else
31     mu=features(1:2:end);
32   k=features(2:2:end);
33   ex=((s-mu).^2)/(2*sigma^2);
34   tmp=log(k)-ex;
35   index=find(tmp==max(tmp),1);
36   %value=k(index)*(1/(sqrt(2*3.14159)*sigma))*exp(tmp(index));
37   value=k(index)*(1/sigma)*exp(tmp(index));
38 end
42 %for i=1:2:length(features)
43 %  if(features(i+1)>0)
44 %    p=features(i+1)*normpdf(s,features(i),sigma);
45     
46 %    if(p>value)
47 %      index=(i+1)/2;
48 %      value=p;
49 %    end
50 %  end
51 %end
52 %if(index==0)
53 %  index=find(abs(features(1:2:end)-s)==min(abs(features(1:2:end)-s)),1,'first');
54 %  value=1;
55 %end