From bec62bee56ea5c0c2c178fa4da78efb170cdef37 Mon Sep 17 00:00:00 2001 From: juacrumar Date: Wed, 26 May 2021 12:59:50 +0200 Subject: [PATCH] add option to use same trvl seed for all replicas --- doc/sphinx/source/n3fit/runcard_detailed.rst | 10 ++++++++++ validphys2/src/validphys/n3fit_data.py | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/sphinx/source/n3fit/runcard_detailed.rst b/doc/sphinx/source/n3fit/runcard_detailed.rst index ea8fa3baf6..091819644a 100644 --- a/doc/sphinx/source/n3fit/runcard_detailed.rst +++ b/doc/sphinx/source/n3fit/runcard_detailed.rst @@ -105,6 +105,16 @@ The fraction of events that are considered for the training and validation sets It is possible to run a fit with no validation set by setting the fraction to ``1.0``, in this case the training set will be used as validation set. +The random seed for the training/validation split is defined by the variable ``trvlseed``. +By default the seed is further modified by the replica index, but it is possible +to fix it such that it is the same for all replicas with ``same_trvl_per_replica`` +(``false`` by default). + +.. code-block:: yaml + + trvlseed: 7 + same_trvl_per_replica: true + .. _networkarch-label: diff --git a/validphys2/src/validphys/n3fit_data.py b/validphys2/src/validphys/n3fit_data.py index 078f8228a4..2d9a617285 100644 --- a/validphys2/src/validphys/n3fit_data.py +++ b/validphys2/src/validphys/n3fit_data.py @@ -25,11 +25,13 @@ log = logging.getLogger(__name__) -def replica_trvlseed(replica, trvlseed): +def replica_trvlseed(replica, trvlseed, same_trvl_per_replica=False): """Generates the ``trvlseed`` for a ``replica``.""" # TODO: move to the new infrastructure # https://numpy.org/doc/stable/reference/random/index.html#introduction np.random.seed(seed=trvlseed) + if same_trvl_per_replica: + return np.random.randint(0, pow(2, 31)) for _ in range(replica): res = np.random.randint(0, pow(2, 31)) return res