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
Showing
with 1170 additions and 392 deletions
from __future__ import absolute_import, print_function
from collections import namedtuple
import os
import signal
......@@ -12,8 +10,7 @@ from pandas import DataFrame
from distutils.version import LooseVersion
import dill as pickle
from ..utils import (
logger, get_progress_bar, check_directory_exists_and_if_not_mkdir)
from ..utils import logger, check_directory_exists_and_if_not_mkdir
from .base_sampler import MCMCSampler, SamplerError
......@@ -25,8 +22,8 @@ class Emcee(MCMCSampler):
documentation for that class for further help. Under Other Parameters, we
list commonly used kwargs and the bilby defaults.
Other Parameters
----------------
Parameters
==========
nwalkers: int, (100)
The number of walkers
nsteps: int, (100)
......@@ -44,7 +41,6 @@ class Emcee(MCMCSampler):
a: float (2)
The proposal scale factor
"""
default_kwargs = dict(
......@@ -224,7 +220,7 @@ class Emcee(MCMCSampler):
""" Defines various things related to checkpointing and storing data
Returns
-------
=======
checkpoint_info: named_tuple
An object with attributes `sampler_file`, `chain_file`, and
`chain_template`. The first two give paths to where the sampler and
......@@ -353,7 +349,7 @@ class Emcee(MCMCSampler):
self.pos0 = self.sampler.chain[:, -1, :]
def run_sampler(self):
tqdm = get_progress_bar()
from tqdm.auto import tqdm
sampler_function_kwargs = self.sampler_function_kwargs
iterations = sampler_function_kwargs.pop('iterations')
iterations -= self._previous_iterations
......
from __future__ import absolute_import
import numpy as np
from .base_sampler import Sampler
......@@ -13,7 +12,7 @@ class FakeSampler(Sampler):
See base class for parameters. Added parameters are described below.
Parameters
----------
==========
sample_file: str
A string pointing to the posterior data file to be loaded.
"""
......
from __future__ import absolute_import, print_function
from ..utils import logger, get_progress_bar
from ..utils import logger
import numpy as np
import os
from .emcee import Emcee
......@@ -13,8 +12,8 @@ class Kombine(Emcee):
documentation for that class for further help. Under Other Parameters, we
list commonly used kwargs and the bilby defaults.
Other Parameters
----------------
Parameters
==========
nwalkers: int, (500)
The number of walkers
iterations: int, (100)
......@@ -32,7 +31,6 @@ class Kombine(Emcee):
burn_in_act: float (3.)
The number of autocorrelation times to discard as burn-in
"""
default_kwargs = dict(nwalkers=500, args=[], pool=None, transd=False,
......@@ -141,7 +139,7 @@ class Kombine(Emcee):
logger.info("Kombine auto-burnin complete. Removing {} samples from chains".format(self.nburn))
self._set_pos0_for_resume()
tqdm = get_progress_bar()
from tqdm.auto import tqdm
sampler_function_kwargs = self.sampler_function_kwargs
iterations = sampler_function_kwargs.pop('iterations')
iterations -= self._previous_iterations
......
import numpy as np
from pandas import DataFrame
from .base_sampler import NestedSampler
from ..utils import logger, check_directory_exists_and_if_not_mkdir, load_json
class Nessai(NestedSampler):
"""bilby wrapper of nessai (https://github.com/mj-will/nessai)
All positional and keyword arguments passed to `run_sampler` are propogated
to `nessai.flowsampler.FlowSampler`
See the documentation for an explanation of the different kwargs.
Documentation: https://nessai.readthedocs.io/
"""
default_kwargs = dict(
output=None,
nlive=1000,
stopping=0.1,
resume=True,
max_iteration=None,
checkpointing=True,
seed=1234,
acceptance_threshold=0.01,
analytic_priors=False,
maximum_uninformed=1000,
uninformed_proposal=None,
uninformed_proposal_kwargs=None,
flow_class=None,
flow_config=None,
training_frequency=None,
reset_weights=False,
reset_permutations=False,
reset_acceptance=False,
train_on_empty=True,
cooldown=100,
memory=False,
poolsize=None,
drawsize=None,
max_poolsize_scale=10,
update_poolsize=False,
latent_prior='truncated_gaussian',
draw_latent_kwargs=None,
compute_radius_with_all=False,
min_radius=False,
max_radius=50,
check_acceptance=False,
fuzz=1.0,
expansion_fraction=1.0,
rescale_parameters=True,
rescale_bounds=[-1, 1],
update_bounds=False,
boundary_inversion=False,
inversion_type='split', detect_edges=False,
detect_edges_kwargs=None,
reparameterisations=None,
n_pool=None,
max_threads=1,
pytorch_threads=None,
plot=None,
proposal_plots=False
)
seed_equiv_kwargs = ['sampling_seed']
def log_prior(self, theta):
"""
Parameters
----------
theta: list
List of sampled values on a unit interval
Returns
-------
float: Joint ln prior probability of theta
"""
return self.priors.ln_prob(theta, axis=0)
def run_sampler(self):
from nessai.flowsampler import FlowSampler
from nessai.model import Model as BaseModel
from nessai.livepoint import dict_to_live_points
from nessai.posterior import compute_weights
from nessai.utils import setup_logger
class Model(BaseModel):
"""A wrapper class to pass our log_likelihood and priors into nessai
Parameters
----------
names : list of str
List of parameters to sample
priors : :obj:`bilby.core.prior.PriorDict`
Priors to use for sampling. Needed for the bounds and the
`sample` method.
"""
def __init__(self, names, priors):
self.names = names
self.priors = priors
self._update_bounds()
@staticmethod
def log_likelihood(x, **kwargs):
"""Compute the log likelihood"""
theta = [x[n].item() for n in self.search_parameter_keys]
return self.log_likelihood(theta)
@staticmethod
def log_prior(x, **kwargs):
"""Compute the log prior"""
theta = {n: x[n] for n in self._search_parameter_keys}
return self.log_prior(theta)
def _update_bounds(self):
self.bounds = {key: [self.priors[key].minimum, self.priors[key].maximum]
for key in self.names}
def new_point(self, N=1):
"""Draw a point from the prior"""
prior_samples = self.priors.sample(size=N)
samples = {n: prior_samples[n] for n in self.names}
return dict_to_live_points(samples)
def new_point_log_prob(self, x):
"""Proposal probability for new the point"""
return self.log_prior(x)
# Setup the logger for nessai using the same settings as the bilby logger
setup_logger(self.outdir, label=self.label,
log_level=logger.getEffectiveLevel())
model = Model(self.search_parameter_keys, self.priors)
out = None
while out is None:
try:
out = FlowSampler(model, **self.kwargs)
except TypeError as e:
raise TypeError("Unable to initialise nessai sampler with error: {}".format(e))
try:
out.run(save=True, plot=self.plot)
except SystemExit as e:
import sys
logger.info("Caught exit code {}, exiting with signal {}".format(e.args[0], self.exit_code))
sys.exit(self.exit_code)
# Manually set likelihood evaluations because parallelisation breaks the counter
self.result.num_likelihood_evaluations = out.ns.likelihood_evaluations[-1]
self.result.posterior = DataFrame(out.posterior_samples)
self.result.nested_samples = DataFrame(out.nested_samples)
self.result.nested_samples.rename(
columns=dict(logL='log_likelihood', logP='log_prior'), inplace=True)
self.result.posterior.rename(
columns=dict(logL='log_likelihood', logP='log_prior'), inplace=True)
_, log_weights = compute_weights(np.array(self.result.nested_samples.log_likelihood),
np.array(out.ns.state.nlive))
self.result.nested_samples['weights'] = np.exp(log_weights)
self.result.log_evidence = out.ns.log_evidence
self.result.log_evidence_err = np.sqrt(out.ns.information / out.ns.nlive)
return self.result
def _translate_kwargs(self, kwargs):
if 'nlive' not in kwargs:
for equiv in self.npoints_equiv_kwargs:
if equiv in kwargs:
kwargs['nlive'] = kwargs.pop(equiv)
if 'n_pool' not in kwargs:
for equiv in self.npool_equiv_kwargs:
if equiv in kwargs:
kwargs['n_pool'] = kwargs.pop(equiv)
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):
"""
Set the directory where the output will be written
and check resume and checkpoint status.
"""
if 'config_file' in self.kwargs:
d = load_json(self.kwargs['config_file'], None)
self.kwargs.update(d)
self.kwargs.pop('config_file')
if not self.kwargs['plot']:
self.kwargs['plot'] = self.plot
if self.kwargs['n_pool'] == 1 and self.kwargs['max_threads'] == 1:
logger.warning('Setting pool to None (n_pool=1 & max_threads=1)')
self.kwargs['n_pool'] = None
if not self.kwargs['output']:
self.kwargs['output'] = self.outdir + '/{}_nessai/'.format(self.label)
if self.kwargs['output'].endswith('/') is False:
self.kwargs['output'] = '{}/'.format(self.kwargs['output'])
check_directory_exists_and_if_not_mkdir(self.kwargs['output'])
NestedSampler._verify_kwargs_against_default_kwargs(self)
from __future__ import absolute_import
import numpy as np
from pandas import DataFrame
......@@ -14,8 +13,8 @@ class Nestle(NestedSampler):
that function for further help. Under Other Parameters, we list commonly
used kwargs and the bilby defaults
Other Parameters
----------------
Parameters
==========
npoints: int
The number of live points, note this can also equivalently be given as
one of [nlive, nlives, n_live_points]
......@@ -52,7 +51,7 @@ class Nestle(NestedSampler):
""" Runs Nestle sampler with given kwargs and returns the result
Returns
-------
=======
bilby.core.result.Result: Packaged information about the result
"""
......@@ -74,6 +73,7 @@ class Nestle(NestedSampler):
sorted_samples=self.result.samples)
self.result.log_evidence = out.logz
self.result.log_evidence_err = out.logzerr
self.result.information_gain = out.h
self.calc_likelihood_count()
return self.result
......@@ -83,7 +83,7 @@ class Nestle(NestedSampler):
kwargs without actually running to the end
Returns
-------
=======
bilby.core.result.Result: Dummy container for sampling results.
"""
......
from __future__ import absolute_import
import numpy as np
......@@ -84,7 +83,7 @@ class PyPolyChord(NestedSampler):
The second column are the log likelihoods, the remaining columns are the physical parameters
Returns
-------
=======
array_like, array_like: The log_likelihoods and the associated parameters
"""
......
......@@ -43,12 +43,12 @@ class JumpProposal(object):
""" A generic class for jump proposals
Parameters
----------
==========
priors: bilby.core.prior.PriorDict
Dictionary of priors used in this sampling run
Attributes
----------
==========
log_j: float
Log Jacobian of the proposal. Characterises whether or not detailed balance
is preserved. If not, log_j needs to be adjusted accordingly.
......@@ -60,12 +60,12 @@ class JumpProposal(object):
""" A generic wrapper for the jump proposal function
Parameters
----------
==========
args: Arguments that are going to be passed into the proposal function
kwargs: Keyword arguments that are going to be passed into the proposal function
Returns
-------
=======
dict: A dictionary with the new samples. Boundary conditions are applied.
"""
......@@ -106,7 +106,7 @@ class JumpProposalCycle(object):
""" A generic wrapper class for proposal cycles
Parameters
----------
==========
proposal_functions: list
A list of callable proposal functions/objects
weights: list
......@@ -153,7 +153,7 @@ class JumpProposalCycle(object):
"""
Returns
-------
=======
Normalised proposal weights
"""
......@@ -175,7 +175,7 @@ class NormJump(JumpProposal):
A normal distributed step centered around the old sample
Parameters
----------
==========
step_size: float
The scalable step size
priors:
......@@ -196,8 +196,9 @@ class EnsembleWalk(JumpProposal):
**random_number_generator_args):
"""
An ensemble walk
Parameters
----------
==========
random_number_generator: func, optional
A random number generator. Default is random.random
n_points: int, optional
......@@ -233,7 +234,7 @@ class EnsembleStretch(JumpProposal):
Stretch move. Calculates the log Jacobian which can be used in cpnest to bias future moves.
Parameters
----------
==========
scale: float, optional
Stretching scale. Default is 2.0.
"""
......@@ -257,7 +258,7 @@ class DifferentialEvolution(JumpProposal):
old sample based on them using some Gaussian randomisation in the step.
Parameters
----------
==========
sigma: float, optional
Random spread in the evolution step. Default is 1e-4
mu: float, optional
......@@ -280,7 +281,7 @@ class EnsembleEigenVector(JumpProposal):
Ensemble step based on the ensemble eigenvectors.
Parameters
----------
==========
priors:
See superclass
"""
......
This diff is collapsed.
from __future__ import absolute_import, print_function
import glob
import shutil
......@@ -17,8 +16,8 @@ class PTMCMCSampler(MCMCSampler):
documentation for that class for further help. Under Other Parameters, we
list commonly used kwargs and the bilby defaults.
Other Parameters
----------------
Parameters
==========
Niter: int (2*10**4 + 1)
The number of mcmc steps
burn: int (5 * 10**3)
......@@ -33,10 +32,13 @@ class PTMCMCSampler(MCMCSampler):
(https://github.com/rgreen1995/PTMCMCSampler/blob/master/examples/simple.ipynb)
and
(http://jellis18.github.io/PTMCMCSampler/PTMCMCSampler.html#ptmcmcsampler-ptmcmcsampler-module)
for examples and more info. logl_grad: func (None) Gradient of
likelihood if known (default = None) logp_grad: func (None) Gradient
of prior if known (default = None) verbose: bool (True) Update current
run-status to the screen
for examples and more info.
logl_grad: func (None)
Gradient of likelihood if known (default = None)
logp_grad: func (None)
Gradient of prior if known (default = None)
verbose: bool (True)
Update current run-status to the screen
"""
......
from __future__ import absolute_import, print_function
from collections import OrderedDict
from distutils.version import StrictVersion
......@@ -21,8 +20,8 @@ class Pymc3(MCMCSampler):
class for further help. Under Other Parameters, we list commonly used
kwargs and the bilby, or where appropriate, PyMC3 defaults.
Other Parameters
----------------
Parameters
==========
draws: int, (1000)
The number of sample draws from the posterior per chain.
chains: int, (2)
......
......@@ -24,8 +24,8 @@ class Pymultinest(NestedSampler):
for that class for further help. Under Other Parameters, we list commonly
used kwargs and the bilby defaults.
Other Parameters
----------------
Parameters
==========
npoints: int
The number of live points, note this can also equivalently be given as
one of [nlive, nlives, n_live_points]
......@@ -129,9 +129,9 @@ class Pymultinest(NestedSampler):
def _apply_multinest_boundaries(self):
if self.kwargs["wrapped_params"] is None:
self.kwargs["wrapped_params"] = []
for param, value in self.priors.items():
if value.boundary == "periodic":
self.kwargs["wrapped_params"] = list()
for param in self.search_parameter_keys:
if self.priors[param].boundary == "periodic":
self.kwargs["wrapped_params"].append(1)
else:
self.kwargs["wrapped_params"].append(0)
......
from __future__ import absolute_import
import datetime
import distutils.dir_util
......@@ -28,8 +27,8 @@ class Ultranest(NestedSampler):
`ultranest.NestedSampler` will be used, otherwise the
`ultranest.ReactiveNestedSampler` will be used.
Other Parameters
----------------
Parameters
==========
num_live_points: int
The number of live points, note this can also equivalently be given as
one of [nlive, nlives, n_live_points, num_live_points]. If not given
......@@ -61,7 +60,7 @@ class Ultranest(NestedSampler):
log_interval=None,
dlogz=None,
max_iters=None,
update_interval_iter_fraction=0.2,
update_interval_volume_fraction=0.2,
viz_callback=None,
dKL=0.5,
frac_remain=0.01,
......@@ -232,7 +231,7 @@ class Ultranest(NestedSampler):
]
else:
keys = [
"update_interval_iter_fraction",
"update_interval_volume_fraction",
"update_interval_ncall",
"log_interval",
"show_status",
......@@ -366,6 +365,8 @@ class Ultranest(NestedSampler):
self.result.nested_samples = nested_samples
self.result.log_evidence = out["logz"]
self.result.log_evidence_err = out["logzerr"]
if self.kwargs["num_live_points"] is not None:
self.result.information_gain = np.power(out["logzerr"], 2) * self.kwargs["num_live_points"]
self.result.outputfiles_basename = self.outputfiles_basename
self.result.sampling_time = datetime.timedelta(seconds=self.total_sampling_time)
......@@ -7,7 +7,7 @@ class CoupledTimeAndFrequencySeries(object):
""" A waveform generator
Parameters
----------
==========
sampling_frequency: float, optional
The sampling frequency
duration: float, optional
......@@ -32,7 +32,7 @@ class CoupledTimeAndFrequencySeries(object):
""" Frequency array for the waveforms. Automatically updates if sampling_frequency or duration are updated.
Returns
-------
=======
array_like: The frequency array
"""
if not self._frequency_array_updated:
......@@ -60,7 +60,7 @@ class CoupledTimeAndFrequencySeries(object):
""" Time array for the waveforms. Automatically updates if sampling_frequency or duration are updated.
Returns
-------
=======
array_like: The time array
"""
......@@ -91,7 +91,7 @@ class CoupledTimeAndFrequencySeries(object):
""" Allows one to set the time duration and automatically updates the frequency and time array.
Returns
-------
=======
float: The time duration.
"""
......@@ -108,7 +108,7 @@ class CoupledTimeAndFrequencySeries(object):
""" Allows one to set the sampling frequency and automatically updates the frequency and time array.
Returns
-------
=======
float: The sampling frequency.
"""
......
This diff is collapsed.
This diff is collapsed.
......@@ -27,7 +27,7 @@ def set_cosmology(cosmology=None):
as the last used cosmology.
Parameters
----------
==========
cosmology: astropy.cosmology.FLRW, str, dict
Description of cosmology, one of:
None - Use DEFAULT_COSMOLOGY
......@@ -37,7 +37,7 @@ def set_cosmology(cosmology=None):
class.
Returns
-------
=======
cosmo: astropy.cosmology.FLRW
Cosmology instance
"""
......
This diff is collapsed.
This diff is collapsed.
# LIGO India Aundha at Aplus sensitvity.
# LIGO-T2000158
# https://dcc.ligo.org/LIGO-T2000012/public
name = 'A1'
power_spectral_density = PowerSpectralDensity(asd_file='Aplus_asd.txt')
minimum_frequency = 20
maximum_frequency = 2048
length = 4
latitude = 19 + 36. / 60 + 47.9017 / 3600
longitude = 77 + 1. / 60 + 51.0997 / 3600
elevation = 440.0
xarm_azimuth = 117.6157
yarm_azimuth = 207.6165
This diff is collapsed.