This is a static copy of a profile report

Home

eff_PCA (1 call, 0.160 sec)
Generated 05-Nov-2014 07:52:41 using cpu time.
function in file /usr0/home/jenkins/workspace/cellorganizer-demo3D11-glnx64/utilities/3D/vesicles/eff_PCA.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
train_cell_shape_model3function1
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
71
score = coeff' * D;
10.060 s37.5%
66
coeff = D * eigenVect;
10.030 s18.8%
55
D = (A - repmat(mu, N,1))';
10.030 s18.8%
57
T = D'*D/N;
10.020 s12.5%
68
coeff(:,i) = coeff(:,i) / sqrt...
2010.010 s6.2%
All other lines  0.010 s6.3%
Totals  0.160 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
repmatfunction10.020 s12.5%
flipudfunction10 s0%
fliplrfunction10 s0%
meanfunction10 s0%
Self time (built-ins, overhead, etc.)  0.140 s87.5%
Totals  0.160 s100% 
Code Analyzer results
Line numberMessage
53The value assigned to variable 'n' might be unused.
Coverage results
[ Show coverage for parent directory ]
Total lines in function71
Non-code lines (comments, blank lines)59
Code lines (lines that can run)12
Code lines that did run12
Code lines that did not run0
Coverage (did run/can run)100.00 %
Function listing
   time   calls  line
1 function [mu, coeff, score, latent] = eff_PCA(A)
2 % Let A be a N*n matrix, N rows represent the observation
3 % n columns represent the variance.
4 % Here we calculate the covariance matrix of input A, in order
5 % calculate the eigen values and eigen vectors of the A*A'
6 % MU - Recentering of the orginal data.
7 % COEFF - n*N matrix, correspond to the N normalized eigen vectors of the
8 % covariance matrix, i.e., principle components.
9 % SCORE - N*N matrix, the projected length on each principle mode. There
10 % are N principle modes as maximum.
11 % LATENT - N diangonal vector correspond to the eigen values of each
12 % principle mode
13 %
14 % The ultimate goal of doing so, is to use the optimized method
15 % to compute PCA from A*A' (a N by N matrix) rather than
16 % frome A'*A (a n by n matrix). Because the dimension n of the
17 % variance is often much bigger than the observation N.
18 %
19 % We can do so by:
20 % 1. Compute the eigVect and eigVal of the T = (D * D' )
21 % Then we have T * eigVect = eigVal * eigVect;
22 % 2. We can compute the eigVect and eigVal of S = D' * D
23 % by D' * eigVect
24
25
26 % Author: Wei Wang
27 % September ??, 2010 T. Peng
28 %
29 % Copyright (C) 2012 Murphy Lab
30 % Lane Center for Computational Biology
31 % School of Computer Science
32 % Carnegie Mellon University
33 %
34 % This program is free software; you can redistribute it and/or modify
35 % it under the terms of the GNU General Public License as published
36 % by the Free Software Foundation; either version 2 of the License,
37 % or (at your option) any later version.
38 %
39 % This program is distributed in the hope that it will be useful, but
40 % WITHOUT ANY WARRANTY; without even the implied warranty of
41 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
42 % General Public License for more details.
43 %
44 % You should have received a copy of the GNU General Public License
45 % along with this program; if not, write to the Free Software
46 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
47 % 02110-1301, USA.
48 %
49 % For additional information visit http://murphylab.web.cmu.edu or
50 % send email to murphy@cmu.edu
51
52 % Step1 compute the eigVect and eigVal of the T = (D * D' )
1 53 [N, n] = size(A);
1 54 mu = mean(A);
0.03 1 55 D = (A - repmat(mu, N,1))';
56
0.02 1 57 T = D'*D/N;
0.01 1 58 [V, eigD] = eig(T);
59
1 60 eigenVect = fliplr(V);
1 61 latent = flipud(diag(eigD));
62
63 % Step 2 compute A' * eigenVect, in order to calculate the eigenVect
64 % of the original covariance matrix
65
0.03 1 66 coeff = D * eigenVect;
1 67 for i = 1:N
0.01 201 68 coeff(:,i) = coeff(:,i) / sqrt(latent(i) * N);
201 69 end
70
0.06 1 71 score = coeff' * D;