# ICA - How do I know the optimal number of components?

I'm trying to use the FastICA algorithm in MATLAB. My question is: How do I know, which is the optimal number of ICs? I have a matrix of 62 samples with 1009 signals and the FastICA algorithm returns 31 ICs. Why 31? Is there some output where I can see how much variance has been explained by what number of components? Is it right that the order of ICs doesn't matter at all?

I assume you are using the implementation of FastICA 2.5 available here.

How do I know, which is the optimal number of ICs?

Usually it is not straightforward to know. ICA does not give the dataset's dimensionality explicitly. "Standard" way is to use PCA for that.

I have a matrix of 62 samples with 1009 signals and the FastICA algorithm returns 31 ICs. Why 31?

I do not have your data (or how you call FastICA) so I can't really say for sure but this is almost certain associated with the eigenvalues of the covariance matrix are being smaller than the default tolerance in the implementation of FastICA ($10^{-7}$); reading the function pcamat.m will give you more details on the matter. Usually they drop of dimensions to avoid singularity problems.

Is there some output where I can see how much variance has been explained by what number of components?

I haven't checked that using FastICA but the obvious way would be to do something like this:

    U =eig(cov(D)); k= 31; sum(U(  (end-k+1): end ))/sum(U);


where $U$ is the vector of eigenvalues of your sample's covariance matrix in reverse order, $D$ is your data and $k$ is the number of components you are using. I can do that because ICA will use the same number of components as returned by PCA; therefore ICA will at most be able to encapsulate the variation contained by the first $k$ components of PCA. That is because both ICA and PCA are doing effectively a linear decomposition of your zero-meaned data $D$ such that $D = A C$, $C$ being "some sort" of components (ICs, PCs, what have you) and $A$ being the associated component scores. (This is related to the Karhunen-Loeve expansion in case you are interested.)

Is it right that the order of ICs doesn't matter at all?

Yes; unless you (want to) do something fancy with the optimization step.