Skip to content
Snippets Groups Projects
Commit 1b07e26f authored by Gregory Ashton's avatar Gregory Ashton
Browse files

Merge branch 'split-up-gw-likelihood' into 'master'

Split up gw likelihood

Closes #602

See merge request !1027
parents 94c078c6 66a87102
No related branches found
No related tags found
1 merge request!1027Split up gw likelihood
Pipeline #340721 failed
...@@ -45,11 +45,15 @@ containers: ...@@ -45,11 +45,15 @@ containers:
script: script:
- python -m pip install . - python -m pip install .
- python -c "import bilby" - python -c "import bilby"
- python -c "import bilby.bilby_mcmc"
- python -c "import bilby.core" - python -c "import bilby.core"
- python -c "import bilby.core.prior" - python -c "import bilby.core.prior"
- python -c "import bilby.core.sampler" - python -c "import bilby.core.sampler"
- python -c "import bilby.core.utils"
- python -c "import bilby.gw" - python -c "import bilby.gw"
- python -c "import bilby.gw.detector" - 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.gw.sampler"
- python -c "import bilby.hyper" - python -c "import bilby.hyper"
- python -c "import cli_bilby" - 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): ...@@ -12,7 +12,7 @@ if python_version < (3, 7):
def write_version_file(version): 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 Parameters
---------- ----------
...@@ -27,31 +27,32 @@ def write_version_file(version): ...@@ -27,31 +27,32 @@ def write_version_file(version):
""" """
try: try:
git_log = subprocess.check_output( git_log = subprocess.check_output(
['git', 'log', '-1', '--pretty=%h %ai']).decode('utf-8') ["git", "log", "-1", "--pretty=%h %ai"]
git_diff = (subprocess.check_output(['git', 'diff', '.']) + ).decode("utf-8")
subprocess.check_output( git_diff = (
['git', 'diff', '--cached', '.'])).decode('utf-8') subprocess.check_output(["git", "diff", "."])
if git_diff == '': + subprocess.check_output(["git", "diff", "--cached", "."])
git_status = '(CLEAN) ' + git_log ).decode("utf-8")
if git_diff == "":
git_status = "(CLEAN) " + git_log
else: else:
git_status = '(UNCLEAN) ' + git_log git_status = "(UNCLEAN) " + git_log
except Exception as e: except Exception as e:
print("Unable to obtain git version information, exception: {}" print("Unable to obtain git version information, exception: {}".format(e))
.format(e)) git_status = "release"
git_status = 'release'
version_file = '.version' version_file = ".version"
if os.path.isfile(version_file) is False: if os.path.isfile(version_file) is False:
with open('bilby/' + version_file, 'w+') as f: with open("bilby/" + version_file, "w+") as f:
f.write('{}: {}'.format(version, git_status)) f.write("{}: {}".format(version, git_status))
return version_file return version_file
def get_long_description(): 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__)) 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() long_description = f.read()
return long_description return long_description
...@@ -73,32 +74,51 @@ VERSION = '1.1.4' ...@@ -73,32 +74,51 @@ VERSION = '1.1.4'
version_file = write_version_file(VERSION) version_file = write_version_file(VERSION)
long_description = get_long_description() long_description = get_long_description()
setup(name='bilby', setup(
description='A user-friendly Bayesian inference library', name="bilby",
long_description=long_description, description="A user-friendly Bayesian inference library",
long_description_content_type="text/x-rst", long_description=long_description,
url='https://git.ligo.org/lscsoft/bilby', long_description_content_type="text/x-rst",
author='Greg Ashton, Moritz Huebner, Paul Lasky, Colm Talbot', url="https://git.ligo.org/lscsoft/bilby",
author_email='paul.lasky@monash.edu', author="Greg Ashton, Moritz Huebner, Paul Lasky, Colm Talbot",
license="MIT", author_email="paul.lasky@monash.edu",
version=VERSION, license="MIT",
packages=['bilby', 'bilby.core', 'bilby.core.prior', 'bilby.core.sampler', version=VERSION,
'bilby.core.utils', 'bilby.gw', 'bilby.gw.detector', packages=[
'bilby.gw.sampler', 'bilby.hyper', 'bilby.gw.eos', 'bilby.bilby_mcmc', "bilby",
'cli_bilby'], "bilby.bilby_mcmc",
package_dir={'bilby': 'bilby', 'cli_bilby': 'cli_bilby'}, "bilby.core",
package_data={'bilby.gw': ['prior_files/*'], "bilby.core.prior",
'bilby.gw.detector': ['noise_curves/*.txt', 'detectors/*'], "bilby.core.sampler",
'bilby.gw.eos': ['eos_tables/*.dat'], "bilby.core.utils",
'bilby': [version_file]}, "bilby.gw",
python_requires='>=3.6', "bilby.gw.detector",
install_requires=get_requirements(), "bilby.gw.eos",
entry_points={'console_scripts': "bilby.gw.likelihood",
['bilby_plot=cli_bilby.plot_multiple_posteriors:main', "bilby.gw.sampler",
'bilby_result=cli_bilby.bilby_result:main'] "bilby.hyper",
}, "cli_bilby",
classifiers=[ ],
"Programming Language :: Python :: 3.6", package_dir={"bilby": "bilby", "cli_bilby": "cli_bilby"},
"Programming Language :: Python :: 3.7", package_data={
"License :: OSI Approved :: MIT License", "bilby.gw": ["prior_files/*"],
"Operating System :: OS Independent"]) "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