def create_gaussian_prior_for(parameter, mean, std): """ Use for informed variables. The Gaussian prior weights by a Gaussian in the parameter. If you would like the logarithm of the parameter to be weighted by a Gaussian, create a ancillary parameter (see create_jeffreys_prior_for). :param parameter: Parameter to create a prior for. E.g. xspowerlaw.mypowerlaw.PhoIndex """ import invgauss lo = parameter.min hi = parameter.max f = invgauss.get_invgauss_func(mean, std) return lambda x: min(lo, max(hi, f(x)))
def create_gaussian_prior_for(parameter, mean, std): """ Use for informed variables. The Gaussian prior weights by a Gaussian in the parameter. If you would like the logarithm of the parameter to be weighted by a Gaussian, create a ancillary parameter (see create_jeffreys_prior_for). :param parameter: Parameter to create a prior for. E.g. xspowerlaw.mypowerlaw.PhoIndex """ import invgauss lo = parameter.min hi = parameter.max f = invgauss.get_invgauss_func(mean, std) return lambda x: max(lo, min(hi, f(x)))
# creating ancillary parameters for logarithmic treatment print 'creating prior functions...' from sherpa.models.parameter import Parameter srclevel = Parameter('src', 'level', numpy.log10(src.norm.val), -8, -1, -8, -1) srcnh = Parameter('src', 'nh', numpy.log10(abso.nH.val) + 22, 19, 24, 19, 24) galnh = Parameter('gal', 'nh', numpy.log10(galabso.nH.val) + 22, 19, 24, 19, 24) src.norm = 10**srclevel abso.nH = 10**(srcnh - 22) galabso.nH = 10**(galnh - 22) # example of a custom prior import invgauss f = invgauss.get_invgauss_func(numpy.log10(props['nhgal']), 0.15) def limited_19_24(x): v = f(x) if v <= 19: v = 19 if v >= 24: v = 24 return v priors = [] parameters = [srclevel, src.PhoIndex, srcnh, galnh] import bxa.sherpa as bxa
galabso.nH.val = props['nhgal'] / 1e22 # creating ancillary parameters for logarithmic treatment print('creating prior functions...') from sherpa.models.parameter import Parameter srclevel = Parameter('src', 'level', numpy.log10(src.norm.val), -8, -1, -8, -1) srcnh = Parameter('src', 'nh', numpy.log10(abso.nH.val)+22, 19, 24, 19, 24) galnh = Parameter('gal', 'nh', numpy.log10(galabso.nH.val)+22, 19, 24, 19, 24) src.norm = 10**srclevel abso.nH = 10**(srcnh - 22) galabso.nH = 10**(galnh - 22) # example of a custom prior import invgauss f = invgauss.get_invgauss_func(numpy.log10(props['nhgal']), 0.15) def limited_19_24(x): v = f(x) if v <= 19: v = 19 if v >= 24: v = 24 return v priors = [] parameters = [srclevel, src.PhoIndex, srcnh, galnh] import bxa.sherpa as bxa priors += [bxa.create_uniform_prior_for(srclevel)] priors += [bxa.create_uniform_prior_for(src.PhoIndex)]