Tedana - SVD Convergence Error

Summary of what happened:

Hi all, I am using Tedana to process multi-echo functional images and I’m running into an issue that I haven’t encountered before concerning SVD convergence in a Python subscript.
I am using fmriprep to preprocess and motion correct the images, and passing the ACPC-aligned, echo-separated images to Tedana.
The error I am getting is “numpy.linalg.LinAlgError: SVD did not converge” about 1.5 hours into the processing. I have seen from other posts that this failure often occurs when there is a memory/resource issue, but I am running this via an LPC computing cluster and have not experienced this before.

Command used (and if a helper script was used, a link to the helper script or the command generated):

This is the Tedana call:

MEPCA=kundu
MaxIterations=500
MaxRestarts=10

tedana -d "$Subdir"/func/rest/"$DataDirs"/Rest_E*_acpc.nii.gz -e $(cat "$Subdir"/func/rest/"$DataDirs"/TE.txt) --out-dir "$Subdir"/func/rest/"$DataDirs"/Tedana/ \
--tedpca "$MEPCA" --fittype curvefit --mask "$Subdir"/func/rest/"$DataDirs"/brain_mask.nii.gz --maxit "$MaxIterations" --maxrestart "$MaxRestarts" --seed 42 --verbose # specify more iterations / restarts to increase likelihood of ICA convergence (also increases possible runtime).

and this is the submission command for our bsub cluster:

bsub -q bsc_long -e /project/oathes_analysis2/R61/logs/HCP/sub-$(echo $i)_func3.e -o /project/oathes_analysis2/R61/logs/HCP/sub-$(echo $i)_func3.o -n 16 -M 50000 -R "rusage [mem=50000] span[hosts=1]" -N sh adjusted_func_denoise_meica.sh /project/oathes_analysis2/R61/ $i

Version:

tedana v23.0.2

Environment (Docker, Singularity / Apptainer, custom installation):

Running via a conda environment:

module load miniconda/3-22.11
eval "$(/appl/miniconda3-22.11/bin/conda shell.bash hook)"
conda activate /project/oathes_analysis2/R61/tedanacondaenv
export PYTHONPATH=/project/oathes_analysis2/R61/tedanacondaenv/lib/python3.9/site-packages:$PYTHONPATH
export PATH=/project/oathes_analysis2/R61/tedanacondaenv/bin:$PATH
export PATH=/project/oathes_analysis2/R61/tedanacondaenv/lib:$PATH

