|
GAMBIT
v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
|
Go to the documentation of this file. 3 Convolve chi-squared in a data file with a fractional theory error 4 ================================================================== 6 python convolve_with_theory.py <file> <frac-error> <min> <max> 8 prints (parameter, convolved chi-squared) from a file containing 9 (parameter, chi-squared). 14 from scipy.interpolate import interp1d 15 from scipy.stats import norm, lognorm 16 from scipy.integrate import quad 19 def convolve(file_name, frac_error=0.1, min_=0., max_=1., log_normal=True): 21 Convolve chi-squared in a data file with a fractional theory error 24 file_name (str): Data file with columns (parameter, chi-squared). 25 frac_error (float, optional): Fractional theory error on the parameter. 26 min_ (float, optional): Minimum value of parameter. 27 max_ (float, optional): Maximum value of parameter. 28 log_normal (bool, optional): Whether to use log-normal or normal error. 31 list(tuples): List of (parameter, convolved chi-squared) 34 param, chi_squared = np.loadtxt(file_name, unpack= True) 37 like = interp1d(param, np.exp(-0.5 * chi_squared), 38 kind= 'linear', bounds_error= False, fill_value= "extrapolate") 43 sigma = np.log(1. + frac_error) 44 dist = lognorm(sigma, scale=mu) 46 sigma = frac_error * mu 47 dist = norm(mu, sigma) 51 integrand = lambda x, mu: like(x) * prior(x, mu) 52 convolved = lambda mu: -2. * np.log( 53 quad(integrand, min_, max_, args=(mu))[0] 54 / quad(prior, min_, max_, args=(mu))[0]) 57 return [(p, convolved(p)) for p in param] 59 if __name__ == "__main__": 62 FILE_NAME = sys.argv[1] 64 raise RuntimeError(__doc__) 66 ARGS = map(float, sys.argv[2:]) 68 for p, c in convolve(FILE_NAME, *ARGS): def convolve(file_name, frac_error=0.1, min_=0., max_=1., log_normal=True)
|