From f580d19a139d45fbe1fd726502a08ca3c0039c5f Mon Sep 17 00:00:00 2001 From: Philip Cook Date: Mon, 17 May 2021 12:19:26 -0400 Subject: [PATCH] ENH: Allow user to set random seed in repro mode --- Scripts/antsRegistrationSyN.sh | 35 ++++++++++++++++++++++++----- Scripts/antsRegistrationSyNQuick.sh | 35 +++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/Scripts/antsRegistrationSyN.sh b/Scripts/antsRegistrationSyN.sh index d40391180..45ea41356 100755 --- a/Scripts/antsRegistrationSyN.sh +++ b/Scripts/antsRegistrationSyN.sh @@ -95,14 +95,19 @@ Optional arguments: 0: false 1: true - -y: use 'repro' mode. GC for linear stages and fixed seed + -y: use 'repro' mode for exact reproducibility of output. Uses GC metric for linear + stages and a fixed random seed (default = 0). + 0: false + 1: true -z: collapse output transforms (default = 1) + -e: Fix random seed to an int value + NB: Multiple image pairs can be specified for registration during the SyN stage. Specify additional images using the '-m' and '-f' options. Note that image pair correspondence is given by the order specified on the command line. - Only the first fixed and moving image pair is used for the linear resgitration + Only the first fixed and moving image pair is used for the linear registration stages. Example: @@ -179,11 +184,16 @@ Optional arguments: 0: false 1: true - -y: use 'repro' mode. GC for linear stages and fixed seed + -y: use 'repro' mode for exact reproducibility of output. Uses GC metric for linear + stages and a fixed random seed (default = 0). + 0: false + 1: true -z: collapse output transforms (default = 1) + 0: false + 1: true - -e: Fix random seed to an int value (default = system time) + -e: Fix random seed to an int value NB: Multiple image pairs can be specified for registration during the SyN stage. Specify additional images using the '-m' and '-f' options. Note that image @@ -491,11 +501,26 @@ if [[ $ISLARGEIMAGE -eq 1 ]]; LINEARMETRIC="MI" LINEARMETRICPARAMETER=32 + +# Precedence for random seeding +# 1. Command line option -e +# 2. Environment variable ANTS_RANDOM_SEED +# 3. Fixed seed = 1 if run in repro mode +# 4. ITK default (system time) + +if [[ -n ${ANTS_RANDOM_SEED} ]] && [[ ${RANDOMSEED} -eq 0 ]]; + then + RANDOMSEED=${ANTS_RANDOM_SEED} + fi + if [[ $REPRO -eq 1 ]]; then LINEARMETRIC="GC" LINEARMETRICPARAMETER=1 - RANDOMSEED=1 + if [[ ${RANDOMSEED} -eq 0 ]]; + then + RANDOMSEED=1 + fi fi INITIALSTAGE="--initial-moving-transform [ ${FIXEDIMAGES[0]},${MOVINGIMAGES[0]},1 ]" diff --git a/Scripts/antsRegistrationSyNQuick.sh b/Scripts/antsRegistrationSyNQuick.sh index 286bc0300..27a9f49f5 100755 --- a/Scripts/antsRegistrationSyNQuick.sh +++ b/Scripts/antsRegistrationSyNQuick.sh @@ -95,9 +95,16 @@ Optional arguments: 0: false 1: true - -y: use 'repro' mode. GC for linear stages and fixed seed + -y: use 'repro' mode for exact reproducibility of output. Uses GC metric for linear + stages, CC metric for deformable stages, and a fixed random seed (default = 0). + 0: false + 1: true -z: collapse output transforms (default = 1) + 0: false + 1: true + + -e: Fix random seed to an int value NB: Multiple image pairs can be specified for registration during the SyN stage. Specify additional images using the '-m' and '-f' options. Note that image @@ -179,11 +186,16 @@ Optional arguments: 0: false 1: true - -y: use 'repro' mode. GC for linear stages and fixed seed + -y: use 'repro' mode for exact reproducibility of output. Uses GC metric for linear + stages, CC metric for deformable stages, and a fixed random seed (default = 0). + 0: false + 1: true -z: collapse output transforms (default = 1) + 0: false + 1: true - -e: Fix random seed to an int value (default = system time) + -e: Fix random seed to an int value NB: Multiple image pairs can be specified for registration during the SyN stage. Specify additional images using the '-m' and '-f' options. Note that image @@ -491,11 +503,26 @@ if [[ $ISLARGEIMAGE -eq 1 ]]; LINEARMETRIC="MI" LINEARMETRICPARAMETER=32 + +# Precedence for random seeding +# 1. Command line option -e +# 2. Environment variable ANTS_RANDOM_SEED +# 3. Fixed seed = 1 if run in repro mode +# 4. ITK default (system time) + +if [[ -n ${ANTS_RANDOM_SEED} ]] && [[ ${RANDOMSEED} -eq 0 ]]; + then + RANDOMSEED=${ANTS_RANDOM_SEED} + fi + if [[ $REPRO -eq 1 ]]; then LINEARMETRIC="GC" LINEARMETRICPARAMETER=1 - RANDOMSEED=1 + if [[ ${RANDOMSEED} -eq 0 ]]; + then + RANDOMSEED=1 + fi fi INITIALSTAGE="--initial-moving-transform [ ${FIXEDIMAGES[0]},${MOVINGIMAGES[0]},1 ]"