From 0394aa72a6fc9eeca911da1af98360cd4bea4fa9 Mon Sep 17 00:00:00 2001 From: Colm Talbot <colm.talbot@ligo.org> Date: Mon, 1 Oct 2018 18:39:58 -0500 Subject: [PATCH] add aligned spin prior --- CHANGELOG.md | 1 + test/prior_test.py | 4 ++-- tupak/gw/prior.py | 40 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9da7f48f..9172cf23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ Changes currently on master, but not under a tag. - Hyperparameter estimation now enables the user to provide the single event evidences - Add nested samples to nestle output - Prior and child classes now implement the \_\_eq\_\_ magic method for comparisons +- Add AlignedSpin gw prior ### Changes - Fix construct_cbc_derived_parameters diff --git a/test/prior_test.py b/test/prior_test.py index 3b22b6c6..89047308 100644 --- a/test/prior_test.py +++ b/test/prior_test.py @@ -7,7 +7,6 @@ import os import shutil from collections import OrderedDict - class TestPriorInstantiationWithoutOptionalPriors(unittest.TestCase): def setUp(self): @@ -152,7 +151,8 @@ class TestPriorClasses(unittest.TestCase): tupak.core.prior.Cauchy(name='test', unit='unit', alpha=0, beta=1), tupak.core.prior.Lorentzian(name='test', unit='unit', alpha=0, beta=1), tupak.core.prior.Gamma(name='test', unit='unit', k=1, theta=1), - tupak.core.prior.ChiSquared(name='test', unit='unit', nu=2) + tupak.core.prior.ChiSquared(name='test', unit='unit', nu=2), + tupak.gw.prior.AlignedSpin(name='test', unit='unit') ] def test_minimum_rescaling(self): diff --git a/tupak/gw/prior.py b/tupak/gw/prior.py index e876b254..d45f2a7e 100644 --- a/tupak/gw/prior.py +++ b/tupak/gw/prior.py @@ -1,5 +1,6 @@ import os -from ..core.prior import PriorSet, FromFile, Prior, DeltaFunction, Gaussian +from ..core.prior import (PriorSet, Uniform, FromFile, Prior, DeltaFunction, + Gaussian, Interped) from ..core.utils import logger import numpy as np from scipy.interpolate import UnivariateSpline @@ -26,6 +27,43 @@ class UniformComovingVolume(FromFile): latex_label=latex_label, unit='Mpc') +class AlignedSpin(Interped): + + def __init__(self, a_prior=Uniform(0, 1), z_prior=Uniform(-1, 1), + name=None, latex_label=None, unit=None): + """ + Prior distribution for the aligned (z) component of the spin. + + This takes prior distributions for the magnitude and cosine of the tilt + and forms a compound prior. + + This is useful when using aligned-spin only waveform approximants. + + This is an extension of e.g., (A7) of https://arxiv.org/abs/1805.10457. + + Parameters + ---------- + a_prior: Prior + Prior distribution for spin magnitude + z_prior: Prior + Prior distribution for cosine spin tilt + name: see superclass + latex_label: see superclass + unit: see superclass + """ + self.a_prior = a_prior + self.z_prior = z_prior + chi_min = min(a_prior.maximum * z_prior.minimum, + a_prior.minimum * z_prior.maximum) + chi_max = a_prior.maximum * z_prior.maximum + xx = np.linspace(chi_min, chi_max, 800) + aas = np.linspace(a_prior.minimum, a_prior.maximum, 1000) + yy = [np.trapz(np.nan_to_num(a_prior.prob(aas) / aas * + z_prior.prob(x / aas)), aas) for x in xx] + Interped.__init__(self, xx=xx, yy=yy, name=name, + latex_label=latex_label, unit=unit) + + class BBHPriorSet(PriorSet): def __init__(self, dictionary=None, filename=None): """ Initialises a Prior set for Binary Black holes -- GitLab