-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Theory uncertainties implemented #35
base: main
Are you sure you want to change the base?
Changes from all commits
67f4185
bb22e01
b720b69
1c4ca02
dfe53b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,11 @@ | |
from importlib.util import spec_from_loader | ||
import numpy as np | ||
import tensorflow as tf | ||
import yaml | ||
|
||
import os | ||
|
||
import scipy as sp | ||
|
||
from validphys import bsmnames | ||
|
||
|
@@ -25,6 +30,8 @@ | |
from n3fit.backends import base_layer_selector, regularizer_selector | ||
from n3fit.layers.CombineCfac import CombineCfacLayer | ||
|
||
from validphys.loader import _get_nnpdf_profile | ||
|
||
import logging | ||
log = logging.getLogger(__name__) | ||
|
||
|
@@ -148,7 +155,12 @@ def __call__(self, pdf_layer, mask=None): | |
|
||
|
||
def observable_generator( | ||
spec_dict, positivity_initial=1.0, integrability=False, post_observable=None | ||
spec_dict, | ||
positivity_initial=1.0, | ||
integrability=False, | ||
post_observable=None, | ||
use_th_covmat=False, | ||
theoryid=None, | ||
): # pylint: disable=too-many-locals | ||
""" | ||
This function generates the observable model for each experiment. | ||
|
@@ -318,6 +330,29 @@ def observable_generator( | |
obsrot_tr = None | ||
obsrot_vl = None | ||
|
||
if use_th_covmat: | ||
data_path = str(_get_nnpdf_profile()['data_path']) + 'theory_' + theoryid.id + '/simu_factors' | ||
# If using the theory covariance matrix, we must build it here. | ||
th_covmats = [] | ||
for ds in spec_dict.get("datasets"): | ||
simu_fac_path = data_path + '/SIMU_' + ds['name'] + '.yaml' | ||
if os.path.exists(simu_fac_path): | ||
with open(simu_fac_path, 'rb') as file: | ||
simu_file = yaml.safe_load(file) | ||
if 'theory_cov' in simu_file.keys(): | ||
th_covmats += [simu_file['theory_cov']] | ||
else: | ||
th_covmats += [np.zeros((ds['ndata'],ds['ndata']))] | ||
else: | ||
th_covmats += [np.zeros((ds['ndata'],ds['ndata']))] | ||
|
||
th_covmat = sp.linalg.block_diag(*th_covmats) | ||
|
||
if not np.all((th_covmat == 0.0)): | ||
covmat = th_covmat + spec_dict["covmat"] | ||
invcovmat = np.linalg.inv(covmat) | ||
spec_dict["invcovmat"] = invcovmat | ||
|
||
Comment on lines
+354
to
+355
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @J-M-Moore, here you are changing the invcovmat entry of spec_dict. I am asking since out_exp at line 378 is given the covmat not augmented with the theory one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm yeah you're probably right that this is a mistake |
||
out_tr = ObservableWrapper( | ||
spec_name, | ||
model_obs_tr, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably need to have a check here to ensure that only the SIMUnet theory is used.
No other theory has simu_factors