Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/KPMstats/cwr_predict.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 [mu, Sigma, weights, mask] = cwr_predict(cwr, X, mask_data) | |
2 % CWR_PREDICT cluster weighted regression: predict Y given X | |
3 % function [mu, Sigma] = cwr_predict(cwr, X) | |
4 % | |
5 % mu(:,t) = E[Y|X(:,t)] = sum_c P(c | X(:,t)) E[Y|c, X(:,t)] | |
6 % Sigma(:,:,t) = Cov[Y|X(:,t)] | |
7 % | |
8 % [mu, Sigma, weights, mask] = cwr_predict(cwr, X, mask_data) | |
9 % mask(i) = sum_t sum_c p(mask_data(:,i) | X(:,t), c) P(c|X(:,t)) | |
10 % This evaluates the predictive density on a set of points | |
11 % (This is only sensible if T=1, ie. X is a single vector) | |
12 | |
13 [nx T] = size(X); | |
14 [ny nx nc] = size(cwr.weightsY); | |
15 mu = zeros(ny, T); | |
16 Sigma = zeros(ny, ny, T); | |
17 | |
18 if nargout == 4 | |
19 comp_mask = 1; | |
20 N = size(mask_data,2); | |
21 mask = zeros(N,1); | |
22 else | |
23 comp_mask = 0; | |
24 end | |
25 | |
26 if nc==1 | |
27 if isempty(cwr.weightsY) | |
28 mu = repmat(cwr.muY, 1, T); | |
29 Sigma = repmat(cwr.SigmaY, [1 1 T]); | |
30 else | |
31 mu = repmat(cwr.muY, 1, T) + cwr.weightsY * X; | |
32 Sigma = repmat(cwr.SigmaY, [1 1 T]); | |
33 %for t=1:T | |
34 % mu(:,t) = cwr.muY + cwr.weightsY*X(:,t); | |
35 % Sigma(:,:,t) = cwr.SigmaY; | |
36 %end | |
37 end | |
38 if comp_mask, mask = gaussian_prob(mask_data, mu, Sigma); end | |
39 weights = []; | |
40 return; | |
41 end | |
42 | |
43 | |
44 % likX(c,t) = p(x(:,t) | c) | |
45 likX = mixgauss_prob(X, cwr.muX, cwr.SigmaX); | |
46 weights = normalize(repmat(cwr.priorC, 1, T) .* likX, 1); | |
47 for t=1:T | |
48 mut = zeros(ny, nc); | |
49 for c=1:nc | |
50 mut(:,c) = cwr.muY(:,c) + cwr.weightsY(:,:,c)*X(:,t); | |
51 if comp_mask | |
52 mask = mask + gaussian_prob(mask_data, mut(:,c), cwr.SigmaY(:,:,c)) * weights(c); | |
53 end | |
54 end | |
55 %w = normalise(cwr.priorC(:) .* likX(:,t)); | |
56 [mu(:,t), Sigma(:,:,t)] = collapse_mog(mut, cwr.SigmaY, weights(:,t)); | |
57 end |