Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions extra_tests/regression_fits/trainable_prepro.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ mcseed: 1

load: "weights.weights.h5"

sampling:
separate_multiplicative: True
separate_multiplicative: True

parameters: # This defines the parameter dictionary that is passed to the Model Trainer
nodes_per_layer: [15, 10, 8]
Expand Down
3 changes: 1 addition & 2 deletions n3fit/runcards/examples/Basic_feature_scaling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ datacuts:
############################################################
theory:
theoryid: 708 # database id
sampling:
separate_multiplicative: true
separate_multiplicative: True

############################################################
trvlseed: 1
Expand Down
3 changes: 1 addition & 2 deletions n3fit/runcards/examples/Basic_hyperopt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ datacuts:
theory:
theoryid: 708 # database id

sampling:
separate_multiplicative: true
separate_multiplicative: True

############################################################
hyperscan_config:
Expand Down
3 changes: 1 addition & 2 deletions n3fit/runcards/examples/Basic_runcard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ theory:
theoryid: 708 # database id

resample_negative_pseudodata: True
separate_multiplicative: 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']
Expand Down
3 changes: 1 addition & 2 deletions n3fit/runcards/examples/Basic_runcard_closure_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ datacuts:
theory:
theoryid: 708 # database id

sampling:
separate_multiplicative: 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']
Expand Down
3 changes: 1 addition & 2 deletions n3fit/runcards/examples/Basic_runcard_parallel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ datacuts:
theory:
theoryid: 708 # database id

sampling:
separate_multiplicative: true
separate_multiplicative: True
############################################################
trvlseed: 1
nnseed: 2
Expand Down
3 changes: 1 addition & 2 deletions n3fit/runcards/examples/DIS_diagonal_l2reg_example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ datacuts:
theory:
theoryid: 708 # database id

sampling:
separate_multiplicative: true
separate_multiplicative: True
############################################################
trvlseed: 1
nnseed: 2
Expand Down
3 changes: 1 addition & 2 deletions n3fit/runcards/examples/developing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ datacuts:
theory:
theoryid: 40000000

sampling:
separate_multiplicative: true
separate_multiplicative: True
############################################################
trvlseed: 1
nnseed: 2
Expand Down
11 changes: 3 additions & 8 deletions n3fit/src/n3fit/scripts/n3fit_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions n3fit/src/n3fit/tests/regressions/quickcard-sequential.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ nnseed: 2
mcseed: 1

save: weights.weights.h5
sampling:
separate_multiplicative: true
separate_multiplicative: True

parameters: # This defines the parameter dictionary that is passed to the Model Trainer
nodes_per_layer: [15, 10, 8]
Expand Down
3 changes: 1 addition & 2 deletions n3fit/src/n3fit/tests/regressions/quickcard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ nnseed: 2
mcseed: 1

load: "weights.weights.h5"
sampling:
separate_multiplicative: true
separate_multiplicative: True

parameters: # This defines the parameter dictionary that is passed to the Model Trainer
nodes_per_layer: [15, 10, 8]
Expand Down
3 changes: 1 addition & 2 deletions n3fit/src/n3fit/tests/regressions/quickcard_pol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ nnseed: 2
mcseed: 1

load: "weights_pol.weights.h5"
sampling:
separate_multiplicative: true
separate_multiplicative: True

parameters:
nodes_per_layer: [25, 20, 4]
Expand Down
3 changes: 1 addition & 2 deletions n3fit/src/n3fit/tests/regressions/quickcard_qed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ nnseed: 2
mcseed: 1

load: "weights.weights.h5"
sampling:
separate_multiplicative: true
separate_multiplicative: True

parameters: # This defines the parameter dictionary that is passed to the Model Trainer
nodes_per_layer: [15, 10, 8]
Expand Down
14 changes: 8 additions & 6 deletions validphys2/src/validphys/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,12 +701,14 @@ def produce_dataset_inputs_fitting_covmat(
return covmats.dataset_inputs_t0_total_covmat
return covmats.dataset_inputs_t0_exp_covmat

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
Expand All @@ -716,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
Expand Down
34 changes: 9 additions & 25 deletions validphys2/src/validphys/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,27 +191,19 @@ 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
being shifted away from the underlying law.

"""
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.
Expand All @@ -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
)
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
24 changes: 10 additions & 14 deletions validphys2/src/validphys/pseudodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion validphys2/src/validphys/tests/test_overfit_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"t0pdfset": {"from_": "datacuts"},
"pdf": {"from_": "fit"},
"dataset_inputs": {"from_": "fit"},
"separate_multiplicative": True
"separate_multiplicative": True,
}


Expand Down
1 change: 1 addition & 0 deletions validphys2/src/validphys/tests/test_pseudodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down