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 (27)
Showing
with 91 additions and 22 deletions
...@@ -3,3 +3,4 @@ omit = ...@@ -3,3 +3,4 @@ omit =
test/integration/example_test.py test/integration/example_test.py
test/integration/noise_realisation_test.py test/integration/noise_realisation_test.py
test/integration/other_test.py test/integration/other_test.py
bilby/_version.py
...@@ -15,3 +15,4 @@ MANIFEST ...@@ -15,3 +15,4 @@ MANIFEST
*.ipynb_checkpoints *.ipynb_checkpoints
outdir/* outdir/*
.idea/* .idea/*
bilby/_version.py
...@@ -24,6 +24,7 @@ Eric Thrane ...@@ -24,6 +24,7 @@ Eric Thrane
Ethan Payne Ethan Payne
Francisco Javier Hernandez Francisco Javier Hernandez
Gregory Ashton Gregory Ashton
Hank Hua
Hector Estelles Hector Estelles
Ignacio Magaña Hernandez Ignacio Magaña Hernandez
Isobel Marguarethe Romero-Shaw Isobel Marguarethe Romero-Shaw
...@@ -34,6 +35,7 @@ Jeremy G Baier ...@@ -34,6 +35,7 @@ Jeremy G Baier
John Veitch John Veitch
Joshua Brandt Joshua Brandt
Josh Willis Josh Willis
Karl Wette
Katerina Chatziioannou Katerina Chatziioannou
Kaylee de Soto Kaylee de Soto
Khun Sang Phukon Khun Sang Phukon
...@@ -59,6 +61,7 @@ Paul Easter ...@@ -59,6 +61,7 @@ Paul Easter
Paul Lasky Paul Lasky
Philip Relton Philip Relton
Rhys Green Rhys Green
Richard Udall
Rico Lo Rico Lo
Roberto Cotesta Roberto Cotesta
Rory Smith Rory Smith
...@@ -75,7 +78,9 @@ Stephen R Green ...@@ -75,7 +78,9 @@ Stephen R Green
Sumeet Kulkarni Sumeet Kulkarni
Sylvia Biscoveanu Sylvia Biscoveanu
Tathagata Ghosh Tathagata Ghosh
Tomasz Baka
Will M. Farr
Virginia d'Emilio Virginia d'Emilio
Vivien Raymond Vivien Raymond
Ka-Lok Lo Ka-Lok Lo
Isaac Legred Isaac Legred
\ No newline at end of file
# All notable changes will be documented in this file # All notable changes will be documented in this file
## [1.2.1] 2022-09-05
Version 1.2.1 release of Bilby
This release contains a few bug fixes following 1.2.0.
### Changes
- Improve how sampling seed is handled across samplers (!1134)
- Make sure labels are included when evidences are in corner plot legend (!1135)
- Remove calls to `getargspec` (!1136)
- Make sure parameter reconstruction cache is not mangled when reading (!1126)
- Enable the constant uncertainty calibration spline to have a specifiable boundary condition (!1137)
- Fix a bug in checkpointing for `bilby_mcmc` (!1141)
- Fix the `LALCBCWaveformGenerator` (!1140)
- Switch to automatic versioning with `setuptools_scm` (!1125)
- Improve the stability of the multivariate normal prior (!1142)
- Extend mass conversions to include source-frame parameters (!1131)
- Fix prior ranges for GW150914 example (!1129)
## [1.2.0] 2022-08-15 ## [1.2.0] 2022-08-15
Version 1.2.0 release of Bilby Version 1.2.0 release of Bilby
......
...@@ -5,4 +5,5 @@ include gw_requirements.txt ...@@ -5,4 +5,5 @@ include gw_requirements.txt
include mcmc_requirements.txt include mcmc_requirements.txt
include optional_requirements.txt include optional_requirements.txt
include sampler_requirements.txt include sampler_requirements.txt
include bilby/_version.py
recursive-include test *.py *.prior recursive-include test *.py *.prior
...@@ -24,7 +24,10 @@ from .core import utils, likelihood, prior, result, sampler ...@@ -24,7 +24,10 @@ from .core import utils, likelihood, prior, result, sampler
from .core.sampler import run_sampler from .core.sampler import run_sampler
from .core.likelihood import Likelihood from .core.likelihood import Likelihood
__version__ = utils.get_version_information() try:
from ._version import version as __version__
except ModuleNotFoundError: # development mode
__version__ = 'unknown'
if sys.version_info < (3,): if sys.version_info < (3,):
......
...@@ -202,6 +202,7 @@ class Bilby_MCMC(MCMCSampler): ...@@ -202,6 +202,7 @@ class Bilby_MCMC(MCMCSampler):
logger.warning("Burn-in inefficiency fraction greater than 10%") logger.warning("Burn-in inefficiency fraction greater than 10%")
def _translate_kwargs(self, kwargs): def _translate_kwargs(self, kwargs):
kwargs = super()._translate_kwargs(kwargs)
if "printdt" not in kwargs: if "printdt" not in kwargs:
for equiv in ["print_dt", "print_update"]: for equiv in ["print_dt", "print_update"]:
if equiv in kwargs: if equiv in kwargs:
...@@ -1075,9 +1076,6 @@ class BilbyMCMCSampler(object): ...@@ -1075,9 +1076,6 @@ class BilbyMCMCSampler(object):
Eindex=0, Eindex=0,
use_ratio=False, use_ratio=False,
): ):
from ..core.sampler.base_sampler import _sampling_convenience_dump
self._sampling_helper = _sampling_convenience_dump
self.beta = beta self.beta = beta
self.Tindex = Tindex self.Tindex = Tindex
self.Eindex = Eindex self.Eindex = Eindex
......
...@@ -382,6 +382,7 @@ class MultivariateGaussianDist(BaseJointPriorDist): ...@@ -382,6 +382,7 @@ class MultivariateGaussianDist(BaseJointPriorDist):
self.covs = [] self.covs = []
self.corrcoefs = [] self.corrcoefs = []
self.sigmas = [] self.sigmas = []
self.logprodsigmas = [] # log of product of sigmas, needed for "standard" multivariate normal
self.weights = [] self.weights = []
self.eigvalues = [] self.eigvalues = []
self.eigvectors = [] self.eigvectors = []
...@@ -528,6 +529,9 @@ class MultivariateGaussianDist(BaseJointPriorDist): ...@@ -528,6 +529,9 @@ class MultivariateGaussianDist(BaseJointPriorDist):
self.covs.append(np.eye(self.num_vars)) self.covs.append(np.eye(self.num_vars))
self.sigmas.append(np.ones(self.num_vars)) self.sigmas.append(np.ones(self.num_vars))
# compute log of product of sigmas, needed for "standard" multivariate normal
self.logprodsigmas.append(np.log(np.prod(self.sigmas[-1])))
# get eigen values and vectors # get eigen values and vectors
try: try:
evals, evecs = np.linalg.eig(self.corrcoefs[-1]) evals, evecs = np.linalg.eig(self.corrcoefs[-1])
...@@ -557,9 +561,16 @@ class MultivariateGaussianDist(BaseJointPriorDist): ...@@ -557,9 +561,16 @@ class MultivariateGaussianDist(BaseJointPriorDist):
# add the mode # add the mode
self.nmodes += 1 self.nmodes += 1
# add multivariate Gaussian # add "standard" multivariate normal distribution
# - when the typical scales of the parameters are very different,
# multivariate_normal() may complain that the covariance matrix is singular
# - instead pass zero means and correlation matrix instead of covariance matrix
# to get the equivalent of a standard normal distribution in higher dimensions
# - this modifies the multivariate normal PDF as follows:
# multivariate_normal(mean=mus, cov=cov).logpdf(x)
# = multivariate_normal(mean=0, cov=corrcoefs).logpdf((x - mus)/sigmas) - logprodsigmas
self.mvn.append( self.mvn.append(
scipy.stats.multivariate_normal(mean=self.mus[-1], cov=self.covs[-1]) scipy.stats.multivariate_normal(mean=np.zeros(self.num_vars), cov=self.corrcoefs[-1])
) )
def _rescale(self, samp, **kwargs): def _rescale(self, samp, **kwargs):
...@@ -630,7 +641,9 @@ class MultivariateGaussianDist(BaseJointPriorDist): ...@@ -630,7 +641,9 @@ class MultivariateGaussianDist(BaseJointPriorDist):
for j in range(samp.shape[0]): for j in range(samp.shape[0]):
# loop over the modes and sum the probabilities # loop over the modes and sum the probabilities
for i in range(self.nmodes): for i in range(self.nmodes):
lnprob[j] = np.logaddexp(lnprob[j], self.mvn[i].logpdf(samp[j])) # self.mvn[i] is a "standard" multivariate normal distribution; see add_mode()
z = (samp[j] - self.mus[i]) / self.sigmas[i]
lnprob[j] = np.logaddexp(lnprob[j], self.mvn[i].logpdf(z) - self.logprodsigmas[i])
# set out-of-bounds values to -inf # set out-of-bounds values to -inf
lnprob[outbounds] = -np.inf lnprob[outbounds] = -np.inf
......
...@@ -298,7 +298,7 @@ def reweight(result, label=None, new_likelihood=None, new_prior=None, ...@@ -298,7 +298,7 @@ def reweight(result, label=None, new_likelihood=None, new_prior=None,
if conversion_function is not None: if conversion_function is not None:
data_frame = result.posterior data_frame = result.posterior
if "npool" in inspect.getargspec(conversion_function).args: if "npool" in inspect.signature(conversion_function).parameters:
data_frame = conversion_function(data_frame, new_likelihood, new_prior, npool=npool) data_frame = conversion_function(data_frame, new_likelihood, new_prior, npool=npool)
else: else:
data_frame = conversion_function(data_frame, new_likelihood, new_prior) data_frame = conversion_function(data_frame, new_likelihood, new_prior)
...@@ -1389,7 +1389,7 @@ class Result(object): ...@@ -1389,7 +1389,7 @@ class Result(object):
data_frame['log_prior'] = self.log_prior_evaluations data_frame['log_prior'] = self.log_prior_evaluations
if conversion_function is not None: if conversion_function is not None:
if "npool" in inspect.getargspec(conversion_function).args: if "npool" in inspect.signature(conversion_function).parameters:
data_frame = conversion_function(data_frame, likelihood, priors, npool=npool) data_frame = conversion_function(data_frame, likelihood, priors, npool=npool)
else: else:
data_frame = conversion_function(data_frame, likelihood, priors) data_frame = conversion_function(data_frame, likelihood, priors)
...@@ -1939,12 +1939,17 @@ def plot_multiple(results, filename=None, labels=None, colours=None, ...@@ -1939,12 +1939,17 @@ def plot_multiple(results, filename=None, labels=None, colours=None,
if evidences: if evidences:
if np.isnan(results[0].log_bayes_factor): if np.isnan(results[0].log_bayes_factor):
template = r' $\mathrm{{ln}}(Z)={lnz:1.3g}$' template = r'{label} $\mathrm{{ln}}(Z)={lnz:1.3g}$'
else: else:
template = r' $\mathrm{{ln}}(B)={lnbf:1.3g}$' template = r'{label} $\mathrm{{ln}}(B)={lnbf:1.3g}$'
labels = [template.format(lnz=result.log_evidence, labels = [
lnbf=result.log_bayes_factor) template.format(
for ii, result in enumerate(results)] label=label,
lnz=result.log_evidence,
lnbf=result.log_bayes_factor,
)
for label, result in zip(labels, results)
]
axes = fig.get_axes() axes = fig.get_axes()
ndim = int(np.sqrt(len(axes))) ndim = int(np.sqrt(len(axes)))
......
...@@ -196,7 +196,13 @@ class Sampler(object): ...@@ -196,7 +196,13 @@ class Sampler(object):
"cores", "cores",
"n_pool", "n_pool",
] ]
sampling_seed_equiv_kwargs = ["sampling_seed", "seed", "random_seed"]
hard_exit = False hard_exit = False
sampling_seed_key = None
"""Name of keyword argument for setting the sampling for the specific sampler.
If a specific sampler does not have a sampling seed option, then it should be
left as None.
"""
def __init__( def __init__(
self, self,
...@@ -289,8 +295,16 @@ class Sampler(object): ...@@ -289,8 +295,16 @@ class Sampler(object):
self._verify_kwargs_against_default_kwargs() self._verify_kwargs_against_default_kwargs()
def _translate_kwargs(self, kwargs): def _translate_kwargs(self, kwargs):
"""Template for child classes""" """Translate keyword arguments.
pass
Default only translates the sampling seed if the sampler has
:code:`sampling_seed_key` set.
"""
if self.sampling_seed_key and self.sampling_seed_key not in kwargs:
for equiv in self.sampling_seed_equiv_kwargs:
if equiv in kwargs:
kwargs[self.sampling_seed_key] = kwargs.pop(equiv)
return kwargs
@property @property
def external_sampler_name(self): def external_sampler_name(self):
......
...@@ -54,8 +54,10 @@ class Cpnest(NestedSampler): ...@@ -54,8 +54,10 @@ class Cpnest(NestedSampler):
n_periodic_checkpoint=8000, n_periodic_checkpoint=8000,
) )
hard_exit = True hard_exit = True
sampling_seed_key = "seed"
def _translate_kwargs(self, kwargs): def _translate_kwargs(self, kwargs):
kwargs = super()._translate_kwargs(kwargs)
if "nlive" not in kwargs: if "nlive" not in kwargs:
for equiv in self.npoints_equiv_kwargs: for equiv in self.npoints_equiv_kwargs:
if equiv in kwargs: if equiv in kwargs:
......
...@@ -114,6 +114,7 @@ class DNest4(_TemporaryFileSamplerMixin, NestedSampler): ...@@ -114,6 +114,7 @@ class DNest4(_TemporaryFileSamplerMixin, NestedSampler):
) )
short_name = "dn4" short_name = "dn4"
hard_exit = True hard_exit = True
sampling_seed_key = "seed"
def __init__( def __init__(
self, self,
...@@ -254,6 +255,7 @@ class DNest4(_TemporaryFileSamplerMixin, NestedSampler): ...@@ -254,6 +255,7 @@ class DNest4(_TemporaryFileSamplerMixin, NestedSampler):
return self.result return self.result
def _translate_kwargs(self, kwargs): def _translate_kwargs(self, kwargs):
kwargs = super()._translate_kwargs(kwargs)
if "num_steps" not in kwargs: if "num_steps" not in kwargs:
for equiv in self.walks_equiv_kwargs: for equiv in self.walks_equiv_kwargs:
if equiv in kwargs: if equiv in kwargs:
......
...@@ -239,6 +239,7 @@ class Dynesty(NestedSampler): ...@@ -239,6 +239,7 @@ class Dynesty(NestedSampler):
} }
def _translate_kwargs(self, kwargs): def _translate_kwargs(self, kwargs):
kwargs = super()._translate_kwargs(kwargs)
if "nlive" not in kwargs: if "nlive" not in kwargs:
for equiv in self.npoints_equiv_kwargs: for equiv in self.npoints_equiv_kwargs:
if equiv in kwargs: if equiv in kwargs:
......
...@@ -113,6 +113,7 @@ class Emcee(MCMCSampler): ...@@ -113,6 +113,7 @@ class Emcee(MCMCSampler):
return emcee return emcee
def _translate_kwargs(self, kwargs): def _translate_kwargs(self, kwargs):
kwargs = super()._translate_kwargs(kwargs)
if "nwalkers" not in kwargs: if "nwalkers" not in kwargs:
for equiv in self.nwalkers_equiv_kwargs: for equiv in self.nwalkers_equiv_kwargs:
if equiv in kwargs: if equiv in kwargs:
......
...@@ -19,7 +19,7 @@ class Nessai(NestedSampler): ...@@ -19,7 +19,7 @@ class Nessai(NestedSampler):
""" """
_default_kwargs = None _default_kwargs = None
seed_equiv_kwargs = ["sampling_seed"] sampling_seed_key = "seed"
@property @property
def default_kwargs(self): def default_kwargs(self):
...@@ -165,6 +165,7 @@ class Nessai(NestedSampler): ...@@ -165,6 +165,7 @@ class Nessai(NestedSampler):
return self.result return self.result
def _translate_kwargs(self, kwargs): def _translate_kwargs(self, kwargs):
super()._translate_kwargs(kwargs)
if "nlive" not in kwargs: if "nlive" not in kwargs:
for equiv in self.npoints_equiv_kwargs: for equiv in self.npoints_equiv_kwargs:
if equiv in kwargs: if equiv in kwargs:
...@@ -175,10 +176,6 @@ class Nessai(NestedSampler): ...@@ -175,10 +176,6 @@ class Nessai(NestedSampler):
kwargs["n_pool"] = kwargs.pop(equiv) kwargs["n_pool"] = kwargs.pop(equiv)
if "n_pool" not in kwargs: if "n_pool" not in kwargs:
kwargs["n_pool"] = self._npool kwargs["n_pool"] = self._npool
if "seed" not in kwargs:
for equiv in self.seed_equiv_kwargs:
if equiv in kwargs:
kwargs["seed"] = kwargs.pop(equiv)
def _verify_kwargs_against_default_kwargs(self): def _verify_kwargs_against_default_kwargs(self):
""" """
......
...@@ -42,6 +42,7 @@ class Nestle(NestedSampler): ...@@ -42,6 +42,7 @@ class Nestle(NestedSampler):
) )
def _translate_kwargs(self, kwargs): def _translate_kwargs(self, kwargs):
kwargs = super()._translate_kwargs(kwargs)
if "npoints" not in kwargs: if "npoints" not in kwargs:
for equiv in self.npoints_equiv_kwargs: for equiv in self.npoints_equiv_kwargs:
if equiv in kwargs: if equiv in kwargs:
......
...@@ -50,6 +50,7 @@ class PyPolyChord(NestedSampler): ...@@ -50,6 +50,7 @@ class PyPolyChord(NestedSampler):
nlives={}, nlives={},
) )
hard_exit = True hard_exit = True
sampling_seed_key = "seed"
@signal_wrapper @signal_wrapper
def run_sampler(self): def run_sampler(self):
...@@ -100,6 +101,7 @@ class PyPolyChord(NestedSampler): ...@@ -100,6 +101,7 @@ class PyPolyChord(NestedSampler):
self.kwargs["num_repeats"] = self.ndim * 5 self.kwargs["num_repeats"] = self.ndim * 5
def _translate_kwargs(self, kwargs): def _translate_kwargs(self, kwargs):
kwargs = super()._translate_kwargs(kwargs)
if "nlive" not in kwargs: if "nlive" not in kwargs:
for equiv in self.npoints_equiv_kwargs: for equiv in self.npoints_equiv_kwargs:
if equiv in kwargs: if equiv in kwargs:
......
...@@ -286,6 +286,7 @@ class Ptemcee(MCMCSampler): ...@@ -286,6 +286,7 @@ class Ptemcee(MCMCSampler):
def _translate_kwargs(self, kwargs): def _translate_kwargs(self, kwargs):
"""Translate kwargs""" """Translate kwargs"""
kwargs = super()._translate_kwargs(kwargs)
if "nwalkers" not in kwargs: if "nwalkers" not in kwargs:
for equiv in self.nwalkers_equiv_kwargs: for equiv in self.nwalkers_equiv_kwargs:
if equiv in kwargs: if equiv in kwargs:
......
...@@ -116,6 +116,7 @@ class PTMCMCSampler(MCMCSampler): ...@@ -116,6 +116,7 @@ class PTMCMCSampler(MCMCSampler):
) )
def _translate_kwargs(self, kwargs): def _translate_kwargs(self, kwargs):
kwargs = super()._translate_kwargs(kwargs)
if "Niter" not in kwargs: if "Niter" not in kwargs:
for equiv in self.nwalkers_equiv_kwargs: for equiv in self.nwalkers_equiv_kwargs:
if equiv in kwargs: if equiv in kwargs:
......
...@@ -91,6 +91,8 @@ class Pymc3(MCMCSampler): ...@@ -91,6 +91,8 @@ class Pymc3(MCMCSampler):
default_kwargs.update(default_nuts_kwargs) default_kwargs.update(default_nuts_kwargs)
sampling_seed_key = "random_seed"
def __init__( def __init__(
self, self,
likelihood, likelihood,
......