From fea55a3e312b4bfa92e74b81997111904070b120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Sun, 10 Sep 2023 16:01:45 -0400 Subject: [PATCH 1/2] ENH: Make tractogram downsampling results reproducible by default Make tractogram downsampling results reproducible by default: set a default value to the random seed. --- whitematteranalysis/filter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/whitematteranalysis/filter.py b/whitematteranalysis/filter.py index 9e542cc0..2d6cf9f6 100644 --- a/whitematteranalysis/filter.py +++ b/whitematteranalysis/filter.py @@ -250,7 +250,7 @@ def preprocess(inpd, min_length_mm, else: return outpd -def downsample(inpd, output_number_of_lines, return_indices=False, preserve_point_data=False, preserve_cell_data=True, initial_indices=None, verbose=True, random_seed=None): +def downsample(inpd, output_number_of_lines, return_indices=False, preserve_point_data=False, preserve_cell_data=True, initial_indices=None, verbose=True, random_seed=1234): """ Random (down)sampling of fibers without replacement. """ if initial_indices is None: From 96f67193935cf6780093721a41411461b4bca58a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Sat, 9 Sep 2023 19:24:38 -0400 Subject: [PATCH 2/2] ENH: Allow non-identical results in tractogram downsampling Allow non-identical results in tractogram downsampling: add a flag so that the random seed value is set to `None` when it is used, and thus, allow for non-identical results when randomly drawing a subset of streamlines. The default behavior is to obtain reproducible (identical) results across runs after the change introduced in commit fea55a3. --- bin/wm_preprocess_all.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bin/wm_preprocess_all.py b/bin/wm_preprocess_all.py index d29773a1..e3951676 100755 --- a/bin/wm_preprocess_all.py +++ b/bin/wm_preprocess_all.py @@ -47,6 +47,9 @@ def main(): parser.add_argument( '-retaindata', action='store_true', dest="flag_retaindata", help='If given, all point and cell data stored along the tractography will be retained.') + parser.add_argument( + '--nonidentical', action='store_true', + help='Obtain nonidentical results across runs for downsampling.') args = parser.parse_args() @@ -88,7 +91,11 @@ def main(): else: print("Remove all data stored along the tractography and only keep fiber streamlines.") retaindata = args.flag_retaindata - + + random_seed = 1234 + if args.nonidentical: + random_seed = None + print("==========================") # ======================================================================= @@ -154,7 +161,7 @@ def pipeline(inputPolyDatas, sidx, args): print(id_msg + msg) # , preserve_point_data=True needs editing of preprocess function to use mask function - wm3 = wma.filter.downsample(wm2, args.numberOfFibers, preserve_point_data=retaindata, preserve_cell_data=retaindata, verbose=False) + wm3 = wma.filter.downsample(wm2, args.numberOfFibers, preserve_point_data=retaindata, preserve_cell_data=retaindata, verbose=False, random_seed=random_seed) print("Number of fibers retained: ", wm3.GetNumberOfLines(), "/", num_lines) if wm3 is None: