mercaderd / pynoci

Optimal Number of Idependent Components determination tools
1 stars 0 forks source link

ICA from 3 blocks #1

Closed turovapolina closed 3 years ago

turovapolina commented 3 years ago

Dear @mercaderd,

First of all I want to say thank you for your realisation of ICA-by blocks in Python! This was very useful for my work. Secondly I want to ask you for advice regarding function ICA_by_two_blocks. Is it possible to use 3 blocks there for the correlation calculation? In this part I changed nblocks to 3 and inserted calculation of B3 and Y3 but I am stuck with the CMat calculation:

nblocks=2 blocks = np.empty([block_length, T, nblocks]) for i in range(nblocks): blocks[:,:, i]=X[(i block_length):((i+1) block_length),:] correlation_data = [] for i in arange(maxICs): B1 = jadeR(blocks[:, :, 0], m=i + 1 B2 = jadeR(blocks[:, :, 1], m=i + 1) Y1 = B1 matrix(blocks[:, :, 0]) Y2 = B2 matrix(blocks[:, :, 1]) CMat = np.sort(np.nanmax(np.abs(np.corrcoef(Y1, Y2)[:i + 1, i + 1:]), axis=1))

If it is possible could you please give me advice how correctly extrapolate this algorythm inlo 3-blocks sutuation? Thank you very much in advance!

Best regards, Polina

mercaderd commented 3 years ago

Dear @turovapolina,

Thank you so much for the interest shown in my repository. It was part of my master degree 4 years ago. Regarding the ICA by blocks implementation I remember that complexity increases as the number of blocks increases beacause more correlations have to be obtained.

With nblocks=2, it is quite easy as you only have 2 sets of signals Y1, Y2 so only one correlation matrix is needed - Corr(Y1,Y2)

With nblocks=3, you will have 3 sets of signals, Y1, Y2, Y3 (you already obtained them) so you will need to obtain 3 correlation matrixes for Corr(Y1,Y2), Corr(Y2,Y3) and Corr(Y1,Y3) to fully understand all the correlations. For example: CMat1 = np.sort(np.nanmax(np.abs(np.corrcoef(Y1, Y2)[:i + 1, i + 1:]), axis=1)) CMat2 = np.sort(np.nanmax(np.abs(np.corrcoef(Y1, Y3)[:i + 1, i + 1:]), axis=1)) CMat3 = np.sort(np.nanmax(np.abs(np.corrcoef(Y2, Y3)[:i + 1, i + 1:]), axis=1))

Next you could append all the correlations to correlation_data to get one plot with all the correlations (3 traces for each # IC): correlation_data.append(CMat1[::-1]) #Append correlations in descent order correlation_data.append(CMat2[::-1]) #Append correlations in descent order correlation_data.append(CMat3[::-1]) #Append correlations in descent order

Or you could build 3 correlation_data and get also 3 plots: correlation_data1.append(CMat1[::-1]) #Append correlations in descent order correlation_data2.append(CMat2[::-1]) #Append correlations in descent order correlation_data3.append(CMat3[::-1]) #Append correlations in descent order

The method for 3 blocks is well explained here: Bouveresse, D. J.-R., Moya-González, A., Ammari, F., and Rutledge, D. N. (2012). Two novel methods for the determination of the number of components in independent components analysis models. Chemometrics and Intelligent Laboratory Systems,112:24–32.

I hope this helps! Regards. Daniel

turovapolina commented 3 years ago

Dear @mercaderd,

Thank you very much for your detailed answer! Your advices made clear for me how this method works! Sorry for my late reply, it took me some time to implement your advice and understand the difference. Using the article you recommended I interpreted my results and came to the conclusion that 2 blocks also works well for my data and optimal number of components can be defined. From my amateurish point of view question of determination of number of components for some unsupervised methods as ICA is not widely discussed, I found only just a few articles. It was very lucky for me that your master project included realisation of this algorithm in Python because it would be almost impossible for me to do it by myself!

Sorry for my curiosity, but where now does your area of professional interests lie?

Best regards, Polina

mercaderd commented 3 years ago

Dear @turovapolina,

I am glad this tool and my comments were helpful for you. That's great!

Now I work in the area of technology, privacy and personal data.

Regards, Daniel