Skip to content

Commit

Permalink
Produce covs_pt_prescrip
Browse files Browse the repository at this point in the history
  • Loading branch information
achiefa authored and RoyStegeman committed Feb 14, 2025
1 parent 7b21216 commit 53e25bd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 32 deletions.
13 changes: 13 additions & 0 deletions validphys2/src/validphys/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1800,6 +1800,19 @@ def produce_power_corr_dict(self, pc_parameters=None):

return pc_parameters_by_type

@configparser.explicit_node
def produce_covs_pt_prescrip(self, point_prescription):
if point_prescription != 'power corrections':
from validphys.theorycovariance.construction import covs_pt_prescrip_mhou

f = covs_pt_prescrip_mhou
else:
from validphys.theorycovariance.construction import covs_pt_prescrip_pc

f = covs_pt_prescrip_pc

return f


class Config(report.Config, CoreConfig):
"""The effective configuration parser class."""
73 changes: 41 additions & 32 deletions validphys2/src/validphys/theorycovariance/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,22 +330,14 @@ def compute_covs_pt_prescrip(point_prescription, name1, deltas1, name2=None, del


@check_correct_theory_combination
def covs_pt_prescrip(
combine_by_type,
point_prescription,
pdf: PDF,
power_corr_dict,
pc_included_procs,
pc_excluded_exps,
):
def covs_pt_prescrip_mhou(combine_by_type, point_prescription):
"""Produces the sub-matrices of the theory covariance matrix according
to a point prescription which matches the number of input theories.
chosen in the runcard in order to specify the prescription. Sub-matrices
correspond to applying the scale variation prescription to each pair of
processes in turn, using a different procedure for the case where the
processes are the same relative to when they are different."""
process_info = combine_by_type
datagroup_spec = process_info.data_spec
running_index = 0

covmats = defaultdict(list)
Expand All @@ -366,30 +358,47 @@ def covs_pt_prescrip(
start_locs = (start_proc[name1], start_proc[name2])
covmats[start_locs] = s

# For power corrections, the loops run over experimentes
else:
start_proc_by_exp = defaultdict(list)
for exp_name, data_spec in datagroup_spec.items():
start_proc_by_exp[exp_name] = running_index
running_index += data_spec.load_commondata().ndata

for exp_name1, data_spec1 in datagroup_spec.items():
for exp_name2, data_spec2 in datagroup_spec.items():
process_type1 = process_lookup(exp_name1)
process_type2 = process_lookup(exp_name2)

is_excluded_exp = any(name in pc_excluded_exps for name in [exp_name1, exp_name2])
is_included_proc = any(
proc not in pc_included_procs for proc in [process_type1, process_type2]
return covmats


def covs_pt_prescrip_pc(
combine_by_type,
point_prescription,
pdf: PDF,
power_corr_dict,
pc_included_procs,
pc_excluded_exps,
):
"""Produces the sub-matrices of the theory covariance matrix for power
corrections. Sub-matrices correspond to applying power corrected shifts
to each pair of `datasets`."""
process_info = combine_by_type
datagroup_spec = process_info.data_spec
running_index = 0

covmats = defaultdict(list)
start_proc_by_exp = defaultdict(list)
for exp_name, data_spec in datagroup_spec.items():
start_proc_by_exp[exp_name] = running_index
running_index += data_spec.load_commondata().ndata

for exp_name1, data_spec1 in datagroup_spec.items():
for exp_name2, data_spec2 in datagroup_spec.items():
process_type1 = process_lookup(exp_name1)
process_type2 = process_lookup(exp_name2)

is_excluded_exp = any(name in pc_excluded_exps for name in [exp_name1, exp_name2])
is_included_proc = any(
proc not in pc_included_procs for proc in [process_type1, process_type2]
)
if not (is_excluded_exp or is_included_proc):
deltas1 = compute_deltas_pc(data_spec1, pdf, power_corr_dict)
deltas2 = compute_deltas_pc(data_spec2, pdf, power_corr_dict)
s = compute_covs_pt_prescrip(
point_prescription, exp_name1, deltas1, exp_name2, deltas2
)
if not (is_excluded_exp or is_included_proc):
deltas1 = compute_deltas_pc(data_spec1, pdf, power_corr_dict)
deltas2 = compute_deltas_pc(data_spec2, pdf, power_corr_dict)
s = compute_covs_pt_prescrip(
point_prescription, exp_name1, deltas1, exp_name2, deltas2
)
start_locs = (start_proc_by_exp[exp_name1], start_proc_by_exp[exp_name2])
covmats[start_locs] = s
start_locs = (start_proc_by_exp[exp_name1], start_proc_by_exp[exp_name2])
covmats[start_locs] = s
return covmats


Expand Down

0 comments on commit 53e25bd

Please sign in to comment.