Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_run_sampler():
# initialize sampler
myDriver = orbitize.driver.Driver(input_file, 'OFTI',
1, 1.22, 56.95, mass_err=0.08, plx_err=0.26)
s = myDriver.sampler
# change eccentricity prior
myDriver.system.sys_priors[1] = priors.LinearPrior(-2.18, 2.01)
# test num_samples=1
s.run_sampler(0, num_samples=1)
# test to make sure outputs are reasonable
start = time.time()
orbits = s.run_sampler(1000, num_cores=4)
end = time.time()
print()
print("Runtime: "+str(end-start) + " s")
print()
print(orbits[0])
# test that lnlikes being saved are correct
returned_lnlike_test = s.results.lnlike[0]
import numpy as np
import pytest
from scipy.stats import norm as nm
import orbitize.priors as priors
threshold = 1e-1
initialization_inputs = {
priors.GaussianPrior : [1000., 1.],
priors.LogUniformPrior : [1., 2.],
priors.UniformPrior : [0., 1.],
priors.SinPrior : [],
priors.LinearPrior : [-2., 2.]
}
expected_means_mins_maxes = {
priors.GaussianPrior : (1000.,0.,np.inf),
priors.LogUniformPrior : (1/np.log(2),1., 2.),
priors.UniformPrior : (0.5, 0., 1.),
priors.SinPrior : (np.pi/2., 0., np.pi),
priors.LinearPrior : (1./3.,0.,1.0)
}
lnprob_inputs = {
priors.GaussianPrior : np.array([-3.0, np.inf, 1000., 999.]),
priors.LogUniformPrior : np.array([-1., 0., 1., 1.5, 2., 2.5]),
priors.UniformPrior : np.array([0., 0.5, 1., -1., 2.]),
priors.SinPrior : np.array([0., np.pi/2., np.pi, 10., -1.]),
priors.LinearPrior : np.array([0., 0.5, 1., 2., -1.])
def test_run_sampler():
# initialize sampler
myDriver = orbitize.driver.Driver(input_file, 'OFTI',
1, 1.22, 56.95, mass_err=0.08, plx_err=0.26)
s = myDriver.sampler
# change eccentricity prior
myDriver.system.sys_priors[1] = priors.LinearPrior(-2.18, 2.01)
# test num_samples=1
s.run_sampler(0, num_samples=1)
# test to make sure outputs are reasonable
start = time.time()
orbits = s.run_sampler(1000, num_cores=4)
end = time.time()
print()
print("Runtime: "+str(end-start) + " s")
print()
print(orbits[0])
# test that lnlikes being saved are correct
returned_lnlike_test = s.results.lnlike[0]
Returns:
float: prior probability of this set of parameters
"""
logp = 0.
for param, prior in zip(params, priors):
param = np.array([param])
logp += prior.compute_lnprob(param) # retrun a float
return logp
if __name__ == '__main__':
myPrior = LinearPrior(-1., 1.)
mySamples = myPrior.draw_samples(1000)
print(mySamples)
myProbs = myPrior.compute_lnprob(mySamples)
print(myProbs)
myPrior = GaussianPrior(1.3, 0.2)
mySamples = myPrior.draw_samples(1)
print(mySamples)
myProbs = myPrior.compute_lnprob(mySamples)
print(myProbs)