Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • john-veitch/bilby
  • duncanmmacleod/bilby
  • colm.talbot/bilby
  • lscsoft/bilby
  • matthew-pitkin/bilby
  • salvatore-vitale/tupak
  • charlie.hoy/bilby
  • bfarr/bilby
  • virginia.demilio/bilby
  • vivien/bilby
  • eric-howell/bilby
  • sebastian-khan/bilby
  • rhys.green/bilby
  • moritz.huebner/bilby
  • joseph.mills/bilby
  • scott.coughlin/bilby
  • matthew.carney/bilby
  • hyungwon.lee/bilby
  • monica.rizzo/bilby
  • christopher-berry/bilby
  • lindsay.demarchi/bilby
  • kaushik.rao/bilby
  • charles.kimball/bilby
  • andrew.matas/bilby
  • juan.calderonbustillo/bilby
  • patrick-meyers/bilby
  • hannah.middleton/bilby
  • eve.chase/bilby
  • grant.meadors/bilby
  • khun.phukon/bilby
  • sumeet.kulkarni/bilby
  • daniel.reardon/bilby
  • cjhaster/bilby
  • sylvia.biscoveanu/bilby
  • james-clark/bilby
  • meg.millhouse/bilby
  • joshua.willis/bilby
  • nikhil.sarin/bilby
  • paul.easter/bilby
  • youngmin/bilby
  • daniel-williams/bilby
  • shanika.galaudage/bilby
  • bruce.edelman/bilby
  • avi.vajpeyi/bilby
  • isobel.romero-shaw/bilby
  • andrew.kim/bilby
  • dominika.zieba/bilby
  • jonathan.davies/bilby
  • marc.arene/bilby
  • srishti.tiwari/bilby-tidal-heating-eccentric
  • aditya.vijaykumar/bilby
  • michael.williams/bilby
  • cecilio.garcia-quiros/bilby
  • rory-smith/bilby
  • maite.mateu-lucena/bilby
  • wushichao/bilby
  • kaylee.desoto/bilby
  • brandon.piotrzkowski/bilby
  • rossella.gamba/bilby
  • hunter.gabbard/bilby
  • deep.chatterjee/bilby
  • tathagata.ghosh/bilby
  • arunava.mukherjee/bilby
  • philip.relton/bilby
  • reed.essick/bilby
  • pawan.gupta/bilby
  • francisco.hernandez/bilby
  • rhiannon.udall/bilby
  • leo.tsukada/bilby
  • will-farr/bilby
  • vijay.varma/bilby
  • jeremy.baier/bilby
  • joshua.brandt/bilby
  • ethan.payne/bilby
  • ka-lok.lo/bilby
  • antoni.ramos-buades/bilby
  • oliviastephany.wilk/bilby
  • jack.heinzel/bilby
  • samson.leong/bilby-psi4
  • viviana.caceres/bilby
  • nadia.qutob/bilby
  • michael-coughlin/bilby
  • hemantakumar.phurailatpam/bilby
  • boris.goncharov/bilby
  • sama.al-shammari/bilby
  • siqi.zhong/bilby
  • jocelyn-read/bilby
  • marc.penuliar/bilby
  • stephanie.letourneau/bilby
  • alexandresebastien.goettel/bilby
  • alec.gunny/bilby
  • serguei.ossokine/bilby
  • pratyusava.baral/bilby
  • sophie.hourihane/bilby
  • eunsub/bilby
  • james.hart/bilby
  • pratyusava.baral/bilby-tg
  • zhaozc/bilby
  • pratyusava.baral/bilby_SoG
  • tomasz.baka/bilby
  • nicogerardo.bers/bilby
  • soumen.roy/bilby
  • isaac.mcmahon/healpix-redundancy
  • asamakai.baker/bilby-frequency-dependent-antenna-pattern-functions
  • anna.puecher/bilby
  • pratyusava.baral/bilby-x-g
  • thibeau.wouters/bilby
  • christian.adamcewicz/bilby
  • raffi.enficiaud/bilby
