21

I've been reading a paper on Sparse PCA, which is: http://stats.stanford.edu/~imj/WEBLIST/AsYetUnpub/sparse.pdf

And it states that, if you have n data points, each represented with p features, then, the complexity of PCA is O(min(p^3,n^3)).

Can someone please explain how/why?

Daniel Cheung
  • 4,779
  • 1
  • 30
  • 63
GrowinMan
  • 4,891
  • 12
  • 41
  • 58

3 Answers3

43

Covariance matrix computation is O(p2n); its eigen-value decomposition is O(p3). So, the complexity of PCA is O(p2n+p3).

O(min(p3,n3)) would imply that you could analyze a two-dimensional dataset of any size in fixed time, which is patently false.

Don Reba
  • 13,814
  • 3
  • 48
  • 61
  • 1
    It's odd how the paper phrases this vaguely as "involves a search for directions." It does not outright say that this is the algorithm's complexity, just strongly implies it. – Don Reba Dec 11 '13 at 00:14
  • Great! Could you please give a reference for the above so that it would be easier to cite? – Ébe Isaac Jan 15 '18 at 06:30
  • @ÉbeIsaac Covariance matrix complexity follows immediately from definition. There are lower-complexity algorithms for eigenvalue decomposition, but they are close to O(p³), and this is probably the complexity the paper's author assumes. You shouldn't cite SO answers as authoritative sources, though, unless they are from Jon Skeet. – Don Reba Feb 04 '18 at 06:42
2

Assuming your dataset is $X \in \R^{nxp}$ where n: number of samples, d: dimensions of a sample, you are interested in the eigenanalysis of $X^TX$ which is the main computational cost of PCA. Now matrices $X^TX \in \R^{pxp}$ and $XX^T \in \R^{nxn}$ have the same min(n, p) non negative eigenvalues and eigenvectors. Assuming p less than n you can solve the eigenanalysis in $O(p^3)$. If p greater than n (for example in computer vision in many cases the dimensionality of sample -number of pixels- is greater than the number of samples available) you can perform eigenanalysis in $O(n^3)$ time. In any case you can get the eigenvectors of one matrix from the eigenvalues and eigenvectors of the other matrix and do that in $O(min(p, n)^3)$ time.

$$X^TX = V \Lambda V^T$$

$$XX^T = U \Lambda U^T$$

$$U = XV\Lambda^{-1/2}$$

michaelt
  • 31
  • 6
  • Unfortunately there is no latex support, I suggest you use backquotes to format that as code, or export your latex fomulas to png and upload that. – Ash Mar 10 '18 at 14:51
2

Below is michaelt's answer provided in both the original LaTeX and rendered as a PNG.

Image of LaTeX answer

LaTeX code:

Assuming your dataset is $X \in R^{n\times p}$ where n: number of samples, p: dimensions of a sample, you are interested in the eigenanalysis of $X^TX$ which is the main computational cost of PCA. Now matrices $X^TX \in \R^{p \times p}$ and $XX^T \in \R^{n\times n}$ have the same min(n, p) non negative eigenvalues and eigenvectors. Assuming p less than n you can solve the eigenanalysis in $O(p^3)$. If p greater than n (for example in computer vision in many cases the dimensionality of sample -number of pixels- is greater than the number of samples available) you can perform eigenanalysis in $O(n^3)$ time. In any case you can get the eigenvectors of one matrix from the eigenvalues and eigenvectors of the other matrix and do that in $O(min(p, n)^3)$ time.

mic
  • 1,190
  • 1
  • 17
  • 29
Ebram
  • 161
  • 1
  • 6