[Eeglablist] Reproducible ICA
Frühlinger, Christoph
christoph.fruehlinger at uni-hamburg.de
Thu Jul 3 03:17:47 PDT 2025
Dear Ivano,
thank you very much for your effort in this! I adapted my previous code to:
EEG = pop_runica(EEG,'icatype','runica','pca',EEG.cc.d0601__pcaICA.rankUsed,'extended',1,'interupt','off','rndreset','no');
In a control analysis, I ran the code above twice, saved the output in different EEG structures and compared the IC data. They are indeed identical even within the parfor loop.
Thank you all for helping out!
Best
Christoph
Von: ivano triggiani <ivanotriggiani at gmail.com>
Gesendet: Mittwoch, 2. Juli 2025 18:48
An: smakeig at gmail.com
Cc: Frühlinger, Christoph <christoph.fruehlinger at uni-hamburg.de>; eeglablist at sccn.ucsd.edu
Betreff: Re: [Eeglablist] Reproducible ICA
I have read more about the issue, and, apparently, when you use parfor, every thread works independently with a different random seed.
I searched on the internet and I found that a solution could be something like this:
s = RandStream.create('mrg32k3a', 'NumStreams', length(Files), 'Seed', 42); %this should create a series of random seeds that you can control in the loop.
parfor i = 1:length(Files)
RandStream.setGlobalStream(s(i));
run_preproc(Files{i});
end
I hope this helps.
Ivano
---
Antonio Ivano Triggiani, Ph.D.
________________________________________________
On Wed, Jul 2, 2025 at 12:16 PM Scott Makeig via eeglablist <eeglablist at sccn.ucsd.edu<mailto:eeglablist at sccn.ucsd.edu>> wrote:
Christoph -
There is an input parameter to runica() to set the random seed. If this
is not exposed in pop_runica(), you should be able to easily write a script
to run runica() directly on your data. Else, there may be an option in
pop_runica() to add optional runica() arguments...
However, the differences in runica() output using different random seeds
typically affect noticeably only the smallest (highest-index) ICs; they
arise from variations in order of processing in successive runica learning
steps. As there is no canonical ('correct') order for (extended) infomax
ICA to process the data, these variations define a (small) inherent
ICA-noise data subspace....
Scott Makeig
On Mon, Jun 30, 2025 at 9:51 PM Frühlinger, Christoph via eeglablist <
eeglablist at sccn.ucsd.edu<mailto:eeglablist at sccn.ucsd.edu>> wrote:
> Dear all,
>
> I want to insert a random seed in my preprocessing script before the ICA
> to get reproducible results. I have tried several settings of the random
> seed at different locations in the script (at the top, right before the
> ICA, at the top of the pop_runica() function) as suggested in previous
> threads of the mailing list. However, I keep getting different ICA results
> for the same dataset. Some (potentially) relevant notes regarding the
> script: I use a parfor loop to call the actual preprocessing function like:
>
> ```
> parfor i_Sub = 1:length(Files)
> run_preproc()
> end
>
> function run_preproc()
> # basic preprocessing
>
> EEG = pop_runica(EEG, 'icatype', 'runica', 'pca', rank,
> 'extended', 1, 'interupt', 'off');
>
> # some more preprocessing
> end
> ```
>
> I would appreciate it if you could help me!
>
> Best wishes
> Christoph
> _______________________________________________
> To unsubscribe, send an empty email to
> eeglablist-unsubscribe at sccn.ucsd.edu<mailto:eeglablist-unsubscribe at sccn.ucsd.edu> or visit
> https://sccn.ucsd.edu/mailman/listinfo/eeglablist .
>
--
Scott Makeig, Research Scientist and Director, Swartz Center for
Computational Neuroscience, Institute for Neural Computation, University of
California San Diego, La Jolla CA 92093-0559, http://sccn.ucsd.edu/~scott
_______________________________________________
To unsubscribe, send an empty email to eeglablist-unsubscribe at sccn.ucsd.edu<mailto:eeglablist-unsubscribe at sccn.ucsd.edu> or visit https://sccn.ucsd.edu/mailman/listinfo/eeglablist .
More information about the eeglablist
mailing list