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_mcmc_params_error(capsys):
output = mc3.sample(data=data, uncert=uncert, func=quad, sampler=sampler,
indparams=[x], pstep=pstep, nsamples=1e4, burnin=100)
captured = capsys.readouterr()
assert output is None
assert "'params' is a required argument" in captured.out
def test_mcmc_deprecation_parname(capsys):
output = mc3.sample(data, uncert, func=quad, params=np.copy(params),
sampler=sampler, indparams=[x], pstep=pstep,
nsamples=1e3, burnin=2, parname=pnames)
captured = capsys.readouterr()
assert output is not None
assert "parname argument is deprecated. Use pnames instead." \
in captured.out
def test_mcmc_deprecation_chireturn(capsys):
output = mc3.sample(data, uncert, func=quad, params=np.copy(params),
sampler=sampler, indparams=[x], stepsize=pstep,
nsamples=1e3, burnin=2, ncpu=7, chireturn=True)
captured = capsys.readouterr()
assert output is not None
assert "chireturn argument is deprecated." in captured.out
def test_mcmc_gr(capsys):
output = mc3.sample(data, uncert, func=quad, params=np.copy(params),
sampler=sampler, indparams=[x],
pstep=pstep, nsamples=1e4, burnin=100,
grtest=True)
captured = capsys.readouterr()
assert output is not None
assert "Gelman-Rubin statistics for free parameters:" in captured.out
def test_mcmc_deprecation_leastsq(capsys, lm, leastsq):
if leastsq is True and lm is False:
ls = 'trf'
elif leastsq in [True, 'lm']:
ls = 'lm'
else:
ls = None
output = mc3.sample(data, uncert, func=quad, params=np.copy(params),
sampler=sampler, indparams=[x], stepsize=pstep,
nsamples=1e3, burnin=2, ncpu=7, leastsq=leastsq, lm=lm)
captured = capsys.readouterr()
assert output is not None
if isinstance(leastsq, bool):
assert "leastsq as boolean is deprecated. See docs for new usage. " \
"Set\nleastsq={}".format(repr(ls)) in captured.out
if isinstance(lm, bool):
assert "lm argument is deprecated. See new usage of leastsq. " \
"Set\nleastsq={}".format(repr(ls)) in captured.out
def test_mcmc_pnames(capsys):
output = mc3.sample(data, uncert, func=quad, params=np.copy(params),
sampler=sampler, indparams=[x],
pstep=pstep, nsamples=1e4, burnin=100,
pnames=pnames)
captured = capsys.readouterr()
assert output is not None
assert "constant" in captured.out
assert "linear" in captured.out
assert "quadratic" in captured.out
def test_mcmc_gr_break_iterations(capsys):
output = mc3.sample(data, uncert, func=quad, params=np.copy(params),
sampler=sampler, indparams=[x],
pstep=pstep, nsamples=1e4, burnin=100,
grtest=True, grbreak=1.1, grnmin=5000.0)
captured = capsys.readouterr()
assert output is not None
assert "All parameters satisfy the GR convergence threshold of 1.1" \
in captured.out
def test_dynesty_priors_gauss():
prior = np.array([ 4.5, 0.0, 0.0])
priorlow = np.array([ 0.1, 0.0, 0.0])
priorup = np.array([ 0.1, 0.0, 0.0])
output = mc3.sample(data, uncert, func=quad, params=np.copy(params),
sampler=sampler, indparams=[x], pmin=pmin, pmax=pmax,
pstep=pstep, maxiter=5000,
prior=prior, priorlow=priorlow, priorup=priorup)
assert output is not None
assert -2*output['best_log_post'] > output['best_chisq']
assert np.all(-2*output['log_post'] > output['chisq'])
def test_mcmc_pnames_texnames(capsys):
output = mc3.sample(data, uncert, func=quad, params=np.copy(params),
sampler=sampler, indparams=[x],
pstep=pstep, nsamples=1e4, burnin=100,
pnames=pnames, texnames=texnames)
captured = capsys.readouterr()
assert output is not None
assert "constant" in captured.out
assert "linear" in captured.out
assert "quadratic" in captured.out
grbreak = 1.01
grnmin = 0.5
# Logging:
log = 'MCMC_tutorial.log'
# File outputs:
savefile = 'MCMC_tutorial.npz'
plots = True
rms = True
# Carter & Winn (2009) Wavelet-likelihood method:
wlike = False
# Run the MCMC:
mc3_output = mc3.sample(data=data, uncert=uncert, func=func, params=params,
indparams=indparams, pmin=pmin, pmax=pmax, pstep=pstep,
pnames=pnames, texnames=texnames,
prior=prior, priorlow=priorlow, priorup=priorup,
sampler=sampler, nsamples=nsamples, nchains=nchains,
ncpu=ncpu, burnin=burnin, thinning=thinning,
leastsq=leastsq, chisqscale=chisqscale,
grtest=grtest, grbreak=grbreak, grnmin=grnmin,
hsize=hsize, kickoff=kickoff,
wlike=wlike, log=log,
plots=plots, savefile=savefile, rms=rms)