def test_priors(): """ Test basic functionality of all Priors """ params = radvel.Parameters(1, 'per tc secosw sesinw logk') params['per1'] = radvel.Parameter(10.0) params['tc1'] = radvel.Parameter(0.0) params['secosw1'] = radvel.Parameter(0.0) params['sesinw1'] = radvel.Parameter(0.0) params['logk1'] = radvel.Parameter(1.5) vector = radvel.Vector(params) testTex = r'Delta Function Prior on $\sqrt{e}\cos{\omega}_{b}$' def userdef_prior_func(inp_list): if inp_list[0] >= 0. and inp_list[0] < 1.: return 0. else: return -np.inf prior_tests = { radvel.prior.EccentricityPrior(1): 1 / .99, radvel.prior.EccentricityPrior([1]): 1 / .99, radvel.prior.PositiveKPrior(1): 1.0, radvel.prior.Gaussian('per1', 9.9, 0.1): scipy.stats.norm(9.9, 0.1).pdf(10.), radvel.prior.HardBounds('per1', 1.0, 9.0): 0., radvel.prior.HardBounds('per1', 1.0, 11.0): 1. / 10., radvel.prior.Jeffreys('per1', 0.1, 100.0): (1. / 10.) / np.log(100. / 0.1), radvel.prior.ModifiedJeffreys('per1', 0.1, 100.0, 0.): (1. / 10.) / np.log(100. / 0.1), radvel.prior.ModifiedJeffreys('per1', 2., 100.0, 1.): (1. / 9.) / np.log(99.), radvel.prior.SecondaryEclipsePrior(1, 5.0, 10.0): 1. / np.sqrt(2. * np.pi), radvel.prior.NumericalPrior(['sesinw1'], np.random.randn(1, 5000000)): scipy.stats.norm(0, 1).pdf(0.), radvel.prior.UserDefinedPrior(['secosw1'], userdef_prior_func, testTex): 1.0, radvel.prior.InformativeBaselinePrior('per1', 5.0, duration=1.0): 6. / 10. } for prior, val in prior_tests.items(): print(prior.__repr__()) print(prior.__str__()) tolerance = .01 print(abs(np.exp(prior(params, vector)))) print(val) assert abs(np.exp(prior(params, vector)) - val) < tolerance, \ "Prior output does not match expectation"
def test_priors(): """ Test basic functionality of all Priors """ params = radvel.Parameters(1) params['per1'] = radvel.Parameter(10.0) params['tc1'] = radvel.Parameter(0.0) params['secosw1'] = radvel.Parameter(0.0) params['sesinw1'] = radvel.Parameter(0.0) params['logk1'] = radvel.Parameter(1.5) testTex = 'Delta Function Prior on $\sqrt{e}\cos{\omega}_{b}$' def userdef_prior_func(inp_list): if inp_list == [0.]: return 0. else: return -np.inf prior_tests = { radvel.prior.EccentricityPrior(1): 0.0, radvel.prior.PositiveKPrior(1): 0.0, radvel.prior.Gaussian('per1', 10.0, 0.1): 0.0, radvel.prior.HardBounds('per1', 1.0, 9.0): -np.inf, radvel.prior.Jeffreys('per1', 0.1, 100.0): -np.log(params['per1'].value), radvel.prior.ModifiedJeffreys('per1', 0.1, 100.0): -np.log(params['per1'].value + 0.1), radvel.prior.SecondaryEclipsePrior(1, 5.0, 1.0): 0.0, radvel.prior.NumericalPrior(['sesinw1'], np.random.randn(1, 5000000)): scipy.stats.norm(0, 1).pdf(0), radvel.prior.UserDefinedPrior(['secosw1'], userdef_prior_func, testTex): 0.0 } for prior, val in prior_tests.items(): print(prior.__repr__()) print(prior.__str__()) tolerance = .01 assert prior(params) == val or abs(prior(params) - val) < tolerance, \ "Prior output does not match expectation"