From 40fd8a47a7a9258aa8e012c141953cd6dc73a908 Mon Sep 17 00:00:00 2001 From: RoyStegeman Date: Wed, 17 Jul 2024 11:17:02 +0100 Subject: [PATCH 1/5] move separate_multiplicative key outside sampling key in runcard this fixes vp-setupfit since there separate_multiplicative was not parsed from the sampling key and thus it was not found --- n3fit/src/n3fit/scripts/n3fit_exec.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/n3fit/src/n3fit/scripts/n3fit_exec.py b/n3fit/src/n3fit/scripts/n3fit_exec.py index 9c68bbb5e1..80a21e4b74 100755 --- a/n3fit/src/n3fit/scripts/n3fit_exec.py +++ b/n3fit/src/n3fit/scripts/n3fit_exec.py @@ -76,8 +76,8 @@ def init_output(self): # create output folder for the fit self.replica_path = self.output_path / "nnfit" for replica in self.replicas: - path = self.replica_path / "replica_{0}".format(replica) - log.info("Creating replica output folder in {0}".format(path)) + path = self.replica_path / f"replica_{replica}" + log.info(f"Creating replica output folder in {path}") try: path.mkdir(exist_ok=True) except OSError as e: @@ -177,11 +177,6 @@ def from_yaml(cls, o, *args, **kwargs): N3FIT_FIXED_CONFIG['use_scalevar_uncertainties'] = thconfig.get( 'use_scalevar_uncertainties', True ) - # Sampling flags - if (sam_t0 := file_content.get('sampling')) is not None: - N3FIT_FIXED_CONFIG['separate_multiplicative'] = sam_t0.get( - 'separate_multiplicative', False - ) # Fitting flag file_content.update(N3FIT_FIXED_CONFIG) return cls(file_content, *args, **kwargs) @@ -261,7 +256,7 @@ class N3FitApp(App): config_class = N3FitConfig def __init__(self): - super(N3FitApp, self).__init__(name="n3fit", providers=N3FIT_PROVIDERS) + super().__init__(name="n3fit", providers=N3FIT_PROVIDERS) @property def argparser(self): From 53dcb51f0f3bd60b110434f156db1731fddef60d Mon Sep 17 00:00:00 2001 From: RoyStegeman Date: Wed, 17 Jul 2024 11:54:05 +0100 Subject: [PATCH 2/5] introduce sep_mult key that sets default for separate_multiplicative --- extra_tests/regression_fits/trainable_prepro.yml | 3 +-- n3fit/runcards/examples/Basic_feature_scaling.yml | 3 +-- n3fit/runcards/examples/Basic_hyperopt.yml | 3 +-- n3fit/runcards/examples/Basic_runcard.yml | 3 +-- n3fit/runcards/examples/Basic_runcard_closure_test.yml | 3 +-- n3fit/runcards/examples/Basic_runcard_parallel.yml | 3 +-- n3fit/runcards/examples/DIS_diagonal_l2reg_example.yml | 3 +-- n3fit/runcards/examples/developing.yml | 3 +-- n3fit/src/n3fit/tests/regressions/quickcard-sequential.yml | 3 +-- n3fit/src/n3fit/tests/regressions/quickcard.yml | 3 +-- n3fit/src/n3fit/tests/regressions/quickcard_pol.yml | 3 +-- n3fit/src/n3fit/tests/regressions/quickcard_qed.yml | 3 +-- validphys2/src/validphys/config.py | 5 +++++ 13 files changed, 17 insertions(+), 24 deletions(-) diff --git a/extra_tests/regression_fits/trainable_prepro.yml b/extra_tests/regression_fits/trainable_prepro.yml index 132620e0b7..d7ee0434da 100644 --- a/extra_tests/regression_fits/trainable_prepro.yml +++ b/extra_tests/regression_fits/trainable_prepro.yml @@ -35,8 +35,7 @@ mcseed: 1 load: "weights.weights.h5" -sampling: - separate_multiplicative: True +sep_mult: True parameters: # This defines the parameter dictionary that is passed to the Model Trainer nodes_per_layer: [15, 10, 8] diff --git a/n3fit/runcards/examples/Basic_feature_scaling.yml b/n3fit/runcards/examples/Basic_feature_scaling.yml index a6d3e8e224..2cdc3b92c6 100644 --- a/n3fit/runcards/examples/Basic_feature_scaling.yml +++ b/n3fit/runcards/examples/Basic_feature_scaling.yml @@ -22,8 +22,7 @@ datacuts: ############################################################ theory: theoryid: 708 # database id -sampling: - separate_multiplicative: true +sep_mult: True ############################################################ trvlseed: 1 diff --git a/n3fit/runcards/examples/Basic_hyperopt.yml b/n3fit/runcards/examples/Basic_hyperopt.yml index ded3f8b392..8727a2cc59 100644 --- a/n3fit/runcards/examples/Basic_hyperopt.yml +++ b/n3fit/runcards/examples/Basic_hyperopt.yml @@ -40,8 +40,7 @@ datacuts: theory: theoryid: 708 # database id -sampling: - separate_multiplicative: true +sep_mult: True ############################################################ hyperscan_config: diff --git a/n3fit/runcards/examples/Basic_runcard.yml b/n3fit/runcards/examples/Basic_runcard.yml index f315d80f45..4fe97a8328 100644 --- a/n3fit/runcards/examples/Basic_runcard.yml +++ b/n3fit/runcards/examples/Basic_runcard.yml @@ -24,9 +24,8 @@ theory: theoryid: 708 # database id resample_negative_pseudodata: True +sep_mult: True -sampling: - separate_multiplicative: true parameters: # This defines the parameter dictionary that is passed to the Model Trainer nodes_per_layer: [15, 10, 8] activation_per_layer: ['sigmoid', 'sigmoid', 'linear'] diff --git a/n3fit/runcards/examples/Basic_runcard_closure_test.yml b/n3fit/runcards/examples/Basic_runcard_closure_test.yml index 564c6bf761..c8fe5aa10e 100644 --- a/n3fit/runcards/examples/Basic_runcard_closure_test.yml +++ b/n3fit/runcards/examples/Basic_runcard_closure_test.yml @@ -23,8 +23,7 @@ datacuts: theory: theoryid: 708 # database id -sampling: - separate_multiplicative: true +sep_mult: True parameters: # This defines the parameter dictionary that is passed to the Model Trainer nodes_per_layer: [15, 10, 8] activation_per_layer: ['sigmoid', 'sigmoid', 'linear'] diff --git a/n3fit/runcards/examples/Basic_runcard_parallel.yml b/n3fit/runcards/examples/Basic_runcard_parallel.yml index a515fe04a6..c908a7a0bc 100644 --- a/n3fit/runcards/examples/Basic_runcard_parallel.yml +++ b/n3fit/runcards/examples/Basic_runcard_parallel.yml @@ -24,8 +24,7 @@ datacuts: theory: theoryid: 708 # database id -sampling: - separate_multiplicative: true +sep_mult: True ############################################################ trvlseed: 1 nnseed: 2 diff --git a/n3fit/runcards/examples/DIS_diagonal_l2reg_example.yml b/n3fit/runcards/examples/DIS_diagonal_l2reg_example.yml index 7de4b5ce7f..97beabfac7 100644 --- a/n3fit/runcards/examples/DIS_diagonal_l2reg_example.yml +++ b/n3fit/runcards/examples/DIS_diagonal_l2reg_example.yml @@ -39,8 +39,7 @@ datacuts: theory: theoryid: 708 # database id -sampling: - separate_multiplicative: true +sep_mult: True ############################################################ trvlseed: 1 nnseed: 2 diff --git a/n3fit/runcards/examples/developing.yml b/n3fit/runcards/examples/developing.yml index a2e3789ec8..62bd25047d 100644 --- a/n3fit/runcards/examples/developing.yml +++ b/n3fit/runcards/examples/developing.yml @@ -52,8 +52,7 @@ datacuts: theory: theoryid: 40000000 -sampling: - separate_multiplicative: true +sep_mult: True ############################################################ trvlseed: 1 nnseed: 2 diff --git a/n3fit/src/n3fit/tests/regressions/quickcard-sequential.yml b/n3fit/src/n3fit/tests/regressions/quickcard-sequential.yml index 4608267ee2..04e34f4b22 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard-sequential.yml +++ b/n3fit/src/n3fit/tests/regressions/quickcard-sequential.yml @@ -31,8 +31,7 @@ nnseed: 2 mcseed: 1 save: weights.weights.h5 -sampling: - separate_multiplicative: true +sep_mult: True parameters: # This defines the parameter dictionary that is passed to the Model Trainer nodes_per_layer: [15, 10, 8] diff --git a/n3fit/src/n3fit/tests/regressions/quickcard.yml b/n3fit/src/n3fit/tests/regressions/quickcard.yml index 19b32652dc..e59f04d942 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard.yml +++ b/n3fit/src/n3fit/tests/regressions/quickcard.yml @@ -34,8 +34,7 @@ nnseed: 2 mcseed: 1 load: "weights.weights.h5" -sampling: - separate_multiplicative: true +sep_mult: True parameters: # This defines the parameter dictionary that is passed to the Model Trainer nodes_per_layer: [15, 10, 8] diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_pol.yml b/n3fit/src/n3fit/tests/regressions/quickcard_pol.yml index 8702cb5229..5e9a54185e 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard_pol.yml +++ b/n3fit/src/n3fit/tests/regressions/quickcard_pol.yml @@ -32,8 +32,7 @@ nnseed: 2 mcseed: 1 load: "weights_pol.weights.h5" -sampling: - separate_multiplicative: true +sep_mult: True parameters: nodes_per_layer: [25, 20, 4] diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_qed.yml b/n3fit/src/n3fit/tests/regressions/quickcard_qed.yml index 282f982876..b7ab794799 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard_qed.yml +++ b/n3fit/src/n3fit/tests/regressions/quickcard_qed.yml @@ -34,8 +34,7 @@ nnseed: 2 mcseed: 1 load: "weights.weights.h5" -sampling: - separate_multiplicative: true +sep_mult: True parameters: # This defines the parameter dictionary that is passed to the Model Trainer nodes_per_layer: [15, 10, 8] diff --git a/validphys2/src/validphys/config.py b/validphys2/src/validphys/config.py index 1880fda054..2fe4619d71 100644 --- a/validphys2/src/validphys/config.py +++ b/validphys2/src/validphys/config.py @@ -701,6 +701,11 @@ def produce_dataset_inputs_fitting_covmat( return covmats.dataset_inputs_t0_total_covmat return covmats.dataset_inputs_t0_exp_covmat + def produce_separate_multiplicative(self, sep_mult=False): + if sep_mult is False: + return False + return True + @configparser.explicit_node def produce_dataset_inputs_sampling_covmat( self, From 76a5afc0498064a69e8a150f89228dc10fe593d2 Mon Sep 17 00:00:00 2001 From: RoyStegeman Date: Wed, 17 Jul 2024 12:04:00 +0100 Subject: [PATCH 3/5] sep_mult <-> separate_multiplicative --- .../regression_fits/trainable_prepro.yml | 2 +- .../examples/Basic_feature_scaling.yml | 2 +- n3fit/runcards/examples/Basic_hyperopt.yml | 2 +- n3fit/runcards/examples/Basic_runcard.yml | 2 +- .../examples/Basic_runcard_closure_test.yml | 2 +- .../examples/Basic_runcard_parallel.yml | 2 +- .../examples/DIS_diagonal_l2reg_example.yml | 2 +- n3fit/runcards/examples/developing.yml | 2 +- .../regressions/quickcard-sequential.yml | 2 +- .../src/n3fit/tests/regressions/quickcard.yml | 2 +- .../n3fit/tests/regressions/quickcard_pol.yml | 2 +- .../n3fit/tests/regressions/quickcard_qed.yml | 2 +- validphys2/src/validphys/config.py | 13 +++---- validphys2/src/validphys/filters.py | 34 +++++-------------- validphys2/src/validphys/pseudodata.py | 24 ++++++------- .../validphys/tests/test_overfit_metric.py | 2 +- .../src/validphys/tests/test_pseudodata.py | 3 +- 17 files changed, 39 insertions(+), 61 deletions(-) diff --git a/extra_tests/regression_fits/trainable_prepro.yml b/extra_tests/regression_fits/trainable_prepro.yml index d7ee0434da..051bf17658 100644 --- a/extra_tests/regression_fits/trainable_prepro.yml +++ b/extra_tests/regression_fits/trainable_prepro.yml @@ -35,7 +35,7 @@ mcseed: 1 load: "weights.weights.h5" -sep_mult: True +separate_multiplicative: True parameters: # This defines the parameter dictionary that is passed to the Model Trainer nodes_per_layer: [15, 10, 8] diff --git a/n3fit/runcards/examples/Basic_feature_scaling.yml b/n3fit/runcards/examples/Basic_feature_scaling.yml index 2cdc3b92c6..c240b925c2 100644 --- a/n3fit/runcards/examples/Basic_feature_scaling.yml +++ b/n3fit/runcards/examples/Basic_feature_scaling.yml @@ -22,7 +22,7 @@ datacuts: ############################################################ theory: theoryid: 708 # database id -sep_mult: True +separate_multiplicative: True ############################################################ trvlseed: 1 diff --git a/n3fit/runcards/examples/Basic_hyperopt.yml b/n3fit/runcards/examples/Basic_hyperopt.yml index 8727a2cc59..bdf8a4e08e 100644 --- a/n3fit/runcards/examples/Basic_hyperopt.yml +++ b/n3fit/runcards/examples/Basic_hyperopt.yml @@ -40,7 +40,7 @@ datacuts: theory: theoryid: 708 # database id -sep_mult: True +separate_multiplicative: True ############################################################ hyperscan_config: diff --git a/n3fit/runcards/examples/Basic_runcard.yml b/n3fit/runcards/examples/Basic_runcard.yml index 4fe97a8328..f2231d6e2b 100644 --- a/n3fit/runcards/examples/Basic_runcard.yml +++ b/n3fit/runcards/examples/Basic_runcard.yml @@ -24,7 +24,7 @@ theory: theoryid: 708 # database id resample_negative_pseudodata: True -sep_mult: True +separate_multiplicative: True parameters: # This defines the parameter dictionary that is passed to the Model Trainer nodes_per_layer: [15, 10, 8] diff --git a/n3fit/runcards/examples/Basic_runcard_closure_test.yml b/n3fit/runcards/examples/Basic_runcard_closure_test.yml index c8fe5aa10e..3033ee7a70 100644 --- a/n3fit/runcards/examples/Basic_runcard_closure_test.yml +++ b/n3fit/runcards/examples/Basic_runcard_closure_test.yml @@ -23,7 +23,7 @@ datacuts: theory: theoryid: 708 # database id -sep_mult: True +separate_multiplicative: True parameters: # This defines the parameter dictionary that is passed to the Model Trainer nodes_per_layer: [15, 10, 8] activation_per_layer: ['sigmoid', 'sigmoid', 'linear'] diff --git a/n3fit/runcards/examples/Basic_runcard_parallel.yml b/n3fit/runcards/examples/Basic_runcard_parallel.yml index c908a7a0bc..478c76b4b6 100644 --- a/n3fit/runcards/examples/Basic_runcard_parallel.yml +++ b/n3fit/runcards/examples/Basic_runcard_parallel.yml @@ -24,7 +24,7 @@ datacuts: theory: theoryid: 708 # database id -sep_mult: True +separate_multiplicative: True ############################################################ trvlseed: 1 nnseed: 2 diff --git a/n3fit/runcards/examples/DIS_diagonal_l2reg_example.yml b/n3fit/runcards/examples/DIS_diagonal_l2reg_example.yml index 97beabfac7..d699bf8ab1 100644 --- a/n3fit/runcards/examples/DIS_diagonal_l2reg_example.yml +++ b/n3fit/runcards/examples/DIS_diagonal_l2reg_example.yml @@ -39,7 +39,7 @@ datacuts: theory: theoryid: 708 # database id -sep_mult: True +separate_multiplicative: True ############################################################ trvlseed: 1 nnseed: 2 diff --git a/n3fit/runcards/examples/developing.yml b/n3fit/runcards/examples/developing.yml index 62bd25047d..a5abe4b932 100644 --- a/n3fit/runcards/examples/developing.yml +++ b/n3fit/runcards/examples/developing.yml @@ -52,7 +52,7 @@ datacuts: theory: theoryid: 40000000 -sep_mult: True +separate_multiplicative: True ############################################################ trvlseed: 1 nnseed: 2 diff --git a/n3fit/src/n3fit/tests/regressions/quickcard-sequential.yml b/n3fit/src/n3fit/tests/regressions/quickcard-sequential.yml index 04e34f4b22..1c659c0b28 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard-sequential.yml +++ b/n3fit/src/n3fit/tests/regressions/quickcard-sequential.yml @@ -31,7 +31,7 @@ nnseed: 2 mcseed: 1 save: weights.weights.h5 -sep_mult: True +separate_multiplicative: True parameters: # This defines the parameter dictionary that is passed to the Model Trainer nodes_per_layer: [15, 10, 8] diff --git a/n3fit/src/n3fit/tests/regressions/quickcard.yml b/n3fit/src/n3fit/tests/regressions/quickcard.yml index e59f04d942..69fb60984d 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard.yml +++ b/n3fit/src/n3fit/tests/regressions/quickcard.yml @@ -34,7 +34,7 @@ nnseed: 2 mcseed: 1 load: "weights.weights.h5" -sep_mult: True +separate_multiplicative: True parameters: # This defines the parameter dictionary that is passed to the Model Trainer nodes_per_layer: [15, 10, 8] diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_pol.yml b/n3fit/src/n3fit/tests/regressions/quickcard_pol.yml index 5e9a54185e..84668efe13 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard_pol.yml +++ b/n3fit/src/n3fit/tests/regressions/quickcard_pol.yml @@ -32,7 +32,7 @@ nnseed: 2 mcseed: 1 load: "weights_pol.weights.h5" -sep_mult: True +separate_multiplicative: True parameters: nodes_per_layer: [25, 20, 4] diff --git a/n3fit/src/n3fit/tests/regressions/quickcard_qed.yml b/n3fit/src/n3fit/tests/regressions/quickcard_qed.yml index b7ab794799..c840cf22fd 100644 --- a/n3fit/src/n3fit/tests/regressions/quickcard_qed.yml +++ b/n3fit/src/n3fit/tests/regressions/quickcard_qed.yml @@ -34,7 +34,7 @@ nnseed: 2 mcseed: 1 load: "weights.weights.h5" -sep_mult: True +separate_multiplicative: True parameters: # This defines the parameter dictionary that is passed to the Model Trainer nodes_per_layer: [15, 10, 8] diff --git a/validphys2/src/validphys/config.py b/validphys2/src/validphys/config.py index 2fe4619d71..bdd94e213c 100644 --- a/validphys2/src/validphys/config.py +++ b/validphys2/src/validphys/config.py @@ -701,17 +701,14 @@ def produce_dataset_inputs_fitting_covmat( return covmats.dataset_inputs_t0_total_covmat return covmats.dataset_inputs_t0_exp_covmat - def produce_separate_multiplicative(self, sep_mult=False): - if sep_mult is False: + def produce_sep_mult(self, separate_multiplicative=False): + if separate_multiplicative is False: return False return True @configparser.explicit_node def produce_dataset_inputs_sampling_covmat( - self, - separate_multiplicative=False, - theory_covmat_flag=False, - use_thcovmat_in_sampling=False, + self, sep_mult=False, theory_covmat_flag=False, use_thcovmat_in_sampling=False ): """ Produces the correct covmat to be used in make_replica according @@ -721,12 +718,12 @@ def produce_dataset_inputs_sampling_covmat( from validphys import covmats if theory_covmat_flag and use_thcovmat_in_sampling: - if separate_multiplicative: + if sep_mult: return covmats.dataset_inputs_total_covmat_separate else: return covmats.dataset_inputs_total_covmat else: - if separate_multiplicative: + if sep_mult: return covmats.dataset_inputs_exp_covmat_separate else: return covmats.dataset_inputs_exp_covmat diff --git a/validphys2/src/validphys/filters.py b/validphys2/src/validphys/filters.py index 5a9a73e470..780f00eb09 100644 --- a/validphys2/src/validphys/filters.py +++ b/validphys2/src/validphys/filters.py @@ -191,7 +191,7 @@ def export_mask(path, mask): np.savetxt(path, mask, fmt='%d') -def filter_closure_data(filter_path, data, fakepdf, fakenoise, filterseed, separate_multiplicative): +def filter_closure_data(filter_path, data, fakepdf, fakenoise, filterseed, sep_mult): """Filter closure data. In addition to cutting data points, the data is generated from an underlying ``fakepdf``, applying a shift to the data if ``fakenoise`` is ``True``, which emulates the experimental central values @@ -199,19 +199,11 @@ def filter_closure_data(filter_path, data, fakepdf, fakenoise, filterseed, separ """ log.info('Filtering closure-test data.') - return _filter_closure_data( - filter_path, data, fakepdf, fakenoise, filterseed, separate_multiplicative - ) + return _filter_closure_data(filter_path, data, fakepdf, fakenoise, filterseed, sep_mult) def filter_closure_data_by_experiment( - filter_path, - experiments_data, - fakepdf, - fakenoise, - filterseed, - data_index, - separate_multiplicative, + filter_path, experiments_data, fakepdf, fakenoise, filterseed, data_index, sep_mult ): """ Like :py:func:`filter_closure_data` except filters data by experiment. @@ -228,13 +220,7 @@ def filter_closure_data_by_experiment( experiment_index = data_index[data_index.isin([exp.name], level=0)] res.append( _filter_closure_data( - filter_path, - exp, - fakepdf, - fakenoise, - filterseed, - experiment_index, - separate_multiplicative, + filter_path, exp, fakepdf, fakenoise, filterseed, experiment_index, sep_mult ) ) @@ -285,9 +271,7 @@ def _filter_real_data(filter_path, data): return total_data_points, total_cut_data_points -def _filter_closure_data( - filter_path, data, fakepdf, fakenoise, filterseed, data_index, separate_multiplicative -): +def _filter_closure_data(filter_path, data, fakepdf, fakenoise, filterseed, data_index, sep_mult): """ This function is accessed within a closure test only, that is, the fakedata namespace has to be True (If fakedata = False, the _filter_real_data function @@ -352,9 +336,7 @@ def _filter_closure_data( if fakenoise: # ======= Level 1 closure test =======# - closure_data = make_level1_data( - data, closure_data, filterseed, data_index, separate_multiplicative - ) + closure_data = make_level1_data(data, closure_data, filterseed, data_index, sep_mult) # ====== write commondata and systype files ======# if fakenoise: @@ -411,7 +393,9 @@ def check_positivity(posdatasets): log.info('Verifying positivity tables:') for pos in posdatasets: pos.load_commondata() - log.info(f'{pos.name} checked, {len(pos.cuts.load())}/{pos.commondata.ndata} datapoints passed kinematic cuts.') + log.info( + f'{pos.name} checked, {len(pos.cuts.load())}/{pos.commondata.ndata} datapoints passed kinematic cuts.' + ) def check_integrability(integdatasets): diff --git a/validphys2/src/validphys/pseudodata.py b/validphys2/src/validphys/pseudodata.py index a0083bb803..d29255a9c7 100644 --- a/validphys2/src/validphys/pseudodata.py +++ b/validphys2/src/validphys/pseudodata.py @@ -126,7 +126,7 @@ def make_replica( groups_dataset_inputs_loaded_cd_with_cuts, replica_mcseed, dataset_inputs_sampling_covmat, - separate_multiplicative=False, + sep_mult=False, genrep=True, max_tries=int(1e6), resample_negative_pseudodata=True, @@ -152,7 +152,7 @@ def make_replica( dataset_inputs_sampling_covmat: np.array Full covmat to be used. It can be either only experimental or also theoretical. - separate_multiplicative: bool + sep_mult: bool Specifies whether computing the shifts with the full covmat or whether multiplicative errors should be separated @@ -219,9 +219,9 @@ def make_replica( pseudodata = cd.central_values.to_numpy() pseudodatas.append(pseudodata) - # Separation of multiplicative errors. If separate_multiplicative is True also the exp_covmat is produced + # Separation of multiplicative errors. If sep_mult is True also the exp_covmat is produced # without multiplicative errors - if separate_multiplicative: + if sep_mult: mult_errors = cd.multiplicative_errors mult_uncorr_errors = mult_errors.loc[:, mult_errors.columns == "UNCORR"].to_numpy() mult_corr_errors = mult_errors.loc[:, mult_errors.columns == "CORR"].to_numpy() @@ -234,7 +234,7 @@ def make_replica( else: check_positive_masks.append(np.ones_like(pseudodata, dtype=bool)) # concatenating special multiplicative errors, pseudodatas and positive mask - if separate_multiplicative: + if sep_mult: special_mult_errors = pd.concat(special_mult, axis=0, sort=True).fillna(0).to_numpy() all_pseudodata = np.concatenate(pseudodatas, axis=0) full_mask = np.concatenate(check_positive_masks, axis=0) @@ -255,10 +255,10 @@ def make_replica( mult_shifts.append(mult_shift) - # If separate_multiplicative is true then the multiplicative shifts were not included in the covmat + # If sep_mult is true then the multiplicative shifts were not included in the covmat shifts = covmat_sqrt @ rng.normal(size=covmat.shape[1]) mult_part = 1.0 - if separate_multiplicative: + if sep_mult: special_mult = ( 1 + special_mult_errors * rng.normal(size=(1, special_mult_errors.shape[1])) / 100 ).prod(axis=1) @@ -329,7 +329,7 @@ def level0_commondata_wc(data, fakepdf): return level0_commondata_instances_wc -def make_level1_data(data, level0_commondata_wc, filterseed, data_index, separate_multiplicative): +def make_level1_data(data, level0_commondata_wc, filterseed, data_index, sep_mult): """ Given a list of Level 0 commondata instances, return the same list with central values replaced by Level 1 data. @@ -395,16 +395,12 @@ def make_level1_data(data, level0_commondata_wc, filterseed, data_index, separat use_weights_in_covmat=False, norm_threshold=None, _list_of_central_values=None, - _only_additive=separate_multiplicative, + _only_additive=sep_mult, ) # ================== generation of Level1 data ======================# level1_data = make_replica( - level0_commondata_wc, - filterseed, - covmat, - separate_multiplicative=separate_multiplicative, - genrep=True, + level0_commondata_wc, filterseed, covmat, sep_mult=sep_mult, genrep=True ) indexed_level1_data = indexed_make_replica(data_index, level1_data) diff --git a/validphys2/src/validphys/tests/test_overfit_metric.py b/validphys2/src/validphys/tests/test_overfit_metric.py index 342f21f79c..9e537e8fba 100644 --- a/validphys2/src/validphys/tests/test_overfit_metric.py +++ b/validphys2/src/validphys/tests/test_overfit_metric.py @@ -17,7 +17,7 @@ "t0pdfset": {"from_": "datacuts"}, "pdf": {"from_": "fit"}, "dataset_inputs": {"from_": "fit"}, - "separate_multiplicative": True + "sep_mult": True, } diff --git a/validphys2/src/validphys/tests/test_pseudodata.py b/validphys2/src/validphys/tests/test_pseudodata.py index be6e02ebe5..f9681801c1 100644 --- a/validphys2/src/validphys/tests/test_pseudodata.py +++ b/validphys2/src/validphys/tests/test_pseudodata.py @@ -7,6 +7,7 @@ This is used to benchmark the correctness of the pseudodata recreation. """ + from numpy.testing import assert_allclose import pandas as pd import pytest @@ -74,7 +75,7 @@ def test_no_savepseudodata(): def test_read_matches_recreate(): reads = API.read_fit_pseudodata(fit=PSEUDODATA_FIT) - recreates = API.recreate_fit_pseudodata(fit=PSEUDODATA_FIT, separate_multiplicative=True) + recreates = API.recreate_fit_pseudodata(fit=PSEUDODATA_FIT, sep_mult=True) for read, recreate in zip(reads, recreates): # We ignore the absolute ordering of the dataframes and just check # that they contain identical elements. From f0efd9627d68be8f3e6b500b45240fd15bb49bf7 Mon Sep 17 00:00:00 2001 From: RoyStegeman Date: Wed, 17 Jul 2024 18:14:44 +0100 Subject: [PATCH 4/5] fix test --- validphys2/src/validphys/tests/test_overfit_metric.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validphys2/src/validphys/tests/test_overfit_metric.py b/validphys2/src/validphys/tests/test_overfit_metric.py index 9e537e8fba..f22fd283a5 100644 --- a/validphys2/src/validphys/tests/test_overfit_metric.py +++ b/validphys2/src/validphys/tests/test_overfit_metric.py @@ -17,7 +17,7 @@ "t0pdfset": {"from_": "datacuts"}, "pdf": {"from_": "fit"}, "dataset_inputs": {"from_": "fit"}, - "sep_mult": True, + "separate_multiplicative": True, } From cdb9a660e5166c30c3f73a3b62ff0867638fd92f Mon Sep 17 00:00:00 2001 From: RoyStegeman Date: Wed, 17 Jul 2024 18:23:27 +0100 Subject: [PATCH 5/5] replace test input sep_mult -> separate_multiplicative for aesthetic reasons --- validphys2/src/validphys/tests/test_pseudodata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validphys2/src/validphys/tests/test_pseudodata.py b/validphys2/src/validphys/tests/test_pseudodata.py index f9681801c1..a85aac4309 100644 --- a/validphys2/src/validphys/tests/test_pseudodata.py +++ b/validphys2/src/validphys/tests/test_pseudodata.py @@ -75,7 +75,7 @@ def test_no_savepseudodata(): def test_read_matches_recreate(): reads = API.read_fit_pseudodata(fit=PSEUDODATA_FIT) - recreates = API.recreate_fit_pseudodata(fit=PSEUDODATA_FIT, sep_mult=True) + recreates = API.recreate_fit_pseudodata(fit=PSEUDODATA_FIT, separate_multiplicative=True) for read, recreate in zip(reads, recreates): # We ignore the absolute ordering of the dataframes and just check # that they contain identical elements.