annotate toolboxes/FullBNT-1.0.7/KPMstats/cwr_predict.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function [mu, Sigma, weights, mask] = cwr_predict(cwr, X, mask_data)
Daniel@0 2 % CWR_PREDICT cluster weighted regression: predict Y given X
Daniel@0 3 % function [mu, Sigma] = cwr_predict(cwr, X)
Daniel@0 4 %
Daniel@0 5 % mu(:,t) = E[Y|X(:,t)] = sum_c P(c | X(:,t)) E[Y|c, X(:,t)]
Daniel@0 6 % Sigma(:,:,t) = Cov[Y|X(:,t)]
Daniel@0 7 %
Daniel@0 8 % [mu, Sigma, weights, mask] = cwr_predict(cwr, X, mask_data)
Daniel@0 9 % mask(i) = sum_t sum_c p(mask_data(:,i) | X(:,t), c) P(c|X(:,t))
Daniel@0 10 % This evaluates the predictive density on a set of points
Daniel@0 11 % (This is only sensible if T=1, ie. X is a single vector)
Daniel@0 12
Daniel@0 13 [nx T] = size(X);
Daniel@0 14 [ny nx nc] = size(cwr.weightsY);
Daniel@0 15 mu = zeros(ny, T);
Daniel@0 16 Sigma = zeros(ny, ny, T);
Daniel@0 17
Daniel@0 18 if nargout == 4
Daniel@0 19 comp_mask = 1;
Daniel@0 20 N = size(mask_data,2);
Daniel@0 21 mask = zeros(N,1);
Daniel@0 22 else
Daniel@0 23 comp_mask = 0;
Daniel@0 24 end
Daniel@0 25
Daniel@0 26 if nc==1
Daniel@0 27 if isempty(cwr.weightsY)
Daniel@0 28 mu = repmat(cwr.muY, 1, T);
Daniel@0 29 Sigma = repmat(cwr.SigmaY, [1 1 T]);
Daniel@0 30 else
Daniel@0 31 mu = repmat(cwr.muY, 1, T) + cwr.weightsY * X;
Daniel@0 32 Sigma = repmat(cwr.SigmaY, [1 1 T]);
Daniel@0 33 %for t=1:T
Daniel@0 34 % mu(:,t) = cwr.muY + cwr.weightsY*X(:,t);
Daniel@0 35 % Sigma(:,:,t) = cwr.SigmaY;
Daniel@0 36 %end
Daniel@0 37 end
Daniel@0 38 if comp_mask, mask = gaussian_prob(mask_data, mu, Sigma); end
Daniel@0 39 weights = [];
Daniel@0 40 return;
Daniel@0 41 end
Daniel@0 42
Daniel@0 43
Daniel@0 44 % likX(c,t) = p(x(:,t) | c)
Daniel@0 45 likX = mixgauss_prob(X, cwr.muX, cwr.SigmaX);
Daniel@0 46 weights = normalize(repmat(cwr.priorC, 1, T) .* likX, 1);
Daniel@0 47 for t=1:T
Daniel@0 48 mut = zeros(ny, nc);
Daniel@0 49 for c=1:nc
Daniel@0 50 mut(:,c) = cwr.muY(:,c) + cwr.weightsY(:,:,c)*X(:,t);
Daniel@0 51 if comp_mask
Daniel@0 52 mask = mask + gaussian_prob(mask_data, mut(:,c), cwr.SigmaY(:,:,c)) * weights(c);
Daniel@0 53 end
Daniel@0 54 end
Daniel@0 55 %w = normalise(cwr.priorC(:) .* likX(:,t));
Daniel@0 56 [mu(:,t), Sigma(:,:,t)] = collapse_mog(mut, cwr.SigmaY, weights(:,t));
Daniel@0 57 end