Random number generator

Hi all,

Is there a way to control MRTrix’s RNG to produce replicable probabilistic tractography?

Claude

Yes, but it comes at a price. You can set the seed used for the RNG via the MRTRIX_RNG_SEED environment variable. But that’s not enough to ensure the same results in a multi-threaded application like tckgen, since the random numbers will be consumed by different threads in whatever order they run. To really ensure perfectly reproducible results, you also need to run single-threaded – as stated in the documentation for that variable…

1 Like

Hey,

Just to follow up this question, I have done some tests on tckgen try to get fully reproducible streamlines but not succeeded.
What I did was to have the random seed fixed, and use single thread, both probabilistic and deterministic algo were tested:

See below codes and outputs:

first computation with determinisitc algo

tckgen -nthreads 0 -config MRTRIX_RNG_SEED 20 -algorithm SD_STREAM -select 1000 -seed_image ./fs/ROIs/Left-AV_dil-1.nii.gz -seed_unidirectional -include ./fs/ROIs/ctx-lh-lateralorbitofrontal_AND_ctx-lh-medialorbitofrontal_dil-1.nii.gz -angle 45 -cutoff 0.05 -minlength 40 -maxlength 90 -stop ./dwi_wmCsd_autolmax.mif compuatation_1_SD_STREAM.tck

second computation with determinisitc algo

tckgen -nthreads 0 -config MRTRIX_RNG_SEED 20 -algorithm SD_STREAM -select 1000 -seed_image ./fs/ROIs/Left-AV_dil-1.nii.gz -seed_unidirectional -include ./fs/ROIs/ctx-lh-lateralorbitofrontal_AND_ctx-lh-medialorbitofrontal_dil-1.nii.gz -angle 45 -cutoff 0.05 -minlength 40 -maxlength 90 -stop ./dwi_wmCsd_autolmax.mif compuatation_2_SD_STREAM.tck

first computation with prob algo

tckgen -nthreads 0 -config MRTRIX_RNG_SEED 20 -algorithm iFoD2 -select 1000 -seed_image ./fs/ROIs/Left-AV_dil-1.nii.gz -seed_unidirectional -include ./fs/ROIs/ctx-lh-lateralorbitofrontal_AND_ctx-lh-medialorbitofrontal_dil-1.nii.gz -angle 45 -cutoff 0.05 -minlength 40 -maxlength 90 -stop ./dwi_wmCsd_autolmax.mif compuatation_1_ifod2.tck

second computation with prob algo

tckgen -nthreads 0 -config MRTRIX_RNG_SEED 20 -algorithm iFoD2 -select 1000 -seed_image ./fs/ROIs/Left-AV_dil-1.nii.gz -seed_unidirectional -include ./fs/ROIs/ctx-lh-lateralorbitofrontal_AND_ctx-lh-medialorbitofrontal_dil-1.nii.gz -angle 45 -cutoff 0.05 -minlength 40 -maxlength 90 -stop ./dwi_wmCsd_autolmax.mif compuatation_2_ifod2.tck

The issue here is that MRTRIX_RNG_SEED is an environment variable, not a config file entry. Try typing:

export MRTRIX_RNG_SEED=20

before invoking tckgen. Alternatively, you should be able to prefix your tckgen call with MRTRIX_RNG_SEED=20, like so:

MRTRIX_RNG_SEED=20 tckgen -nthreads 0 -algorithm ifod2 ...

Thanks! Confirmed it works!

1 Like