Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/netlab3.3/ppca.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 [var, U, lambda] = ppca(x, ppca_dim) | |
2 %PPCA Probabilistic Principal Components Analysis | |
3 % | |
4 % Description | |
5 % [VAR, U, LAMBDA] = PPCA(X, PPCA_DIM) computes the principal | |
6 % component subspace U of dimension PPCA_DIM using a centred covariance | |
7 % matrix X. The variable VAR contains the off-subspace variance (which | |
8 % is assumed to be spherical), while the vector LAMBDA contains the | |
9 % variances of each of the principal components. This is computed | |
10 % using the eigenvalue and eigenvector decomposition of X. | |
11 % | |
12 % See also | |
13 % EIGDEC, PCA | |
14 % | |
15 | |
16 % Copyright (c) Ian T Nabney (1996-2001) | |
17 | |
18 | |
19 if ppca_dim ~= round(ppca_dim) | ppca_dim < 1 | ppca_dim > size(x, 2) | |
20 error('Number of PCs must be integer, >0, < dim'); | |
21 end | |
22 | |
23 [ndata, data_dim] = size(x); | |
24 % Assumes that x is centred and responsibility weighted | |
25 % covariance matrix | |
26 [l Utemp] = eigdec(x, data_dim); | |
27 % Zero any negative eigenvalues (caused by rounding) | |
28 l(l<0) = 0; | |
29 % Now compute the sigma squared values for all possible values | |
30 % of q | |
31 s2_temp = cumsum(l(end:-1:1))./[1:data_dim]'; | |
32 % If necessary, reduce the value of q so that var is at least | |
33 % eps * largest eigenvalue | |
34 q_temp = min([ppca_dim; data_dim-min(find(s2_temp/l(1) > eps))]); | |
35 if q_temp ~= ppca_dim | |
36 wstringpart = 'Covariance matrix ill-conditioned: extracted'; | |
37 wstring = sprintf('%s %d/%d PCs', ... | |
38 wstringpart, q_temp, ppca_dim); | |
39 warning(wstring); | |
40 end | |
41 if q_temp == 0 | |
42 % All the latent dimensions have disappeared, so we are | |
43 % just left with the noise model | |
44 var = l(1)/data_dim; | |
45 lambda = var*ones(1, ppca_dim); | |
46 else | |
47 var = mean(l(q_temp+1:end)); | |
48 end | |
49 U = Utemp(:, 1:q_temp); | |
50 lambda(1:q_temp) = l(1:q_temp); | |
51 | |
52 |