From 89dac9fa6afdbc574271aa9b450c2b9ffe2dd114 Mon Sep 17 00:00:00 2001 From: RosalynLP Date: Tue, 9 Mar 2021 09:42:56 +0000 Subject: [PATCH 01/11] add production rule for force process grouping --- validphys2/src/validphys/config.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/validphys2/src/validphys/config.py b/validphys2/src/validphys/config.py index 9fd0977325..56598fcd5c 100644 --- a/validphys2/src/validphys/config.py +++ b/validphys2/src/validphys/config.py @@ -1358,6 +1358,9 @@ def produce_group_dataset_inputs_by_metadata( def produce_group_dataset_inputs_by_experiment(self, data_input): return self.produce_group_dataset_inputs_by_metadata(data_input, "experiment") + def produce_force_process_grouping(self, data_input): + return self.produce_group_dataset_inputs_by_metadata(data_input, "nnpdf31_process") + def produce_scale_variation_theories(self, theoryid, point_prescription): """Produces a list of theoryids given a theoryid at central scales and a point prescription. The options for the latter are '3 point', '5 point', '5bar point', '7 point' From 871f934c39599fb1a525b920553bf902eb788465 Mon Sep 17 00:00:00 2001 From: RosalynLP Date: Tue, 9 Mar 2021 09:53:14 +0000 Subject: [PATCH 02/11] get rid of unneccessary groups_index --- .../src/validphys/theorycovariance/output.py | 66 ++++++++----------- 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/validphys2/src/validphys/theorycovariance/output.py b/validphys2/src/validphys/theorycovariance/output.py index 819d501b4c..fc0f855210 100644 --- a/validphys2/src/validphys/theorycovariance/output.py +++ b/validphys2/src/validphys/theorycovariance/output.py @@ -76,7 +76,7 @@ def matrix_plot_labels(df): return ticklocs, ticklabels, startlocs -def plot_covmat_heatmap(covmat, title, groups_index): +def plot_covmat_heatmap(covmat, title): """Matrix plot of a covariance matrix.""" df = covmat df.sort_index(0, inplace=True) @@ -180,9 +180,9 @@ def _get_key(element): @figure -def plot_corrmat_heatmap(corrmat, title, groups_index): +def plot_corrmat_heatmap(corrmat, title): """Matrix plot of a correlation matrix""" - df = pd.DataFrame(corrmat.values, index=groups_index, columns=groups_index) + df = corrmat df.sort_index(0, inplace=True) df.sort_index(1, inplace=True) oldindex = df.index.tolist() @@ -210,30 +210,29 @@ def plot_corrmat_heatmap(corrmat, title, groups_index): @figure -def plot_normexpcovmat_heatmap(groups_normcovmat, groups_index): +def plot_normexpcovmat_heatmap(groups_normcovmat): """Matrix plot of the experiment covariance matrix normalised to data.""" fig = plot_covmat_heatmap( - groups_normcovmat, "Experimental Covariance Matrix", groups_index + groups_normcovmat, "Experimental Covariance Matrix" ) return fig @figure -def plot_expcorrmat_heatmap(groups_corrmat, groups_index): +def plot_expcorrmat_heatmap(groups_corrmat): """Matrix plot of the experiment correlation matrix""" fig = plot_corrmat_heatmap( - groups_corrmat, "Experimental Correlation Matrix", groups_index + groups_corrmat, "Experimental Correlation Matrix" ) return fig @figure -def plot_normthblockcovmat_heatmap(theory_normblockcovmat, groups_index): +def plot_normthblockcovmat_heatmap(theory_normblockcovmat): """Matrix plot for block diagonal theory covariance matrix""" fig = plot_covmat_heatmap( theory_normblockcovmat, "Block diagonal theory covariance matrix by dataset", - groups_index, ) return fig @@ -242,7 +241,6 @@ def plot_normthblockcovmat_heatmap(theory_normblockcovmat, groups_index): def plot_normthcovmat_heatmap_custom( theory_normcovmat_custom, theoryids, - groups_index, fivetheories: (str, type(None)) = None, ): """Matrix plot for block diagonal theory covariance matrix by process type""" @@ -253,18 +251,17 @@ def plot_normthcovmat_heatmap_custom( elif fivetheories == "linear": l = "linear 5" fig = plot_covmat_heatmap( - theory_normcovmat_custom, f"Theory Covariance matrix ({l} pt)", groups_index + theory_normcovmat_custom, f"Theory Covariance matrix ({l} pt)" ) return fig @figure -def plot_thblockcorrmat_heatmap(theory_blockcorrmat, groups_index): +def plot_thblockcorrmat_heatmap(theory_blockcorrmat): """Matrix plot of the theory correlation matrix""" fig = plot_corrmat_heatmap( theory_blockcorrmat, - "Theory correlation matrix block diagonal by dataset", - groups_index, + "Theory correlation matrix block diagonal by dataset" ) return fig @@ -273,7 +270,6 @@ def plot_thblockcorrmat_heatmap(theory_blockcorrmat, groups_index): def plot_thcorrmat_heatmap_custom( theory_corrmat_custom, theoryids, - groups_index, fivetheories: (str, type(None)) = None, ): """Matrix plot of the theory correlation matrix, correlations by process type""" @@ -284,20 +280,18 @@ def plot_thcorrmat_heatmap_custom( elif fivetheories == "linear": l = "linear 5" fig = plot_corrmat_heatmap( - theory_corrmat_custom, f"Theory Correlation matrix ({l} pt)", groups_index + theory_corrmat_custom, f"Theory Correlation matrix ({l} pt)" ) return fig @figure def plot_normexpplusblockthcovmat_heatmap( - experimentplusblocktheory_normcovmat, groups_index -): + experimentplusblocktheory_normcovmat): """Matrix plot of the exp + theory covariance matrix normalised to data""" fig = plot_covmat_heatmap( experimentplusblocktheory_normcovmat, "Experiment + theory (block diagonal by dataset) covariance matrix", - groups_index, ) return fig @@ -306,7 +300,6 @@ def plot_normexpplusblockthcovmat_heatmap( def plot_normexpplusthcovmat_heatmap_custom( experimentplustheory_normcovmat_custom, theoryids, - groups_index, fivetheories: (str, type(None)) = None, ): """Matrix plot of the exp + theory covariance matrix normalised to data""" @@ -318,19 +311,17 @@ def plot_normexpplusthcovmat_heatmap_custom( l = "linear 5" fig = plot_covmat_heatmap( experimentplustheory_normcovmat_custom, - f"Experimental + Theory Covariance Matrix ({l} pt)", - groups_index, + f"Experimental + Theory Covariance Matrix ({l} pt)" ) return fig @figure -def plot_expplusblockthcorrmat_heatmap(experimentplusblocktheory_corrmat, groups_index): +def plot_expplusblockthcorrmat_heatmap(experimentplusblocktheory_corrmat): """Matrix plot of the exp + theory correlation matrix""" fig = plot_corrmat_heatmap( experimentplusblocktheory_corrmat, "Experiment + theory (block diagonal by dataset) correlation matrix", - groups_index, ) return fig @@ -339,7 +330,6 @@ def plot_expplusblockthcorrmat_heatmap(experimentplusblocktheory_corrmat, groups def plot_expplusthcorrmat_heatmap_custom( experimentplustheory_corrmat_custom, theoryids, - groups_index, fivetheories: (str, type(None)) = None, ): """Matrix plot of the exp + theory correlation matrix""" @@ -351,14 +341,13 @@ def plot_expplusthcorrmat_heatmap_custom( l = "linear 5" fig = plot_corrmat_heatmap( experimentplustheory_corrmat_custom, - f"Experimental + Theory Correlation Matrix ({l} pt)", - groups_index, + f"Experimental + Theory Correlation Matrix ({l} pt)" ) return fig @figure -def plot_blockcovdiff_heatmap(theory_block_diag_covmat, groups_covmat, groups_index): +def plot_blockcovdiff_heatmap(theory_block_diag_covmat, groups_covmat): """Matrix plot (thcov + expcov)/expcov""" df = (theory_block_diag_covmat.as_matrix() + groups_covmat.values) / np.mean( groups_covmat.values @@ -366,8 +355,7 @@ def plot_blockcovdiff_heatmap(theory_block_diag_covmat, groups_covmat, groups_in fig = plot_covmat_heatmap( df, "(Theory + experiment)/mean(experiment)" - + "for block diagonal theory covmat by dataset", - groups_index, + + "for block diagonal theory covmat by dataset" ) return fig @@ -377,7 +365,6 @@ def plot_covdiff_heatmap_custom( theory_covmat_custom, groups_covmat, theoryids, - groups_index, fivetheories: (str, type(None)) = None, ): """Matrix plot (thcov + expcov)/expcov""" @@ -391,8 +378,7 @@ def plot_covdiff_heatmap_custom( fig = plot_covmat_heatmap( df, "(Theory + experiment)/mean(experiment)" - + f"covariance matrices for {l} points", - groups_index, + + f"covariance matrices for {l} points" ) return fig @@ -403,7 +389,6 @@ def plot_diag_cov_comparison( groups_covmat, groups_data_values, theoryids, - groups_index, fivetheories: (str, type(None)) = None, ): """Plot of sqrt(cov_ii)/|data_i| for cov = exp, theory, exp+theory""" @@ -414,19 +399,20 @@ def plot_diag_cov_comparison( elif fivetheories == "linear": l = "linear 5" data = np.abs(groups_data_values) + plot_index = theory_covmat_custom.index sqrtdiags_th = np.sqrt(np.diag(theory_covmat_custom)) / data - sqrtdiags_th = pd.DataFrame(sqrtdiags_th.values, index=groups_index) + sqrtdiags_th = pd.DataFrame(sqrtdiags_th.values, index=plot_index) sqrtdiags_th.sort_index(0, inplace=True) oldindex = sqrtdiags_th.index.tolist() newindex = sorted(oldindex, key=_get_key) sqrtdiags_th = sqrtdiags_th.reindex(newindex) sqrtdiags_exp = np.sqrt(np.diag(groups_covmat)) / data - sqrtdiags_exp = pd.DataFrame(sqrtdiags_exp.values, index=groups_index) + sqrtdiags_exp = pd.DataFrame(sqrtdiags_exp.values, index=plot_index) sqrtdiags_exp.sort_index(0, inplace=True) sqrtdiags_exp = sqrtdiags_exp.reindex(newindex) df_total = theory_covmat_custom + groups_covmat sqrtdiags_tot = np.sqrt(np.diag(df_total)) / data - sqrtdiags_tot = pd.DataFrame(sqrtdiags_tot.values, index=groups_index) + sqrtdiags_tot = pd.DataFrame(sqrtdiags_tot.values, index=plot_index) sqrtdiags_tot.sort_index(0, inplace=True) sqrtdiags_tot = sqrtdiags_tot.reindex(newindex) fig, ax = plt.subplots(figsize=(20, 10)) @@ -455,7 +441,6 @@ def plot_diag_cov_comparison( def plot_diag_cov_impact( theory_covmat_custom, groups_covmat, - groups_index, groups_data_values, theoryids, fivetheories: (str, type(None)) = None, @@ -473,12 +458,13 @@ def plot_diag_cov_impact( inv_tot = (np.diag(la.inv(matrix_theory + matrix_experiment))) ** ( -0.5 ) / groups_data_values - df_inv_exp = pd.DataFrame(inv_exp, index=groups_index) + plot_index = theory_covmat_custom.index + df_inv_exp = pd.DataFrame(inv_exp, index=plot_index) df_inv_exp.sort_index(0, inplace=True) oldindex = df_inv_exp.index.tolist() newindex = sorted(oldindex, key=_get_key) df_inv_exp = df_inv_exp.reindex(newindex) - df_inv_tot = pd.DataFrame(inv_tot, index=groups_index) + df_inv_tot = pd.DataFrame(inv_tot, index=plot_index) df_inv_tot.sort_index(0, inplace=True) df_inv_tot = df_inv_tot.reindex(newindex) fig, ax = plt.subplots() From dbe79ff005d8b68b157567d05bf13efaebb9316d Mon Sep 17 00:00:00 2001 From: RosalynLP Date: Tue, 9 Mar 2021 10:31:13 +0000 Subject: [PATCH 03/11] add procs actions --- validphys2/src/validphys/results.py | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/validphys2/src/validphys/results.py b/validphys2/src/validphys/results.py index 0d7d31c2d4..43a31f8353 100644 --- a/validphys2/src/validphys/results.py +++ b/validphys2/src/validphys/results.py @@ -154,6 +154,7 @@ def rawdata(self): experiments_data = collect("data", ("group_dataset_inputs_by_experiment",)) +procs_data = collect("data", ("force_process_grouping",)) def groups_index(groups_data): """Return a pandas.MultiIndex with levels for group, dataset and point @@ -193,17 +194,26 @@ def groups_index(groups_data): def experiments_index(experiments_data): return groups_index(experiments_data) +def procs_index(procs_data): + return groups_index(procs_data) def groups_data_values(group_result_table): """Returns list of data values for the input groups.""" data_central_values = group_result_table["data_central"] return data_central_values +def procs_data_values(proc_result_table): + """Like groups_data_values but grouped by process.""" + data_central_values = proc_result_table["data_central"] + return data_central_values groups_results = collect( "dataset_inputs_results", ("group_dataset_inputs_by_metadata",) ) +procs_results = collect( + "dataset_inputs_results", ("force_process_grouping",) +) def group_result_table_no_table(groups_results, groups_index): """Generate a table containing the data central value, the central prediction, @@ -243,12 +253,19 @@ def group_result_table(group_result_table_no_table): """Duplicate of group_result_table_no_table but with a table decorator.""" return group_result_table_no_table +def proc_result_table_no_table(procs_results, procs_index): + return group_result_table_no_table(procs_results, procs_index) + +@table +def proc_result_table(proc_result_table_no_table): + return proc_result_table_no_table experiment_result_table = collect( "group_result_table", ("group_dataset_inputs_by_experiment",) ) + @table def group_result_table_68cl( groups_results, group_result_table_no_table: pd.DataFrame, pdf: PDF @@ -334,6 +351,12 @@ def groups_covmat(groups_covmat_no_table): """Duplicate of groups_covmat_no_table but with a table decorator.""" return groups_covmat_no_table +def procs_covmat_no_table(experiments_covmat_no_table, procs_index): + return relabel_experiments_to_groups(experiments_covmat_no_table, procs_index) + +@table +def procs_covmat(procs_covmat_no_table): + return procs_covmat_no_table experiments_sqrt_covmat = collect( "dataset_inputs_sqrt_covmat", ("group_dataset_inputs_by_experiment",) @@ -401,6 +424,9 @@ def groups_normcovmat(groups_covmat, groups_data_values): mat = df / np.outer(groups_data_array, groups_data_array) return mat +@table +def procs_normcovmat(procs_covmat, procs_data_values): + return groups_normcovmat(procs_covmat, procs_data_values) @table def groups_corrmat(groups_covmat): @@ -411,6 +437,9 @@ def groups_corrmat(groups_covmat): mat = diag_minus_half[:, np.newaxis] * df * diag_minus_half return mat +@table +def procs_corrmat(procs_covmat): + return groups_corrmat(procs_covmat) @table def closure_pseudodata_replicas( @@ -1253,6 +1282,13 @@ def groups_central_values(group_result_table): central_theory_values = group_result_table["theory_central"] return central_theory_values +def procs_central_values_no_table(proc_result_table): + central_theory_values = proc_result_table_no_table["theory_central"] + return central_theory_values + +@table +def procs_central_values(proc_result_table): + return procs_central_values_no_table dataspecs_each_dataset_chi2 = collect("each_dataset_chi2", ("dataspecs",)) each_dataset = collect("dataset", ("data",)) From ae91e6c532e99832c950e9bf936b4cc2c18fd306 Mon Sep 17 00:00:00 2001 From: RosalynLP Date: Tue, 9 Mar 2021 10:39:31 +0000 Subject: [PATCH 04/11] add procs_chi2_table --- validphys2/src/validphys/results.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/validphys2/src/validphys/results.py b/validphys2/src/validphys/results.py index 43a31f8353..88028a7ec7 100644 --- a/validphys2/src/validphys/results.py +++ b/validphys2/src/validphys/results.py @@ -831,6 +831,9 @@ def groups_chi2_table(groups_data, pdf, groups_chi2, each_dataset_chi2): "groups_chi2_table", ("group_dataset_inputs_by_experiment",) ) +procs_chi2_table = collect( + "groups_chi2_table", ("force_process_grouping",) +) @check_cuts_considered @table From 76f5e9d782345aef899cd2b8ae6179c775986ab5 Mon Sep 17 00:00:00 2001 From: RosalynLP Date: Tue, 9 Mar 2021 10:48:04 +0000 Subject: [PATCH 05/11] replace groups -> process in thcov actions --- .../theorycovariance/construction.py | 176 +++++++++--------- .../src/validphys/theorycovariance/output.py | 72 +++---- 2 files changed, 124 insertions(+), 124 deletions(-) diff --git a/validphys2/src/validphys/theorycovariance/construction.py b/validphys2/src/validphys/theorycovariance/construction.py index 94bddec505..65c8c30a82 100644 --- a/validphys2/src/validphys/theorycovariance/construction.py +++ b/validphys2/src/validphys/theorycovariance/construction.py @@ -15,19 +15,19 @@ from reportengine.table import table from reportengine import collect -from validphys.results import (groups_central_values, - groups_central_values_no_table, - groups_data_values) +from validphys.results import (procs_central_values, + procs_central_values_no_table, + procs_data_values) from validphys.results import Chi2Data, results from validphys.calcutils import calc_chi2, all_chi2_theory, central_chi2_theory from validphys.theorycovariance.theorycovarianceutils import process_lookup, check_correct_theory_combination log = logging.getLogger(__name__) -theoryids_groups_central_values = collect(groups_central_values, +theoryids_procs_central_values = collect(procs_central_values, ('theoryids',)) -theoryids_groups_central_values_no_table = collect(groups_central_values_no_table, +theoryids_procs_central_values_no_table = collect(procs_central_values_no_table, ('theoryids',)) collected_theoryids = collect('theoryids', @@ -51,14 +51,14 @@ def make_scale_var_covmat(predictions): return s @check_correct_theory_combination -def theory_covmat_singleprocess_no_table(theoryids_groups_central_values_no_table, - groups_index, theoryids, +def theory_covmat_singleprocess_no_table(theoryids_procs_central_values_no_table, + procs_index, theoryids, fivetheories:(str, type(None)) = None): """Calculates the theory covariance matrix for scale variations. - The matrix is a dataframe indexed by groups_index.""" - s = make_scale_var_covmat(theoryids_groups_central_values_no_table) - df = pd.DataFrame(s, index=groups_index, columns=groups_index) + The matrix is a dataframe indexed by procs_index.""" + s = make_scale_var_covmat(theoryids_procs_central_values_no_table) + df = pd.DataFrame(s, index=procs_index, columns=procs_index) return df @table @@ -70,7 +70,7 @@ def theory_covmat_singleprocess(theory_covmat_singleprocess_no_table, results_bytheoryids = collect(results,('theoryids',)) each_dataset_results_bytheory = collect('results_bytheoryids', - ('group_dataset_inputs_by_metadata','data')) + ('force_process_grouping','data')) @check_correct_theory_combination def theory_covmat_datasets(each_dataset_results_bytheory, @@ -117,46 +117,46 @@ def total_covmat_diagtheory_datasets(each_dataset_results_bytheory, return dataset_covmats @table -def theory_block_diag_covmat(theory_covmat_datasets, groups_index): +def theory_block_diag_covmat(theory_covmat_datasets, procs_index): """Takes the theory covariance matrices for individual datasets and returns a data frame with a block diagonal theory covariance matrix by dataset""" s = la.block_diag(*theory_covmat_datasets) - df = pd.DataFrame(s, index=groups_index, columns=groups_index) + df = pd.DataFrame(s, index=procs_index, columns=procs_index) return df @table -def theory_diagonal_covmat(theory_covmat_singleprocess_no_table, groups_index): +def theory_diagonal_covmat(theory_covmat_singleprocess_no_table, procs_index): """Returns theory covmat with only diagonal values""" s = theory_covmat_singleprocess_no_table.values # Initialise array of zeros and set precision to same as FK tables s_diag = np.zeros((len(s),len(s)), dtype=np.float32) np.fill_diagonal(s_diag, np.diag(s)) - df = pd.DataFrame(s_diag, index=groups_index, columns=groups_index) + df = pd.DataFrame(s_diag, index=procs_index, columns=procs_index) return df -groups_results_theory = collect('groups_results', ('theoryids',)) +procs_results_theory = collect('procs_results', ('theoryids',)) @check_correct_theory_combination -def total_covmat_groups(groups_results_theory, +def total_covmat_procs(procs_results_theory, fivetheories:(str, type(None)) = None): """Same as total_covmat_datasets but per experiment rather than per dataset. Needed for calculation of chi2 per experiment.""" - group_result_covmats = [] - for group_result in zip(*groups_results_theory): - theory_centrals = [x[1].central_value for x in group_result] + proc_result_covmats = [] + for proc_result in zip(*procs_results_theory): + theory_centrals = [x[1].central_value for x in proc_result] s = make_scale_var_covmat(theory_centrals) - sigma = group_result[0][0].covmat + sigma = proc_result[0][0].covmat cov = s + sigma - group_result_covmats.append(cov) - return group_result_covmats + proc_result_covmats.append(cov) + return proc_result_covmats -commondata_groups = collect('commondata', ['group_dataset_inputs_by_metadata', 'data']) +commondata_procs = collect('commondata', ['force_process_grouping', 'data']) -def dataset_names(commondata_groups): +def dataset_names(commondata_procs): """Returns a list of the names of the datasets, in the same order as they are inputted in the runcard""" - names = [commondata.name for commondata in commondata_groups] + names = [commondata.name for commondata in commondata_procs] return names ProcessInfo = namedtuple("ProcessInfo", ('theory', 'namelist', 'sizes')) @@ -363,7 +363,7 @@ def covs_pt_prescrip(combine_by_type, process_starting_points, theoryids, return covmats @table -def theory_covmat_custom(covs_pt_prescrip, covmap, groups_index): +def theory_covmat_custom(covs_pt_prescrip, covmap, procs_index): """Takes the individual sub-covmats between each two processes and assembles them into a full covmat. Then reshuffles the order from ordering by process to ordering by experiment as listed in the runcard""" @@ -378,17 +378,17 @@ def theory_covmat_custom(covs_pt_prescrip, covmap, groups_index): for i in range(matlength): for j in range(matlength): cov_by_exp[covmap[i]][covmap[j]] = mat[i][j] - df = pd.DataFrame(cov_by_exp, index=groups_index, - columns=groups_index) + df = pd.DataFrame(cov_by_exp, index=procs_index, + columns=procs_index) return df @check_correct_theory_combination -def total_covmat_diagtheory_groups(groups_results_theory, +def total_covmat_diagtheory_procs(procs_results_theory, fivetheories:(str, type(None)) = None): - """Same as total_covmat_datasets but per group rather than - per dataset. Needed for calculation of chi2 per group.""" + """Same as total_covmat_datasets but per proc rather than + per dataset. Needed for calculation of chi2 per proc.""" exp_result_covmats = [] - for exp_result in zip(*groups_results_theory): + for exp_result in zip(*procs_results_theory): theory_centrals = [x[1].central_value for x in exp_result] s = make_scale_var_covmat(theory_centrals) # Initialise array of zeros and set precision to same as FK tables @@ -423,131 +423,131 @@ def theory_corrmat_custom(theory_covmat_custom): return mat @table -def theory_normcovmat_singleprocess(theory_covmat_singleprocess, groups_data_values): +def theory_normcovmat_singleprocess(theory_covmat_singleprocess, procs_data_values): """Calculates the theory covariance matrix for scale variations normalised to data.""" df = theory_covmat_singleprocess - mat = df/np.outer(groups_data_values, groups_data_values) + mat = df/np.outer(procs_data_values, procs_data_values) return mat @table -def theory_normblockcovmat(theory_block_diag_covmat, groups_data_values): +def theory_normblockcovmat(theory_block_diag_covmat, procs_data_values): """Calculates the theory covariance matrix for scale variations normalised to data, block diagonal by dataset.""" df = theory_block_diag_covmat - mat = df/np.outer(groups_data_values, groups_data_values) + mat = df/np.outer(procs_data_values, procs_data_values) return mat @table -def theory_normcovmat_custom(theory_covmat_custom, groups_data_values): +def theory_normcovmat_custom(theory_covmat_custom, procs_data_values): """Calculates the theory covariance matrix for scale variations normalised to data, with variations according to the relevant prescription.""" df = theory_covmat_custom - mat = df/np.outer(groups_data_values, groups_data_values) + mat = df/np.outer(procs_data_values, procs_data_values) return mat @table -def experimentplustheory_covmat_singleprocess(groups_covmat_no_table, +def experimentplustheory_covmat_singleprocess(procs_covmat_no_table, theory_covmat_singleprocess_no_table): """Calculates the experiment + theory covariance matrix for scale variations.""" - df = groups_covmat_no_table + theory_covmat_singleprocess_no_table + df = procs_covmat_no_table + theory_covmat_singleprocess_no_table return df @table -def experimentplusblocktheory_covmat(groups_covmat, +def experimentplusblocktheory_covmat(procs_covmat, theory_block_diag_covmat): """Calculates the experiment + theory covariance matrix for scale variations.""" - df = groups_covmat + theory_block_diag_covmat + df = procs_covmat + theory_block_diag_covmat return df @table -def experimentplustheory_covmat_custom(groups_covmat, +def experimentplustheory_covmat_custom(procs_covmat, theory_covmat_custom): """Calculates the experiment + theory covariance matrix for scale variations correlated according to the relevant prescription.""" - df = groups_covmat + theory_covmat_custom + df = procs_covmat + theory_covmat_custom return df @table -def experimentplustheory_normcovmat_singleprocess(groups_covmat, +def experimentplustheory_normcovmat_singleprocess(procs_covmat, theory_covmat_singleprocess, - groups_data): + procs_data): """Calculates the experiment + theory covariance matrix for scale variations normalised to data.""" - df = groups_covmat + theory_covmat_singleprocess - groups_data_array = np.array(groups_data) - mat = df/np.outer(groups_data_array, groups_data_array) + df = procs_covmat + theory_covmat_singleprocess + procs_data_array = np.array(procs_data) + mat = df/np.outer(procs_data_array, procs_data_array) return mat @table -def experimentplusblocktheory_normcovmat(groups_covmat, +def experimentplusblocktheory_normcovmat(procs_covmat, theory_block_diag_covmat, - groups_data_values, + procs_data_values, experimentplustheory_normcovmat): """Calculates the experiment + theory covariance matrix for scale variations normalised to data, block diagonal by data set.""" - mat = experimentplustheory_normcovmat(groups_covmat, + mat = experimentplustheory_normcovmat(procs_covmat, theory_block_diag_covmat, - groups_data_values) + procs_data_values) return mat @table -def experimentplustheory_normcovmat_custom(groups_covmat, +def experimentplustheory_normcovmat_custom(procs_covmat, theory_covmat_custom, - groups_data_values, + procs_data_values, experimentplustheory_normcovmat): """Calculates the experiment + theory covariance matrix for scale variations normalised to data, correlations by process type.""" - mat = experimentplustheory_normcovmat(groups_covmat, + mat = experimentplustheory_normcovmat(procs_covmat, theory_covmat_custom, - groups_data_values) + procs_data_values) return mat @table -def experimentplustheory_corrmat_singleprocess(groups_covmat, +def experimentplustheory_corrmat_singleprocess(procs_covmat, theory_covmat_singleprocess): """Calculates the correlation matrix for the experimental plus theory covariance matrices.""" - total_df = groups_covmat + theory_covmat_singleprocess - total_cov = (groups_covmat + theory_covmat_singleprocess).values + total_df = procs_covmat + theory_covmat_singleprocess + total_cov = (procs_covmat + theory_covmat_singleprocess).values diag_minus_half = (np.diagonal(total_cov))**(-0.5) corrmat = diag_minus_half[:,np.newaxis]*total_df*diag_minus_half return corrmat @table -def experimentplusblocktheory_corrmat(groups_covmat, +def experimentplusblocktheory_corrmat(procs_covmat, theory_block_diag_covmat): """Calculates the correlation matrix for the experimental plus theory covariance matrices, block diagonal by dataset.""" - corrmat = experimentplustheory_corrmat_singleprocess(groups_covmat, + corrmat = experimentplustheory_corrmat_singleprocess(procs_covmat, theory_block_diag_covmat) return corrmat @table -def experimentplustheory_corrmat_custom(groups_covmat, +def experimentplustheory_corrmat_custom(procs_covmat, theory_covmat_custom): """Calculates the correlation matrix for the experimental plus theory covariance matrices, correlations by prescription.""" - corrmat = experimentplustheory_corrmat_singleprocess(groups_covmat, + corrmat = experimentplustheory_corrmat_singleprocess(procs_covmat, theory_covmat_custom) return corrmat -def chi2_impact(theory_covmat_singleprocess, groups_covmat, groups_results): +def chi2_impact(theory_covmat_singleprocess, procs_covmat, procs_results): """Returns total chi2 including theory cov mat""" - dataresults, theoryresults = zip(*groups_results) + dataresults, theoryresults = zip(*procs_results) dat_central_list = [x.central_value for x in dataresults] th_central_list = [x.central_value for x in theoryresults] dat_central = np.concatenate(dat_central_list) th_central = np.concatenate([x for x in th_central_list]) central_diff = dat_central - th_central - cov = theory_covmat_singleprocess.values + groups_covmat.values + cov = theory_covmat_singleprocess.values + procs_covmat.values return calc_chi2(la.cholesky(cov, lower=True), central_diff)/len(central_diff) -def data_theory_diff(groups_results): +def data_theory_diff(procs_results): """Returns (D-T) for central theory, for use in chi2 calculations""" - dataresults, theoryresults = zip(*groups_results) + dataresults, theoryresults = zip(*procs_results) dat_central_list = [x.central_value for x in dataresults] th_central_list = [x.central_value for x in theoryresults] dat_central = np.concatenate(dat_central_list) @@ -555,19 +555,19 @@ def data_theory_diff(groups_results): central_diff = dat_central - th_central return central_diff -def chi2_block_impact(theory_block_diag_covmat, groups_covmat, - groups_results): +def chi2_block_impact(theory_block_diag_covmat, procs_covmat, + procs_results): """Returns total chi2 including theory cov mat""" - chi2 = chi2_impact(theory_block_diag_covmat, groups_covmat, - groups_results) + chi2 = chi2_impact(theory_block_diag_covmat, procs_covmat, + procs_results) return chi2 -def chi2_impact_custom(theory_covmat_custom, groups_covmat, - groups_results): +def chi2_impact_custom(theory_covmat_custom, procs_covmat, + procs_results): """Returns total chi2 including theory cov mat""" - chi2 = chi2_impact(theory_covmat_custom, groups_covmat, - groups_results) + chi2 = chi2_impact(theory_covmat_custom, procs_covmat, + procs_results) return chi2 def theory_diagcovmat(theory_covmat_singleprocess): @@ -578,14 +578,14 @@ def theory_diagcovmat(theory_covmat_singleprocess): np.fill_diagonal(s_diag, np.diag(s)) return s_diag -def chi2_diag_only(theory_diagcovmat, groups_covmat, data_theory_diff): +def chi2_diag_only(theory_diagcovmat, procs_covmat, data_theory_diff): """Returns total chi2 including only diags of theory cov mat""" - cov = theory_diagcovmat + groups_covmat.values + cov = theory_diagcovmat + procs_covmat.values elements = np.dot(data_theory_diff.T,np.dot(la.inv(cov),data_theory_diff)) chi2 = (1/len(data_theory_diff))*np.sum(elements) return chi2 -each_dataset_results = collect(results, ('group_dataset_inputs_by_metadata', 'data')) +each_dataset_results = collect(results, ('proc_dataset_inputs_by_metadata', 'data')) def abs_chi2_data_theory_dataset(each_dataset_results, total_covmat_datasets): """Returns an array of tuples (member_chi², central_chi², numpoints) @@ -599,10 +599,10 @@ def abs_chi2_data_theory_dataset(each_dataset_results, total_covmat_datasets): central_result, len(data_result))) return chi2data_array -def abs_chi2_data_theory_group(groups_results, total_covmat_groups): - """Like abs_chi2_data_theory_dataset but for groups not datasets""" +def abs_chi2_data_theory_proc(procs_results, total_covmat_procs): + """Like abs_chi2_data_theory_dataset but for procs not datasets""" chi2data_array = [] - for expresults, covmat in zip(groups_results, total_covmat_groups): + for expresults, covmat in zip(procs_results, total_covmat_procs): data_result, th_result = expresults chi2s = all_chi2_theory(expresults, covmat) central_result = central_chi2_theory(expresults, covmat) @@ -610,11 +610,11 @@ def abs_chi2_data_theory_group(groups_results, total_covmat_groups): central_result, len(data_result))) return chi2data_array -def abs_chi2_data_diagtheory_group(groups_results, - total_covmat_diagtheory_groups): +def abs_chi2_data_diagtheory_proc(procs_results, + total_covmat_diagtheory_procs): """For a diagonal theory covmat""" - return abs_chi2_data_theory_group(groups_results, - total_covmat_diagtheory_groups) + return abs_chi2_data_theory_proc(procs_results, + total_covmat_diagtheory_procs) def abs_chi2_data_diagtheory_dataset(each_dataset_results, total_covmat_diagtheory_datasets): diff --git a/validphys2/src/validphys/theorycovariance/output.py b/validphys2/src/validphys/theorycovariance/output.py index fc0f855210..80511adc5f 100644 --- a/validphys2/src/validphys/theorycovariance/output.py +++ b/validphys2/src/validphys/theorycovariance/output.py @@ -18,31 +18,31 @@ from reportengine.table import table from validphys import plotutils -from validphys.results import groups_chi2_table +from validphys.results import procs_chi2_table log = logging.getLogger(__name__) @table -def groups_chi2_table_theory( - groups_data, pdf, abs_chi2_data_theory_group, abs_chi2_data_theory_dataset +def procs_chi2_table_theory( + procs_data, pdf, abs_chi2_data_theory_proc, abs_chi2_data_theory_dataset ): - """Same as groups_chi2_table but including theory covariance matrix""" - return groups_chi2_table( - groups_data, pdf, abs_chi2_data_theory_group, abs_chi2_data_theory_dataset + """Same as procs_chi2_table but including theory covariance matrix""" + return procs_chi2_table( + procs_data, pdf, abs_chi2_data_theory_proc, abs_chi2_data_theory_dataset ) @table -def groups_chi2_table_diagtheory( - groups_data, pdf, abs_chi2_data_diagtheory_group, abs_chi2_data_diagtheory_dataset +def procs_chi2_table_diagtheory( + procs_data, pdf, abs_chi2_data_diagtheory_proc, abs_chi2_data_diagtheory_dataset ): - """Same as groups_chi2_table but including + """Same as procs_chi2_table but including diagonal theory covariance matrix""" - return groups_chi2_table( - groups_data, + return procs_chi2_table( + procs_data, pdf, - abs_chi2_data_diagtheory_group, + abs_chi2_data_diagtheory_proc, abs_chi2_data_diagtheory_dataset, ) @@ -210,19 +210,19 @@ def plot_corrmat_heatmap(corrmat, title): @figure -def plot_normexpcovmat_heatmap(groups_normcovmat): +def plot_normexpcovmat_heatmap(procs_normcovmat): """Matrix plot of the experiment covariance matrix normalised to data.""" fig = plot_covmat_heatmap( - groups_normcovmat, "Experimental Covariance Matrix" + procs_normcovmat, "Experimental Covariance Matrix" ) return fig @figure -def plot_expcorrmat_heatmap(groups_corrmat): +def plot_expcorrmat_heatmap(procs_corrmat): """Matrix plot of the experiment correlation matrix""" fig = plot_corrmat_heatmap( - groups_corrmat, "Experimental Correlation Matrix" + procs_corrmat, "Experimental Correlation Matrix" ) return fig @@ -347,10 +347,10 @@ def plot_expplusthcorrmat_heatmap_custom( @figure -def plot_blockcovdiff_heatmap(theory_block_diag_covmat, groups_covmat): +def plot_blockcovdiff_heatmap(theory_block_diag_covmat, procs_covmat): """Matrix plot (thcov + expcov)/expcov""" - df = (theory_block_diag_covmat.as_matrix() + groups_covmat.values) / np.mean( - groups_covmat.values + df = (theory_block_diag_covmat.as_matrix() + procs_covmat.values) / np.mean( + procs_covmat.values ) fig = plot_covmat_heatmap( df, @@ -363,7 +363,7 @@ def plot_blockcovdiff_heatmap(theory_block_diag_covmat, groups_covmat): @figure def plot_covdiff_heatmap_custom( theory_covmat_custom, - groups_covmat, + procs_covmat, theoryids, fivetheories: (str, type(None)) = None, ): @@ -374,7 +374,7 @@ def plot_covdiff_heatmap_custom( l = r"$\bar{5}$" elif fivetheories == "linear": l = "linear 5" - df = (theory_covmat_custom + groups_covmat) / np.mean(groups_covmat.values) + df = (theory_covmat_custom + procs_covmat) / np.mean(procs_covmat.values) fig = plot_covmat_heatmap( df, "(Theory + experiment)/mean(experiment)" @@ -386,8 +386,8 @@ def plot_covdiff_heatmap_custom( @figure def plot_diag_cov_comparison( theory_covmat_custom, - groups_covmat, - groups_data_values, + procs_covmat, + procs_data_values, theoryids, fivetheories: (str, type(None)) = None, ): @@ -398,7 +398,7 @@ def plot_diag_cov_comparison( l = r"$\bar{5}$" elif fivetheories == "linear": l = "linear 5" - data = np.abs(groups_data_values) + data = np.abs(procs_data_values) plot_index = theory_covmat_custom.index sqrtdiags_th = np.sqrt(np.diag(theory_covmat_custom)) / data sqrtdiags_th = pd.DataFrame(sqrtdiags_th.values, index=plot_index) @@ -406,11 +406,11 @@ def plot_diag_cov_comparison( oldindex = sqrtdiags_th.index.tolist() newindex = sorted(oldindex, key=_get_key) sqrtdiags_th = sqrtdiags_th.reindex(newindex) - sqrtdiags_exp = np.sqrt(np.diag(groups_covmat)) / data + sqrtdiags_exp = np.sqrt(np.diag(procs_covmat)) / data sqrtdiags_exp = pd.DataFrame(sqrtdiags_exp.values, index=plot_index) sqrtdiags_exp.sort_index(0, inplace=True) sqrtdiags_exp = sqrtdiags_exp.reindex(newindex) - df_total = theory_covmat_custom + groups_covmat + df_total = theory_covmat_custom + procs_covmat sqrtdiags_tot = np.sqrt(np.diag(df_total)) / data sqrtdiags_tot = pd.DataFrame(sqrtdiags_tot.values, index=plot_index) sqrtdiags_tot.sort_index(0, inplace=True) @@ -440,8 +440,8 @@ def plot_diag_cov_comparison( @figure def plot_diag_cov_impact( theory_covmat_custom, - groups_covmat, - groups_data_values, + procs_covmat, + procs_data_values, theoryids, fivetheories: (str, type(None)) = None, ): @@ -453,11 +453,11 @@ def plot_diag_cov_impact( elif fivetheories == "linear": l = "linear 5" matrix_theory = theory_covmat_custom.values - matrix_experiment = groups_covmat.values - inv_exp = (np.diag(la.inv(matrix_experiment))) ** (-0.5) / groups_data_values + matrix_experiment = procs_covmat.values + inv_exp = (np.diag(la.inv(matrix_experiment))) ** (-0.5) / procs_data_values inv_tot = (np.diag(la.inv(matrix_theory + matrix_experiment))) ** ( -0.5 - ) / groups_data_values + ) / procs_data_values plot_index = theory_covmat_custom.index df_inv_exp = pd.DataFrame(inv_exp, index=plot_index) df_inv_exp.sort_index(0, inplace=True) @@ -486,7 +486,7 @@ def plot_diag_cov_impact( @figure def plot_datasets_chi2_theory( - groups_data, each_dataset_chi2, abs_chi2_data_theory_dataset + procs_data, each_dataset_chi2, abs_chi2_data_theory_dataset ): """Plot the chi² of all datasets, before and after adding theory errors, with bars.""" ds = iter(each_dataset_chi2) @@ -494,12 +494,12 @@ def plot_datasets_chi2_theory( dschi2 = [] dschi2theory = [] xticks = [] - for group in groups_data: - for dataset, dsres in zip(group, ds): + for proc in procs_data: + for dataset, dsres in zip(proc, ds): dschi2.append(dsres.central_result / dsres.ndata) xticks.append(dataset.name) - for group in groups_data: - for dataset, dsres in zip(group, dstheory): + for proc in procs_data: + for dataset, dsres in zip(proc, dstheory): dschi2theory.append(dsres.central_result / dsres.ndata) plotvalues = np.stack((dschi2theory, dschi2)) fig, ax = plotutils.barplot( From ce0404090421b21f12172596f74d1da59bfe634f Mon Sep 17 00:00:00 2001 From: RosalynLP Date: Tue, 9 Mar 2021 11:04:43 +0000 Subject: [PATCH 06/11] fix bugs --- validphys2/src/validphys/results.py | 4 ++-- .../src/validphys/theorycovariance/construction.py | 2 +- validphys2/src/validphys/theorycovariance/output.py | 13 +++++++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/validphys2/src/validphys/results.py b/validphys2/src/validphys/results.py index 88028a7ec7..609e9c7c49 100644 --- a/validphys2/src/validphys/results.py +++ b/validphys2/src/validphys/results.py @@ -1285,12 +1285,12 @@ def groups_central_values(group_result_table): central_theory_values = group_result_table["theory_central"] return central_theory_values -def procs_central_values_no_table(proc_result_table): +def procs_central_values_no_table(proc_result_table_no_table): central_theory_values = proc_result_table_no_table["theory_central"] return central_theory_values @table -def procs_central_values(proc_result_table): +def procs_central_values(procs_central_values_no_table): return procs_central_values_no_table dataspecs_each_dataset_chi2 = collect("each_dataset_chi2", ("dataspecs",)) diff --git a/validphys2/src/validphys/theorycovariance/construction.py b/validphys2/src/validphys/theorycovariance/construction.py index 65c8c30a82..8f6e248282 100644 --- a/validphys2/src/validphys/theorycovariance/construction.py +++ b/validphys2/src/validphys/theorycovariance/construction.py @@ -585,7 +585,7 @@ def chi2_diag_only(theory_diagcovmat, procs_covmat, data_theory_diff): chi2 = (1/len(data_theory_diff))*np.sum(elements) return chi2 -each_dataset_results = collect(results, ('proc_dataset_inputs_by_metadata', 'data')) +each_dataset_results = collect(results, ('force_process_grouping', 'data')) def abs_chi2_data_theory_dataset(each_dataset_results, total_covmat_datasets): """Returns an array of tuples (member_chi², central_chi², numpoints) diff --git a/validphys2/src/validphys/theorycovariance/output.py b/validphys2/src/validphys/theorycovariance/output.py index 80511adc5f..4610678a89 100644 --- a/validphys2/src/validphys/theorycovariance/output.py +++ b/validphys2/src/validphys/theorycovariance/output.py @@ -18,7 +18,7 @@ from reportengine.table import table from validphys import plotutils -from validphys.results import procs_chi2_table +from validphys.results import groups_chi2_table log = logging.getLogger(__name__) @@ -27,8 +27,9 @@ def procs_chi2_table_theory( procs_data, pdf, abs_chi2_data_theory_proc, abs_chi2_data_theory_dataset ): - """Same as procs_chi2_table but including theory covariance matrix""" - return procs_chi2_table( + """Same as groups_chi2_table but including theory covariance matrix. + Note: we use groups_chi2_table here but provide data grouped by process.""" + return groups_chi2_table( procs_data, pdf, abs_chi2_data_theory_proc, abs_chi2_data_theory_dataset ) @@ -37,9 +38,9 @@ def procs_chi2_table_theory( def procs_chi2_table_diagtheory( procs_data, pdf, abs_chi2_data_diagtheory_proc, abs_chi2_data_diagtheory_dataset ): - """Same as procs_chi2_table but including - diagonal theory covariance matrix""" - return procs_chi2_table( + """Same as groups_chi2_table but including diagonal theory covariance matrix. + Note: we use groups_chi2_table here but provide data grouped by process.""" + return groups_chi2_table( procs_data, pdf, abs_chi2_data_diagtheory_proc, From e556fee9a29ee918bf50f7b27462682d526749cd Mon Sep 17 00:00:00 2001 From: RosalynLP Date: Tue, 9 Mar 2021 11:13:09 +0000 Subject: [PATCH 07/11] update action name in template --- .../examples/theory_covariance/template_matrix_plots.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/validphys2/examples/theory_covariance/template_matrix_plots.md b/validphys2/examples/theory_covariance/template_matrix_plots.md index 671074e3e7..8e200fb46f 100644 --- a/validphys2/examples/theory_covariance/template_matrix_plots.md +++ b/validphys2/examples/theory_covariance/template_matrix_plots.md @@ -30,11 +30,11 @@ Total (exp. + th.) $\chi^2$ Experimental $\chi^2$ by dataset -------------------------------- - {@groups_chi2_table@} + {@procs_chi2_table@} Total (exp. + th.) $\chi^2$ by dataset -------------------------------------- - {@groups_chi2_table_theory@} + {@procs_chi2_table_theory@} $\chi^2$ including only diagonal theory elements ------------------------------------------------ From 083b49150c41774d753b92d0a04ed9365e5feae3 Mon Sep 17 00:00:00 2001 From: RosalynLP Date: Tue, 9 Mar 2021 11:14:33 +0000 Subject: [PATCH 08/11] remove metadata_process in runcard --- .../examples/theory_covariance/covariance_matrix_plots.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/validphys2/examples/theory_covariance/covariance_matrix_plots.yaml b/validphys2/examples/theory_covariance/covariance_matrix_plots.yaml index 772d95c2f4..fe5f32b32d 100644 --- a/validphys2/examples/theory_covariance/covariance_matrix_plots.yaml +++ b/validphys2/examples/theory_covariance/covariance_matrix_plots.yaml @@ -3,8 +3,6 @@ meta: keywords: [theory uncertainties, 3-point] title: NLO 3-point variations for 5 process types - DIS CC, DIS NC, DY, Top, Jets -metadata_group: nnpdf31_process - default_theory: - theoryid: 163 From 5da329e5a865cd5e18ed1e0c15ea846d0ceee712 Mon Sep 17 00:00:00 2001 From: RosalynLP Date: Tue, 9 Mar 2021 11:26:35 +0000 Subject: [PATCH 09/11] fix proc table --- validphys2/src/validphys/results.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/validphys2/src/validphys/results.py b/validphys2/src/validphys/results.py index 609e9c7c49..6b753ad8dd 100644 --- a/validphys2/src/validphys/results.py +++ b/validphys2/src/validphys/results.py @@ -827,14 +827,14 @@ def groups_chi2_table(groups_data, pdf, groups_chi2, each_dataset_chi2): return pd.DataFrame(records) +@table +def procs_chi2_table(procs_data, pdf, procs_chi2, each_dataset_chi2): + return groups_chi2_table(procs_data, pdf, procs_chi2, each_dataset_chi2) + experiments_chi2_table = collect( "groups_chi2_table", ("group_dataset_inputs_by_experiment",) ) -procs_chi2_table = collect( - "groups_chi2_table", ("force_process_grouping",) -) - @check_cuts_considered @table def closure_shifts(experiments_index, fit, use_cuts, experiments): @@ -953,6 +953,9 @@ def dataset_chi2_table(chi2_stats, dataset): "dataset_inputs_abs_chi2_data", ("group_dataset_inputs_by_metadata",) ) +procs_chi2 = collect("dataset_inputs_abs_chi2_data", ("force_process_grouping",) +) + fits_groups_chi2_data = collect("groups_chi2", ("fits", "fitcontext")) fits_groups = collect("groups_data", ("fits", "fitcontext",)) From cee2829783831ae49a493ee31de8240406ed5a6c Mon Sep 17 00:00:00 2001 From: RosalynLP Date: Wed, 10 Mar 2021 10:38:50 +0000 Subject: [PATCH 10/11] change name to by_process --- validphys2/src/validphys/config.py | 2 +- validphys2/src/validphys/results.py | 6 +++--- validphys2/src/validphys/theorycovariance/construction.py | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/validphys2/src/validphys/config.py b/validphys2/src/validphys/config.py index 56598fcd5c..0db766e5d3 100644 --- a/validphys2/src/validphys/config.py +++ b/validphys2/src/validphys/config.py @@ -1358,7 +1358,7 @@ def produce_group_dataset_inputs_by_metadata( def produce_group_dataset_inputs_by_experiment(self, data_input): return self.produce_group_dataset_inputs_by_metadata(data_input, "experiment") - def produce_force_process_grouping(self, data_input): + def produce_group_dataset_inputs_by_process(self, data_input): return self.produce_group_dataset_inputs_by_metadata(data_input, "nnpdf31_process") def produce_scale_variation_theories(self, theoryid, point_prescription): diff --git a/validphys2/src/validphys/results.py b/validphys2/src/validphys/results.py index 6b753ad8dd..25121d689b 100644 --- a/validphys2/src/validphys/results.py +++ b/validphys2/src/validphys/results.py @@ -154,7 +154,7 @@ def rawdata(self): experiments_data = collect("data", ("group_dataset_inputs_by_experiment",)) -procs_data = collect("data", ("force_process_grouping",)) +procs_data = collect("data", ("group_dataset_inputs_by_process",)) def groups_index(groups_data): """Return a pandas.MultiIndex with levels for group, dataset and point @@ -212,7 +212,7 @@ def procs_data_values(proc_result_table): ) procs_results = collect( - "dataset_inputs_results", ("force_process_grouping",) + "dataset_inputs_results", ("group_dataset_inputs_by_process",) ) def group_result_table_no_table(groups_results, groups_index): @@ -953,7 +953,7 @@ def dataset_chi2_table(chi2_stats, dataset): "dataset_inputs_abs_chi2_data", ("group_dataset_inputs_by_metadata",) ) -procs_chi2 = collect("dataset_inputs_abs_chi2_data", ("force_process_grouping",) +procs_chi2 = collect("dataset_inputs_abs_chi2_data", ("group_dataset_inputs_by_process",) ) fits_groups_chi2_data = collect("groups_chi2", ("fits", "fitcontext")) diff --git a/validphys2/src/validphys/theorycovariance/construction.py b/validphys2/src/validphys/theorycovariance/construction.py index 8f6e248282..a9ad01cfe7 100644 --- a/validphys2/src/validphys/theorycovariance/construction.py +++ b/validphys2/src/validphys/theorycovariance/construction.py @@ -70,7 +70,7 @@ def theory_covmat_singleprocess(theory_covmat_singleprocess_no_table, results_bytheoryids = collect(results,('theoryids',)) each_dataset_results_bytheory = collect('results_bytheoryids', - ('force_process_grouping','data')) + ('group_dataset_inputs_by_process','data')) @check_correct_theory_combination def theory_covmat_datasets(each_dataset_results_bytheory, @@ -151,7 +151,7 @@ def total_covmat_procs(procs_results_theory, proc_result_covmats.append(cov) return proc_result_covmats -commondata_procs = collect('commondata', ['force_process_grouping', 'data']) +commondata_procs = collect('commondata', ['group_dataset_inputs_by_process', 'data']) def dataset_names(commondata_procs): """Returns a list of the names of the datasets, in the same order as @@ -585,7 +585,7 @@ def chi2_diag_only(theory_diagcovmat, procs_covmat, data_theory_diff): chi2 = (1/len(data_theory_diff))*np.sum(elements) return chi2 -each_dataset_results = collect(results, ('force_process_grouping', 'data')) +each_dataset_results = collect(results, ('group_dataset_inputs_by_process', 'data')) def abs_chi2_data_theory_dataset(each_dataset_results, total_covmat_datasets): """Returns an array of tuples (member_chi², central_chi², numpoints) From fd84f50db0bb04d4c774bacb182379e9d98deaee Mon Sep 17 00:00:00 2001 From: RosalynLP Date: Wed, 10 Mar 2021 10:40:27 +0000 Subject: [PATCH 11/11] review comments --- validphys2/src/validphys/theorycovariance/construction.py | 4 ++-- validphys2/src/validphys/theorycovariance/output.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/validphys2/src/validphys/theorycovariance/construction.py b/validphys2/src/validphys/theorycovariance/construction.py index a9ad01cfe7..b2636c52d1 100644 --- a/validphys2/src/validphys/theorycovariance/construction.py +++ b/validphys2/src/validphys/theorycovariance/construction.py @@ -52,8 +52,8 @@ def make_scale_var_covmat(predictions): @check_correct_theory_combination def theory_covmat_singleprocess_no_table(theoryids_procs_central_values_no_table, - procs_index, theoryids, - fivetheories:(str, type(None)) = None): + procs_index, theoryids, + fivetheories:(str, type(None)) = None): """Calculates the theory covariance matrix for scale variations. The matrix is a dataframe indexed by procs_index.""" diff --git a/validphys2/src/validphys/theorycovariance/output.py b/validphys2/src/validphys/theorycovariance/output.py index 4610678a89..b2765febac 100644 --- a/validphys2/src/validphys/theorycovariance/output.py +++ b/validphys2/src/validphys/theorycovariance/output.py @@ -180,7 +180,6 @@ def _get_key(element): return newelement -@figure def plot_corrmat_heatmap(corrmat, title): """Matrix plot of a correlation matrix""" df = corrmat