Having a problem with doing some clustering across channels via spatio_temporal_cluster_test.

I have set up the adjacency variables much like the tutorial with find_ch_adjacency and combine_adjacency. However, once I attempt to run the above cluster function I get the following error:

ValueError: adjacency (len 131425) must be of the correct size, i.e. be equal to or evenly divide the number of tests (18775).
If adjacency was computed for a source space, try using the fwd["src"] or inv["src"] as some original source space vertices can be excluded during forward computation

This does equally divide though, so I am confused as to how to proceed.

The error message confused me as well, but after peeking at the source code, I think that you are interpreting the message backwards: the adjacency needs to evenly divide the number of tests, rather than be evenly divisible by the number of the tests. In other words, the number of tests (18_775) needs to be evenly divisible by the adjacency (131_425).

So: divmod(18_775, 131_425) (not the other way around), would need to return a remainder of 0 (but doesnāt)

As for a fix, unfortunately I wonāt be of much helpā¦ other than telling you to make sure that your āadjacencyā is not be greater than your number of tests (18_775)

Maybe @CarinaFo , or @larsoner (the last person who touched that line of code) can be of more help?

I have the same problem.
I am using MNE 1.0.3, on Spyder, Python 3.10, on Windows.

My input matrix X has the format [nParticipants * nTimes * nFreqs * nMag], corresponding to [36 * 500 * 29 * 102].

I have also followed the tutorial to compute the adjacency matrix.

adjacency_mag, ch_names_mag = find_ch_adjacency(Epoch.info, ch_type=āmagā). I obtained a sparse._csr.csr_matrix object [102 * 102].
Here is the plot I obtained.

tf_adjacency = combine_adjacency(nTimes, nFreqs, adjacency_mag). I obtained again a sparse._csr.csr_matrix object [1479000 * 1479000] which I think is correct because 500x29x102=1479000.

Then when I try to run the cluster permutations test, I used the following code:

ValueError: adjacency (len 1479000) must be of the correct size, i.e. be equal to or evenly divide the number of tests (2958).

If adjacency was computed for a source space, try using the fwd[āsrcā] or inv[āsrcā] as some original source space vertices can be excluded during forward computation

Line 935: The input matrix X is transformed to form a list of 36 array [500 * 29 * 102].

Line 936: The number of samples is defined as followed:
n_samples = X[0].shape[0]. I obtained n_samples = 500.

Line 937: The number of times is defined as followed:
n_times = X[0].shape[1] I obtained n_times = 29.

Line 945: The X matrix is transformed again to a list of 36 array [500 * 2958] with 29x102 = 2958.

Line 946: The number of tests is defined as:
n_tests = X[0].shape[1]. I obtained n_tests = 2958.

Line 949: A new adjacency is defined as: adjacency = _setup_adjacency(adjacency, n_tests, n_times) (definition line 619).

Line 627: got_times, mod = divmod(n_tests, adjacency.shape[0]). I obtained got_times = 29, and mod = 0.

Line 628-636: if got_times != n_times or mod != 0:
raise ValueError(
"adjacency (len %d) must be of the correct size, i.e. be "
āequal to or evenly divide the number of tests (%d).\n\nā
"If adjacency was computed for a source space, try using "
'the fwd[āsrcā] or inv[āsrcā] as some original source space ā
āvertices can be excluded during forward computationā
% (adjacency.shape[0], n_tests)
)
But my variables got_times = n_times, and mod = 0. So I do not understand why the if statement is validatedā¦

I hope this help and that weāll be abe to find a solution.
Many thanks,
Camille.

Try not creating an adjacency that includes the time dimension ā that should be done automatically in the spatio_temporal_* versions of the function. You should just need to provide the spatio-spectral connectivity like

From the functionās output cluster_stats, we extracted the variable clusters.
From what I understood, this variable should contain freqs, times, sensors information. But it does not contain times info.

freq_inds, time_inds, space_inds = clusters[0]
ValueError: not enough values to unpack (expected 3, got 2)

Yes in principle, but if you collapsed dimensions of your X array originally, they will be collapsed in the output as well, so youāll have to reshape (properly!) to get the original dimensionality back.