Skip to content
Snippets Groups Projects
Commit 66a87102 authored by Colm Talbot's avatar Colm Talbot Committed by Gregory Ashton
Browse files

Split up gw likelihood

parent d51d5194
No related branches found
No related tags found
1 merge request!1027Split up gw likelihood
......@@ -45,11 +45,15 @@ containers:
script:
- python -m pip install .
- python -c "import bilby"
- python -c "import bilby.bilby_mcmc"
- python -c "import bilby.core"
- python -c "import bilby.core.prior"
- python -c "import bilby.core.sampler"
- python -c "import bilby.core.utils"
- python -c "import bilby.gw"
- python -c "import bilby.gw.detector"
- python -c "import bilby.gw.eos"
- python -c "import bilby.gw.likelihood"
- python -c "import bilby.gw.sampler"
- python -c "import bilby.hyper"
- python -c "import cli_bilby"
......
from .base import GravitationalWaveTransient
from .basic import BasicGravitationalWaveTransient
from .roq import BilbyROQParamsRangeError, ROQGravitationalWaveTransient
from .multiband import MBGravitationalWaveTransient
from ..source import lal_binary_black_hole
from ..waveform_generator import WaveformGenerator
def get_binary_black_hole_likelihood(interferometers):
""" A wrapper to quickly set up a likelihood for BBH parameter estimation
Parameters
==========
interferometers: {bilby.gw.detector.InterferometerList, list}
A list of `bilby.detector.Interferometer` instances, typically the
output of either `bilby.detector.get_interferometer_with_open_data`
or `bilby.detector.get_interferometer_with_fake_noise_and_injection`
Returns
=======
bilby.GravitationalWaveTransient: The likelihood to pass to `run_sampler`
"""
waveform_generator = WaveformGenerator(
duration=interferometers.duration,
sampling_frequency=interferometers.sampling_frequency,
frequency_domain_source_model=lal_binary_black_hole,
waveform_arguments={'waveform_approximant': 'IMRPhenomPv2',
'reference_frequency': 50})
return GravitationalWaveTransient(interferometers, waveform_generator)
This diff is collapsed.
import numpy as np
from ...core.likelihood import Likelihood
class BasicGravitationalWaveTransient(Likelihood):
def __init__(self, interferometers, waveform_generator):
"""
A likelihood object, able to compute the likelihood of the data given
some model parameters
The simplest frequency-domain gravitational wave transient likelihood. Does
not include distance/phase marginalization.
Parameters
==========
interferometers: list
A list of `bilby.gw.detector.Interferometer` instances - contains the
detector data and power spectral densities
waveform_generator: bilby.gw.waveform_generator.WaveformGenerator
An object which computes the frequency-domain strain of the signal,
given some set of parameters
"""
super(BasicGravitationalWaveTransient, self).__init__(dict())
self.interferometers = interferometers
self.waveform_generator = waveform_generator
def __repr__(self):
return self.__class__.__name__ + '(interferometers={},\n\twaveform_generator={})' \
.format(self.interferometers, self.waveform_generator)
def noise_log_likelihood(self):
""" Calculates the real part of noise log-likelihood
Returns
=======
float: The real part of the noise log likelihood
"""
log_l = 0
for interferometer in self.interferometers:
log_l -= 2. / self.waveform_generator.duration * np.sum(
abs(interferometer.frequency_domain_strain) ** 2 /
interferometer.power_spectral_density_array)
return log_l.real
def log_likelihood(self):
""" Calculates the real part of log-likelihood value
Returns
=======
float: The real part of the log likelihood
"""
log_l = 0
waveform_polarizations = \
self.waveform_generator.frequency_domain_strain(
self.parameters.copy())
if waveform_polarizations is None:
return np.nan_to_num(-np.inf)
for interferometer in self.interferometers:
log_l += self.log_likelihood_interferometer(
waveform_polarizations, interferometer)
return log_l.real
def log_likelihood_interferometer(self, waveform_polarizations,
interferometer):
"""
Parameters
==========
waveform_polarizations: dict
Dictionary containing the desired waveform polarization modes and the related strain
interferometer: bilby.gw.detector.Interferometer
The Interferometer object we want to have the log-likelihood for
Returns
=======
float: The real part of the log-likelihood for this interferometer
"""
signal_ifo = interferometer.get_detector_response(
waveform_polarizations, self.parameters)
log_l = - 2. / self.waveform_generator.duration * np.vdot(
interferometer.frequency_domain_strain - signal_ifo,
(interferometer.frequency_domain_strain - signal_ifo) /
interferometer.power_spectral_density_array)
return log_l.real
This diff is collapsed.
This diff is collapsed.
......@@ -12,7 +12,7 @@ if python_version < (3, 7):
def write_version_file(version):
""" Writes a file with version information to be used at run time
"""Writes a file with version information to be used at run time
Parameters
----------
......@@ -27,31 +27,32 @@ def write_version_file(version):
"""
try:
git_log = subprocess.check_output(
['git', 'log', '-1', '--pretty=%h %ai']).decode('utf-8')
git_diff = (subprocess.check_output(['git', 'diff', '.']) +
subprocess.check_output(
['git', 'diff', '--cached', '.'])).decode('utf-8')
if git_diff == '':
git_status = '(CLEAN) ' + git_log
["git", "log", "-1", "--pretty=%h %ai"]
).decode("utf-8")
git_diff = (
subprocess.check_output(["git", "diff", "."])
+ subprocess.check_output(["git", "diff", "--cached", "."])
).decode("utf-8")
if git_diff == "":
git_status = "(CLEAN) " + git_log
else:
git_status = '(UNCLEAN) ' + git_log
git_status = "(UNCLEAN) " + git_log
except Exception as e:
print("Unable to obtain git version information, exception: {}"
.format(e))
git_status = 'release'
print("Unable to obtain git version information, exception: {}".format(e))
git_status = "release"
version_file = '.version'
version_file = ".version"
if os.path.isfile(version_file) is False:
with open('bilby/' + version_file, 'w+') as f:
f.write('{}: {}'.format(version, git_status))
with open("bilby/" + version_file, "w+") as f:
f.write("{}: {}".format(version, git_status))
return version_file
def get_long_description():
""" Finds the README and reads in the description """
"""Finds the README and reads in the description"""
here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, 'README.rst')) as f:
with open(os.path.join(here, "README.rst")) as f:
long_description = f.read()
return long_description
......@@ -73,32 +74,51 @@ VERSION = '1.1.4'
version_file = write_version_file(VERSION)
long_description = get_long_description()
setup(name='bilby',
description='A user-friendly Bayesian inference library',
long_description=long_description,
long_description_content_type="text/x-rst",
url='https://git.ligo.org/lscsoft/bilby',
author='Greg Ashton, Moritz Huebner, Paul Lasky, Colm Talbot',
author_email='paul.lasky@monash.edu',
license="MIT",
version=VERSION,
packages=['bilby', 'bilby.core', 'bilby.core.prior', 'bilby.core.sampler',
'bilby.core.utils', 'bilby.gw', 'bilby.gw.detector',
'bilby.gw.sampler', 'bilby.hyper', 'bilby.gw.eos', 'bilby.bilby_mcmc',
'cli_bilby'],
package_dir={'bilby': 'bilby', 'cli_bilby': 'cli_bilby'},
package_data={'bilby.gw': ['prior_files/*'],
'bilby.gw.detector': ['noise_curves/*.txt', 'detectors/*'],
'bilby.gw.eos': ['eos_tables/*.dat'],
'bilby': [version_file]},
python_requires='>=3.6',
install_requires=get_requirements(),
entry_points={'console_scripts':
['bilby_plot=cli_bilby.plot_multiple_posteriors:main',
'bilby_result=cli_bilby.bilby_result:main']
},
classifiers=[
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent"])
setup(
name="bilby",
description="A user-friendly Bayesian inference library",
long_description=long_description,
long_description_content_type="text/x-rst",
url="https://git.ligo.org/lscsoft/bilby",
author="Greg Ashton, Moritz Huebner, Paul Lasky, Colm Talbot",
author_email="paul.lasky@monash.edu",
license="MIT",
version=VERSION,
packages=[
"bilby",
"bilby.bilby_mcmc",
"bilby.core",
"bilby.core.prior",
"bilby.core.sampler",
"bilby.core.utils",
"bilby.gw",
"bilby.gw.detector",
"bilby.gw.eos",
"bilby.gw.likelihood",
"bilby.gw.sampler",
"bilby.hyper",
"cli_bilby",
],
package_dir={"bilby": "bilby", "cli_bilby": "cli_bilby"},
package_data={
"bilby.gw": ["prior_files/*"],
"bilby.gw.detector": ["noise_curves/*.txt", "detectors/*"],
"bilby.gw.eos": ["eos_tables/*.dat"],
"bilby": [version_file],
},
python_requires=">=3.7",
install_requires=get_requirements(),
entry_points={
"console_scripts": [
"bilby_plot=cli_bilby.plot_multiple_posteriors:main",
"bilby_result=cli_bilby.bilby_result:main",
]
},
classifiers=[
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment