From 3c4fbf1cf3552805d62fc359959ba547d5df8781 Mon Sep 17 00:00:00 2001 From: RoyStegeman Date: Wed, 22 May 2024 13:57:24 +0100 Subject: [PATCH 1/3] add resample_pseudodata flag --- validphys2/src/validphys/pseudodata.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/validphys2/src/validphys/pseudodata.py b/validphys2/src/validphys/pseudodata.py index 963696383b..41161ca5c7 100644 --- a/validphys2/src/validphys/pseudodata.py +++ b/validphys2/src/validphys/pseudodata.py @@ -129,6 +129,7 @@ def make_replica( sep_mult, genrep=True, max_tries=int(1e6), + resample_pseudodata=True, ): """Function that takes in a list of :py:class:`validphys.coredata.CommonData` objects and returns a pseudodata replica accounting for @@ -163,6 +164,10 @@ def make_replica( If after max_tries (default=1e6) no physical configuration is found, it will raise a :py:class:`ReplicaGenerationError` + + resample_pseudodata: bool + Set to False to allow for negative predictions and avoid resampling + Returns ------- pseudodata: np.array @@ -263,7 +268,10 @@ def make_replica( # Shifting pseudodata shifted_pseudodata = (all_pseudodata + shifts) * mult_part # positivity control - if np.all(shifted_pseudodata[full_mask] >= 0): + if resample_pseudodata: + if np.all(shifted_pseudodata[full_mask] >= 0): + return shifted_pseudodata + else: return shifted_pseudodata dfail = " ".join(i.setname for i in groups_dataset_inputs_loaded_cd_with_cuts) From 4f5c19ff3564537461c77d10c4880002139e71c5 Mon Sep 17 00:00:00 2001 From: Roy Stegeman Date: Wed, 22 May 2024 14:53:33 +0100 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Juan M. Cruz-Martinez --- validphys2/src/validphys/pseudodata.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/validphys2/src/validphys/pseudodata.py b/validphys2/src/validphys/pseudodata.py index 41161ca5c7..c12368f13e 100644 --- a/validphys2/src/validphys/pseudodata.py +++ b/validphys2/src/validphys/pseudodata.py @@ -129,7 +129,7 @@ def make_replica( sep_mult, genrep=True, max_tries=int(1e6), - resample_pseudodata=True, + resample_negative_pseudodata=True, ): """Function that takes in a list of :py:class:`validphys.coredata.CommonData` objects and returns a pseudodata replica accounting for @@ -164,10 +164,8 @@ def make_replica( If after max_tries (default=1e6) no physical configuration is found, it will raise a :py:class:`ReplicaGenerationError` - - resample_pseudodata: bool - Set to False to allow for negative predictions and avoid resampling - + resample_negative_pseudodata: bool + When True, replicas that produce negative predictions will be resampled for ``max_tries`` until all points are positive (default: True) Returns ------- pseudodata: np.array @@ -268,10 +266,7 @@ def make_replica( # Shifting pseudodata shifted_pseudodata = (all_pseudodata + shifts) * mult_part # positivity control - if resample_pseudodata: - if np.all(shifted_pseudodata[full_mask] >= 0): - return shifted_pseudodata - else: + if np.all(shifted_pseudodata[full_mask] >= 0) or not resample_negative_pseudodata: return shifted_pseudodata dfail = " ".join(i.setname for i in groups_dataset_inputs_loaded_cd_with_cuts) From 8bc67b74789176fd61b73623083e026e1e3204aa Mon Sep 17 00:00:00 2001 From: RoyStegeman Date: Wed, 22 May 2024 14:56:02 +0100 Subject: [PATCH 3/3] add resample_negative_pseudodata to Basic_runcard --- n3fit/runcards/examples/Basic_runcard.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/n3fit/runcards/examples/Basic_runcard.yml b/n3fit/runcards/examples/Basic_runcard.yml index 89a3294dd4..e64260d3bd 100644 --- a/n3fit/runcards/examples/Basic_runcard.yml +++ b/n3fit/runcards/examples/Basic_runcard.yml @@ -23,6 +23,8 @@ datacuts: theory: theoryid: 708 # database id +resample_negative_pseudodata: True + sampling: separate_multiplicative: true parameters: # This defines the parameter dictionary that is passed to the Model Trainer