comparison toolboxes/FullBNT-1.0.7/KPMstats/cwr_prob.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 [likXandY, likYgivenX, post] = cwr_prob(cwr, X, Y);
2 % CWR_EVAL_PDF cluster weighted regression: evaluate likelihood of Y given X
3 % function [likXandY, likYgivenX, post] = cwr_prob(cwr, X, Y);
4 %
5 % likXandY(t) = p(x(:,t), y(:,t))
6 % likXgivenY(t) = p(x(:,t)| y(:,t))
7 % post(c,t) = p(c | x(:,t), y(:,t))
8
9 [nx N] = size(X);
10 nc = length(cwr.priorC);
11
12 if nc == 1
13 [mu, Sigma] = cwr_predict(cwr, X);
14 likY = gaussian_prob(Y, mu, Sigma);
15 likXandY = likY;
16 likYgivenX = likY;
17 post = ones(1,N);
18 return;
19 end
20
21
22 % likY(c,t) = p(y(:,t) | c)
23 likY = clg_prob(X, Y, cwr.muY, cwr.SigmaY, cwr.weightsY);
24
25 % likX(c,t) = p(x(:,t) | c)
26 [junk, likX] = mixgauss_prob(X, cwr.muX, cwr.SigmaX);
27 likX = squeeze(likX);
28
29 % prior(c,t) = p(c)
30 prior = repmat(cwr.priorC(:), 1, N);
31
32 post = likX .* likY .* prior;
33 likXandY = sum(post, 1);
34 post = post ./ repmat(likXandY, nc, 1);
35 %loglik = sum(log(lik));
36 %loglik = log(lik);
37
38 likX = sum(likX .* prior, 1);
39 likYgivenX = likXandY ./ likX;