Mensen / ept_TFCE-matlab

Advanced EEG Statistics
27 stars 9 forks source link

Maximum number of channels #13

Open ghost opened 6 years ago

ghost commented 6 years ago

Dear Armand,

thank you for your great work, the speed of the mex implementation is simply astonishing.

I'd like to run TFCE on connectivity measures in source space (624 voxels), with no time dimension and 33 frequency bands, i.e. a 389376 x 33 array, with the neighbourhood created manually. Matlab crashes when I try this however, with the "MATLAB has encountered an internal problem and needs to close" message. The crash report should be attached.

crash_report.txt

This starts to happen at about 300 x 300 x 33 arrays (200 x 200 x 33 still works). I've compiled the mex files with MinGW64 / gcc, and the problem is identical on both a Windows and a Linux machine. I tried the -largeArrayDims option but this produces a few compile warnings and always returns a matrix of zeros. In any case the crash happens even when compiling with this option.

Is there any fix to the C code that I maybe could try? Thanks!

Best, Mircea

Mensen commented 6 years ago

Thanks!

Could you clarify the data structure a little more? Why isn't your data structure 624 x 33? How many measures do you have from independent samples (presumably participants)?

Would you mind sending me your connectivity structure? That way I can generate some random data and see at which point the mex breaks.

I wasn't aware of an upper bound in the data size but since I usually work with hd-eeg I never go beyond 257 channels. That said, when I look at ERPs that could 257 channels by 500 time points, and then we're in the same territory more or less.

ghost commented 6 years ago

Well I have 624 voxels and I'm interested in all possible combinations since not all measures are necessarily symmetric. So we have 624 x 624 = 389376 voxel pairs in x1 x y1 x z1 x x2 x y2 x z2 space. I consider a voxel pair to be a neighbour of another voxel pair if only one of the 6 spatial dimensions changes by one unit. Since there are 33 frequency bands, this results in a 389376 x 33 array with a maximum of 13 neighbours.

I have 28 participants, but at the moment I'm just trying to get ept_mex_TFCE2D to work with random data. I've attached the actual connectivity structure. Just change the extension from txt to mat. The neighbours array is nbMat.

Neighbourhood.txt

ghost commented 6 years ago

So I debugged it with Visual Studio and it turns out the problem is that grow_i only goes up to 32767 because it's a short int. Changing short to long in lines 52 and 60 of ept_mex_TFCE2D.c fixes the problem!

Mensen commented 6 years ago

That's great! Good find... I wasn't aware of the upper bound to ints.

Did you want to submit a pull request with the changes to that function?

ghost commented 6 years ago

Hi, sorry for the late reply. I'm not sure how the pull request works. If you want to implement the change it's very easy though, change short to long in lines 52 and 60 of ept_mex_TFCE2D.c for grow_i and similarly in ept_mex_TFCE3D.