109 results
Show changes
Commits on Source (3)
......@@ -57,6 +57,7 @@ Michael Puerrer
Michael Williams
Monica Rizzo
Moritz Huebner
Nico Gerardo Bers
Nicola De Lillo
Nikhil Sarin
Nirban Bose
......
......@@ -123,6 +123,9 @@ class Dynesty(NestedSampler):
The proposal methods to use during MCMC. This can be some combination
of :code:`"diff", "volumetric"`. See the dynesty guide in the Bilby docs
for more details. default=:code:`["diff"]`.
rstate: numpy.random.Generator (None)
Instance of a numpy random generator for generating random numbers.
Also see :code:`seed` in 'Other Parameters'.
Other Parameters
================
......@@ -143,8 +146,13 @@ class Dynesty(NestedSampler):
has no impact on the sampling.
dlogz: float, (0.1)
Stopping criteria
seed: int (None)
Use to seed the random number generator if :code:`rstate` is not
specified.
"""
sampling_seed_key = "seed"
@property
def _dynesty_init_kwargs(self):
params = inspect.signature(self.sampler_init).parameters
......@@ -176,6 +184,7 @@ class Dynesty(NestedSampler):
def default_kwargs(self):
kwargs = self._dynesty_init_kwargs
kwargs.update(self._dynesty_sampler_kwargs)
kwargs["seed"] = None
return kwargs
def __init__(
......@@ -265,6 +274,14 @@ class Dynesty(NestedSampler):
for equiv in self.npool_equiv_kwargs:
if equiv in kwargs:
kwargs["queue_size"] = kwargs.pop(equiv)
if "seed" in kwargs:
seed = kwargs.get("seed")
if "rstate" not in kwargs:
kwargs["rstate"] = np.random.default_rng(seed)
else:
logger.warning(
"Kwargs contain both 'rstate' and 'seed', ignoring 'seed'."
)
def _verify_kwargs_against_default_kwargs(self):
if not self.kwargs["walks"]:
......@@ -604,6 +621,7 @@ class Dynesty(NestedSampler):
sampling_time_s=self.sampling_time.seconds,
ncores=self.kwargs.get("queue_size", 1),
)
self.kwargs["rstate"] = None
def _update_sampling_time(self):
end_time = datetime.datetime.now()
......
......@@ -607,7 +607,7 @@ class Interferometer(object):
Returns
=======
float: The matched filter signal to noise ratio squared
complex: The matched filter signal to noise ratio
"""
return gwutils.matched_filter_snr(
......
......@@ -37,8 +37,8 @@ new point from the constrained prior. These can be specified using the
iterations of :code:`dynesty`. With this method, :code:`nact=2` often gives good
results, however, in some cases, a larger value may be required.
2. :code:`sample="acceptance-walk"`: with this method, the length of each MCMC
chain is predetermined. The specific length evolves during the run to yield an
2. :code:`sample="acceptance-walk"`: with this method, at each iteration all MCMC chains
are set to the same length. The specific length evolves during the run to yield an
average of :code:`naccept` accepted jumps during each chain. This method is well
suited to parallelised applications, as each MCMC chain will run for the same
amount of time. The value of :code:`naccept` should be tuned based on the
......
......@@ -7,6 +7,7 @@ import numpy as np
import parameterized
from bilby.core.sampler import dynesty_utils
from scipy.stats import gamma, ks_1samp, uniform, powerlaw
import shutil
@define
......@@ -271,5 +272,78 @@ class TestEstimateNMCMC(unittest.TestCase):
self.assertAlmostEqual(estimated, expected)
class TestReproducibility(unittest.TestCase):
@staticmethod
def model(x, m, c):
return m * x + c
def setUp(self):
bilby.core.utils.random.seed(42)
bilby.core.utils.command_line_args.bilby_test_mode = False
rng = bilby.core.utils.random.rng
self.x = np.linspace(0, 1, 11)
self.injection_parameters = dict(m=0.5, c=0.2)
self.sigma = 0.1
self.y = self.model(self.x, **self.injection_parameters) + rng.normal(
0, self.sigma, len(self.x)
)
self.likelihood = bilby.likelihood.GaussianLikelihood(
self.x, self.y, self.model, self.sigma
)
self.priors = bilby.core.prior.PriorDict()
self.priors["m"] = bilby.core.prior.Uniform(0, 5, boundary="periodic")
self.priors["c"] = bilby.core.prior.Uniform(-2, 2, boundary="reflective")
# Evaluate prior once to ensure normalization constant have been set
theta = self.priors.sample()
self.priors.ln_prob(theta)
self._remove_tree()
bilby.core.utils.check_directory_exists_and_if_not_mkdir("outdir")
def tearDown(self):
del self.likelihood
del self.priors
bilby.core.utils.command_line_args.bilby_test_mode = False
self._remove_tree()
def _remove_tree(self):
try:
shutil.rmtree("outdir")
except OSError:
pass
def _run_sampler(self, **kwargs):
bilby.core.utils.random.seed(42)
return bilby.run_sampler(
likelihood=self.likelihood,
priors=self.priors,
sampler="dynesty",
save=False,
resume=False,
dlogz=1.0,
nlive=20,
**kwargs,
)
def test_reproducibility_seed(self):
res0 = self._run_sampler(seed=1234)
res1 = self._run_sampler(seed=1234)
assert res0.log_evidence == res1.log_evidence
def test_reproducibility_state(self):
rstate = np.random.default_rng(1234)
res0 = self._run_sampler(rstate=rstate)
rstate = np.random.default_rng(1234)
res1 = self._run_sampler(rstate=rstate)
assert res0.log_evidence == res1.log_evidence
def test_reproducibility_state_and_seed(self):
rstate = np.random.default_rng(1234)
res0 = self._run_sampler(rstate=rstate)
res1 = self._run_sampler(seed=1234)
assert res0.log_evidence == res1.log_evidence
if __name__ == "__main__":
unittest.main()