88import numpy as np
99import pandas as pd
1010
11+ from reportengine import collect
12+ from reportengine .table import table
13+
1114from validphys .calcutils import calc_chi2 , bootstrap_values
1215from validphys .checks import check_pdf_is_montecarlo
1316from validphys .closuretest .closure_checks import (
1720 check_fits_same_filterseed ,
1821 check_fits_underlying_law_match ,
1922)
20- from reportengine import collect
21- from reportengine .table import table
2223
2324
2425BiasData = namedtuple ("BiasData" , ("bias" , "ndata" ))
2526
2627underlying_results = collect ("results" , ("fitunderlyinglaw" ,))
2728
29+
2830@check_fit_isclosure
2931@check_use_fitcommondata
30- def bias_dataset (
31- results , underlying_results , fit , use_fitcommondata , sqrt_covariance_matrix
32- ):
32+ def bias_dataset (results , underlying_results , fit , use_fitcommondata ):
3333 """Calculate the bias for a given dataset and fit. The bias is defined as
3434 chi2 between the prediction from the underlying PDF (which was used to
3535 generate the closure pseudodata), also known as level zero closure data, and
@@ -39,11 +39,11 @@ def bias_dataset(
3939 is used to generate the multiplicative contributions to the covariance
4040 matrix
4141 """
42- _ , th_ct = results
42+ dt_ct , th_ct = results
4343 # does collect need to collect a list even with one element?
4444 (_ , th_ul ), = underlying_results
4545 central_diff = th_ct .central_value - th_ul .central_value
46- bias_out = calc_chi2 (sqrt_covariance_matrix , central_diff ) # unnormalised
46+ bias_out = calc_chi2 (dt_ct . sqrtcovmat , central_diff ) # unnormalised
4747 return BiasData (bias_out , len (th_ct ))
4848
4949
@@ -53,20 +53,12 @@ def bias_dataset(
5353@check_fit_isclosure
5454@check_use_fitcommondata
5555def bias_experiment (
56- experiment_results ,
57- underlying_experiment_results ,
58- fit ,
59- use_fitcommondata ,
60- experiment_sqrt_covariance_matrix ,
56+ experiment_results , underlying_experiment_results , fit , use_fitcommondata
6157):
6258 """Like `bias_dataset` but for a whole experiment.
6359 """
6460 return bias_dataset (
65- experiment_results ,
66- underlying_experiment_results ,
67- fit ,
68- use_fitcommondata ,
69- experiment_sqrt_covariance_matrix ,
61+ experiment_results , underlying_experiment_results , fit , use_fitcommondata
7062 )
7163
7264
@@ -177,7 +169,7 @@ def fits_bootstrap_bias_table(
177169
178170@check_fit_isclosure
179171@check_use_fitcommondata
180- def variance_dataset (results , fit , use_fitcommondata , sqrt_covariance_matrix ):
172+ def variance_dataset (results , fit , use_fitcommondata ):
181173 """calculate the variance for a given dataset, which is the spread of
182174 replicas measured in the space of the covariance matrix. Given by:
183175
@@ -188,25 +180,18 @@ def variance_dataset(results, fit, use_fitcommondata, sqrt_covariance_matrix):
188180 be made fully independent of the closure data. This is useful when checking
189181 the variance of data which was not included in the fit.
190182
191- # TODO: here we require that use_fitcommondata is true, for the generic use
192- # case. we require another action which uses explicitly a t0pdf of the
193- # underlying law.
194183 """
195- _ , th = results
184+ dt , th = results
196185 diff = th .central_value [:, np .newaxis ] - th ._rawdata
197- var_unnorm = calc_chi2 (sqrt_covariance_matrix , diff ).mean ()
186+ var_unnorm = calc_chi2 (dt . sqrtcovmat , diff ).mean ()
198187 return VarianceData (var_unnorm , len (th ))
199188
200189
201190@check_fit_isclosure
202191@check_use_fitcommondata
203- def variance_experiment (
204- experiment_results , fit , use_fitcommondata , experiment_sqrt_covariance_matrix
205- ):
192+ def variance_experiment (experiment_results , fit , use_fitcommondata ):
206193 """Like variance_dataset but for a whole experiment"""
207- return variance_dataset (
208- experiment_results , fit , use_fitcommondata , experiment_sqrt_covariance_matrix
209- )
194+ return variance_dataset (experiment_results , fit , use_fitcommondata )
210195
211196
212197def bootstrap_variance_experiment (experiment_results , bootstrap_samples = 500 ):
0 commit comments