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