Relevant log outputs (up to 20 lines):

   202	Traceback (most recent call last):
   203	  File "/project/oathes_analysis2/R61/tedanacondaenv/bin/tedana", line 8, in <module>
   204	    sys.exit(_main())
   205	  File "/project/oathes_analysis2/R61/tedanacondaenv/lib/python3.9/site-packages/tedana/workflows/tedana.py", line 918, in _main
   206	    tedana_workflow(**kwargs, tedana_command=tedana_command)
   207	  File "/project/oathes_analysis2/R61/tedanacondaenv/lib/python3.9/site-packages/tedana/workflows/tedana.py", line 662, in tedana_workflow
   208	    mmix, seed = decomposition.tedica(
   209	  File "/project/oathes_analysis2/R61/tedanacondaenv/lib/python3.9/site-packages/tedana/decomposition/ica.py", line 67, in tedica
   210	    ica.fit(data)
   211	  File "/project/oathes_analysis2/R61/tedanacondaenv/lib/python3.9/site-packages/sklearn/base.py", line 1474, in wrapper
   212	    return fit_method(estimator, *args, **kwargs)
   213	  File "/project/oathes_analysis2/R61/tedanacondaenv/lib/python3.9/site-packages/sklearn/decomposition/_fastica.py", line 733, in fit
   214	    self._fit_transform(X, compute_sources=False)
   215	  File "/project/oathes_analysis2/R61/tedanacondaenv/lib/python3.9/site-packages/sklearn/decomposition/_fastica.py", line 621, in _fit_transform
   216	    u, d = linalg.svd(XT, full_matrices=False, check_finite=False)[:2]
   217	  File "/appl/miniconda3-22.11/lib/python3.9/site-packages/scipy/linalg/_decomp_svd.py", line 145, in svd
   218	    raise LinAlgError("SVD did not converge")
   219	numpy.linalg.LinAlgError: SVD did not converge

I am happy to provide more context or figures/logs as needed.
If anyone has any suggestions or recommendations to get this to work, please let me know.


Hi Jess,

Could you also share your tedana log (tedana_[date-time].tsv)? I haven’t seen this exact error before, but my guess is that the step that estimates the number of PCA components failed, you have too many or too few PCA components and that is making it harder for ICA to converge. The right number of components varies by study, but if it’s nearly the same number as time points or less than 1/5 the number of time points, that’s a sign of a problem. More detail here: FAQ — tedana 24.0.2 documentation

I can give more suggestions, if this is the issue.

Also, tedana v23.0.2 was released in November 2023. I’d recommend updating to the current version (24.0.2). I don’t think any updates will address this specific issue, but there are bug fixes and improvements. The newest version does include an option to run robustICA, which can help if the number of estimated components is the source of the problem.

Hope this helps

Dan

Hey Dan, thank you for the insights. I’ve attached the tsv log below. Seems like it is attempting to pull 715 components out of 886 time points.
Would it be advisable to adjust my decision tree and/or the max iterations in the Tedana call itself? Or any other recommendation you may have.
I can also try and update the version to include robustICA, but would need to assess the impact of that on our study’s processing pipeline before making any changes.
Thanks!
Jess

2025-03-10T12:48:29	tedana.tedana_workflow	INFO    	Using output directory: /project/oathes_analysis2/R61/P689/func/rest/session_1/run_1/Tedana
2025-03-10T12:48:29	tedana.tedana_workflow	INFO    	Loading input data: ['/project/oathes_analysis2/R61//P689/func/rest/session_1/run_1/Rest_E1_acpc.nii.gz', '/project/oathes_analysis2/R61//P689/func/rest/session_1/run_1/Rest_E2_acpc.nii.gz', '/project/oathes_analysis2/R61//P689/func/rest/session_1/run_1/Rest_E3_acpc.nii.gz', '/project/oathes_analysis2/R61//P689/func/rest/session_1/run_1/Rest_E4_acpc.nii.gz', '/project/oathes_analysis2/R61//P689/func/rest/session_1/run_1/Rest_E5_acpc.nii.gz']
2025-03-10T12:53:04	io.__init__    	INFO    	Generating figures directory: /project/oathes_analysis2/R61/P689/func/rest/session_1/run_1/Tedana/figures
2025-03-10T12:53:05	tedana.tedana_workflow	INFO    	Using user-defined mask
2025-03-10T12:53:13	tedana.tedana_workflow	INFO    	Computing T2* map
2025-03-10T13:06:20	combine.make_optcom 	INFO    	Optimally combining data with voxel-wise T2* estimates
2025-03-10T13:07:49	tedana.tedana_workflow	INFO    	Writing optimally combined data set: /project/oathes_analysis2/R61/P689/func/rest/session_1/run_1/Tedana/desc-optcom_bold.nii.gz
2025-03-10T13:07:49	pca.tedpca      	INFO    	Computing PCA of optimally combined multi-echo data with selection criteria: kundu
2025-03-10T13:09:03	collect.generate_metrics	INFO    	Calculating weight maps
2025-03-10T13:11:18	collect.generate_metrics	INFO    	Calculating parameter estimate maps for optimally combined data
2025-03-10T13:23:24	collect.generate_metrics	INFO    	Calculating z-statistic maps
2025-03-10T13:24:36	collect.generate_metrics	INFO    	Calculating F-statistic maps
2025-03-10T13:37:08	collect.generate_metrics	INFO    	Thresholding z-statistic maps
2025-03-10T13:38:34	collect.generate_metrics	INFO    	Calculating T2* F-statistic maps
2025-03-10T13:39:42	collect.generate_metrics	INFO    	Calculating S0 F-statistic maps
2025-03-10T13:40:54	collect.generate_metrics	INFO    	Counting significant voxels in T2* F-statistic maps
2025-03-10T13:40:54	collect.generate_metrics	INFO    	Counting significant voxels in S0 F-statistic maps
2025-03-10T13:40:54	collect.generate_metrics	INFO    	Thresholding optimal combination beta maps to match T2* F-statistic maps
2025-03-10T13:45:16	collect.generate_metrics	INFO    	Thresholding optimal combination beta maps to match S0 F-statistic maps
2025-03-10T13:51:33	collect.generate_metrics	INFO    	Calculating kappa and rho
2025-03-10T13:51:43	collect.generate_metrics	INFO    	Calculating variance explained
2025-03-10T13:51:44	collect.generate_metrics	INFO    	Calculating normalized variance explained
2025-03-10T13:51:46	collect.generate_metrics	INFO    	Calculating DSI between thresholded T2* F-statistic and optimal combination beta maps
2025-03-10T13:51:49	utils.dice        	WARNING 	193 of 885 components have empty maps, resulting in Dice values of 0. Please check your component table for dice columns with 0-values.
2025-03-10T13:51:49	collect.generate_metrics	INFO    	Calculating DSI between thresholded S0 F-statistic and optimal combination beta maps
2025-03-10T13:51:53	collect.generate_metrics	INFO    	Calculating signal-noise t-statistics
2025-03-10T13:51:57	collect.generate_metrics	INFO    	Counting significant noise voxels from z-statistic maps
2025-03-10T13:52:00	collect.generate_metrics	INFO    	Calculating decision table score
2025-03-10T14:12:42	tedpca.kundu_tedpca	INFO    	Performing PCA component selection with Kundu decision tree
2025-03-10T14:12:42	tedpca.kundu_tedpca	INFO    	Selected 715 components with Kappa threshold: 6.32, Rho threshold: 8.29

The core issue is definitely you have too many PCA components and ICA is not able to converge. If you’re getting >500 components for 885 volumes, just kill the job.

I’d first suggest trying another option instead of --tedpca kundu. --tedpca kic or --tedpca aic are other options. If a bunch of runs with the same acqusition are converging without a problem, you can also look at the number of ICA components and set a fixed value, like 200, with --tedpca 200 If you combine this with robustICA, then it will interatively run ICA and find a fewer number of stable components.

I covered more details about these options & how to evaluate them in this thread: ICA failed to converge - #11 by handwerkerd - AFNI Message Board - AFNI Discuss Message Board

Best

Dan