Maintenance will be performed on git.ligo.org, chat.ligo.org, containers.ligo.org, and docs.ligo.org starting 2 March 2020 at approximately 8am MST. It is expected to take around 10 minutes and will include a short period of downtime towards the end of the maintenance window. Please direct any comments, concerns, or questions to computing-help@igwn.org.

Commit ae2e49c1 authored by plasky's avatar plasky

Merge branch 'master' of git.ligo.org:Monash/tupak

parents 4fd1d371 9d2df312
Pipeline #19567 passed with stages
in 6 minutes and 57 seconds
......@@ -13,6 +13,7 @@ To get started with `tupak`, we have a few examples and tutorials:
1. [Examples of injecting and recovering data](https://git.ligo.org/Monash/tupak/tree/master/examples/injection_examples)
* [A basic tutorial](https://git.ligo.org/Monash/tupak/blob/master/examples/injection_examples/basic_tutorial.py)
* [Create your own source model](https://git.ligo.org/Monash/tupak/blob/master/examples/injection_examples/create_your_own_source_model.py)
* [Create your own time-domain source model](https://git.ligo.org/Monash/tupak/blob/master/examples/injection_examples/create_your_own_time_domain_source_model.py)
* [How to specify the prior](https://git.ligo.org/Monash/tupak/blob/master/examples/injection_examples/how_to_specify_the_prior.py)
* [Using a partially marginalized likelihood](https://git.ligo.org/Monash/tupak/blob/master/examples/injection_examples/marginalized_likelihood.py)
......
......@@ -55,7 +55,7 @@ for key in ['a_1', 'a_2', 'tilt_1', 'tilt_2', 'phi_12', 'phi_jl', 'phase', 'psi'
priors['luminosity_distance'] = tupak.prior.create_default_prior(name='luminosity_distance')
# Initialise the likelihood by passing in the interferometer data (IFOs) and the waveoform generator
likelihood = tupak.likelihood.Likelihood(interferometers=IFOs, waveform_generator=waveform_generator)
likelihood = tupak.likelihood.GravitationalWaveTransient(interferometers=IFOs, waveform_generator=waveform_generator)
# Run sampler. In this case we're going to use the `dynesty` sampler
result = tupak.sampler.run_sampler(likelihood=likelihood, priors=priors, sampler='dynesty', npoints=1000,
......
......@@ -42,8 +42,8 @@ for key in ['a_1', 'a_2', 'tilt_1', 'tilt_2', 'phi_12', 'phi_jl', 'phase', 'psi'
priors[key] = injection_parameters[key]
priors['luminosity_distance'] = tupak.prior.create_default_prior(name='luminosity_distance')
# Initialise Likelihood
likelihood = tupak.likelihood.Likelihood(interferometers=IFOs, waveform_generator=waveform_generator)
# Initialise GravitationalWaveTransient
likelihood = tupak.likelihood.GravitationalWaveTransient(interferometers=IFOs, waveform_generator=waveform_generator)
# Run sampler
result = tupak.sampler.run_sampler(likelihood=likelihood, priors=priors, sampler='dynesty',
......
......@@ -46,7 +46,7 @@ prior['A'] = tupak.prior.Uniform(0, 1e-20, 'A')
prior['f0'] = tupak.prior.Uniform(0, 20, 'f')
prior['geocent_time'] = tupak.prior.Uniform(-0.01, 0.01, 'geocent_time')
likelihood = tupak.likelihood.Likelihood(IFOs, waveform_generator)
likelihood = tupak.likelihood.GravitationalWaveTransient(IFOs, waveform_generator)
result = tupak.sampler.run_sampler(
likelihood, prior, sampler='dynesty', outdir=outdir, label=label,
......
......@@ -57,8 +57,8 @@ priors['a_2'] = tupak.prior.Interped(name='a_2', xx=a_2, yy=p_a_2, minimum=0, ma
# Finally, if you don't specify any necessary parameters it will be filled in from the default when the sampler starts.
# Enjoy.
# Initialise Likelihood
likelihood = tupak.likelihood.Likelihood(interferometers=IFOs, waveform_generator=waveform_generator)
# Initialise GravitationalWaveTransient
likelihood = tupak.likelihood.GravitationalWaveTransient(interferometers=IFOs, waveform_generator=waveform_generator)
# Run sampler
result = tupak.sampler.run_sampler(likelihood=likelihood, priors=priors, sampler='dynesty',
......
......@@ -37,9 +37,9 @@ priors = dict()
for key in ['a_1', 'a_2', 'tilt_1', 'tilt_2', 'phi_12', 'phi_jl', 'phase', 'iota', 'ra', 'dec', 'geocent_time']:
priors[key] = injection_parameters[key]
# Initialise Likelihood
# Initialise GravitationalWaveTransient
# Note that we now need to pass the: priors and flags for each thing that's being marginalised.
likelihood = tupak.likelihood.Likelihood(interferometers=IFOs, waveform_generator=waveform_generator, prior=priors,
likelihood = tupak.likelihood.GravitationalWaveTransient(interferometers=IFOs, waveform_generator=waveform_generator, prior=priors,
distance_marginalization=True, phase_marginalization=True)
# Run sampler
......
......@@ -53,7 +53,7 @@ waveform_generator = tupak.waveform_generator.WaveformGenerator(time_duration=in
# In this step, we define the likelihood. Here we use the standard likelihood
# function, passing it the data and the waveform generator.
likelihood = tupak.likelihood.Likelihood(interferometers, waveform_generator)
likelihood = tupak.likelihood.GravitationalWaveTransient(interferometers, waveform_generator)
# Finally, we run the sampler. This function takes the likelihood and prio
# along with some options for how to do the sampling and how to save the data
......
......@@ -14,13 +14,13 @@ label = 'test'
outdir = 'outdir'
# Here is minimum requirement for a Likelihood class needed to run tupak. In
# this case, we setup a GaussianLikelihood, which needs to have a
# Here is minimum requirement for a GravitationalWaveTransient class needed to run tupak. In
# this case, we setup a GaussianGravitationalWaveTransient, which needs to have a
# log_likelihood and noise_log_likelihood method. Note, in this case we make
# use of the `tupak` waveform_generator to make the signal (more on this later)
# But, one could make this work without the waveform generator.
class GaussianLikelihood():
class GaussianGravitationalWaveTransient():
def __init__(self, x, y, waveform_generator):
self.x = x
self.y = y
......@@ -74,9 +74,9 @@ waveform_generator = tupak.waveform_generator.WaveformGenerator(time_duration=ti
time_domain_source_model=model)
# Now lets instantiate a version of out Likelihood, giving it the time, data
# Now lets instantiate a version of out GravitationalWaveTransient, giving it the time, data
# and waveform_generator
likelihood = GaussianLikelihood(time, data, waveform_generator)
likelihood = GaussianGravitationalWaveTransient(time, data, waveform_generator)
# From hereon, the syntax is exactly equivalent to other tupak examples
# We make a prior
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -46,7 +46,7 @@ class Test(unittest.TestCase):
self.assertAlmostEqual(all(self.msd['hf_signal_and_noise'] - hf_signal_and_noise_saved), 0.00000000, 5)
def test_recover_luminosity_distance(self):
likelihood = tupak.likelihood.Likelihood(
likelihood = tupak.likelihood.GravitationalWaveTransient(
[self.msd['IFO']], self.msd['waveform_generator'])
priors = {}
......
......@@ -106,8 +106,8 @@ def generate_all_bbh_parameters(sample, likelihood=None, priors=None):
----------
sample: dict or pandas.DataFrame
Samples to fill in with extra parameters, this may be either an injection or posterior samples.
likelihood: tupak.likelihood.Likelihood
Likelihood used for sampling, used for waveform and likelihood.interferometers.
likelihood: tupak.likelihood.GravitationalWaveTransient
GravitationalWaveTransient used for sampling, used for waveform and likelihood.interferometers.
priors: dict, optional
Dictionary of prior objects, used to fill in non-sampled parameters.
"""
......
......@@ -11,10 +11,10 @@ import tupak
import logging
class Likelihood(object):
class GravitationalWaveTransient(object):
def __init__(self, interferometers, waveform_generator, distance_marginalization=False, phase_marginalization=False,
prior=None):
# Likelihood.__init__(self, interferometers, waveform_generator)
# GravitationalWaveTransient.__init__(self, interferometers, waveform_generator)
self.interferometers = interferometers
self.waveform_generator = waveform_generator
self.parameters = self.waveform_generator.parameters
......@@ -106,7 +106,7 @@ class Likelihood(object):
bounds_error=False, fill_value=-np.inf)
class BasicLikelihood(object):
class BasicGravitationalWaveTransient(object):
def __init__(self, interferometers, waveform_generator):
self.interferometers = interferometers
self.waveform_generator = waveform_generator
......@@ -149,13 +149,13 @@ def get_binary_black_hole_likelihood(interferometers):
output of either `tupak.detector.get_interferometer_with_open_data`
or `tupak.detector.get_interferometer_with_fake_noise_and_injection`
Returns
likelihood: tupak.likelihood.Likelihood
likelihood: tupak.likelihood.GravitationalWaveTransient
The likelihood to pass to `run_sampler`
"""
waveform_generator = tupak.waveform_generator.WaveformGenerator(
time_duration=interferometers[0].duration, sampling_frequency=interferometers[0].sampling_frequency,
frequency_domain_source_model=tupak.source.lal_binary_black_hole,
parameters={'waveform_approximant': 'IMRPhenomPv2', 'reference_frequency': 50})
likelihood = tupak.likelihood.Likelihood(interferometers, waveform_generator)
likelihood = tupak.likelihood.GravitationalWaveTransient(interferometers, waveform_generator)
return likelihood
......@@ -443,7 +443,7 @@ def fill_priors(prior, likelihood, parameters=None):
----------
prior: dict
dictionary of prior objects and floats
likelihood: tupak.likelihood.Likelihood instance
likelihood: tupak.likelihood.GravitationalWaveTransient instance
Used to infer the set of parameters to fill the prior with
parameters: list
list of parameters to be sampled in, this can override the default
......
......@@ -119,7 +119,7 @@ class Result(dict):
filename = '{}/{}_corner.png'.format(self.outdir, self.label)
kwargs['filename'] = kwargs.get('filename', filename)
logging.info('Saving corner plot to {}'.format(kwargs['filename']))
if self.injection_parameters is not None:
if getattr(self, 'injection_parameters', None) is not None:
# If no truth argument given, set these to the injection params
injection_parameters = [self.injection_parameters[key]
for key in self.search_parameter_keys]
......@@ -211,8 +211,8 @@ class Result(dict):
Parameters
----------
likelihood: tupak.likelihood.Likelihood
Likelihood used for sampling.
likelihood: tupak.likelihood.GravitationalWaveTransient
GravitationalWaveTransient used for sampling.
priors: dict
Dictionary of prior object, used to fill in delta function priors.
conversion_function: function
......
......@@ -19,7 +19,7 @@ class Sampler(object):
Parameters
----------
likelihood: likelihood.Likelihood
likelihood: likelihood.GravitationalWaveTransient
A object with a log_l method
prior: dict
The prior to be used in the search. Elements can either be floats
......@@ -150,7 +150,7 @@ class Sampler(object):
try:
self.likelihood.log_likelihood_ratio()
except TypeError:
raise TypeError('Likelihood evaluation failed. Have you definitely specified all the parameters?\n{}'.format(
raise TypeError('GravitationalWaveTransient evaluation failed. Have you definitely specified all the parameters?\n{}'.format(
self.likelihood.parameters))
def prior_transform(self, theta):
......@@ -408,8 +408,8 @@ def run_sampler(likelihood, priors=None, label='label', outdir='outdir',
Parameters
----------
likelihood: `tupak.likelihood.Likelihood`
A `Likelihood` instance
likelihood: `tupak.likelihood.GravitationalWaveTransient`
A `GravitationalWaveTransient` instance
priors: dict
A dictionary of the priors for each parameter - missing parameters will
use default priors, if None, all priors will be default
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment