Skip to content

Commit

Permalink
new sens_mat updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekatz04 committed Mar 13, 2024
1 parent 8bf2413 commit 4fff509
Show file tree
Hide file tree
Showing 50 changed files with 708 additions and 843 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduc

We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/mikekatz04/BBHx/tags).

Current Version: 1.0.6
Current Version: 1.0.7

## Authors

Expand Down
99 changes: 55 additions & 44 deletions bbhx/likelihood.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@
import numpy as np

try:
import cupy as xp
import cupy as cp
from pyLikelihood import hdyn_wrap as hdyn_wrap_gpu
from pyLikelihood import direct_like_wrap as direct_like_wrap_gpu
from pyLikelihood import prep_hdyn as prep_hdyn_gpu

except (ImportError, ModuleNotFoundError) as e:
print("No CuPy")
import numpy as xp
import numpy as cp

from pyLikelihood_cpu import prep_hdyn as prep_hdyn_cpu
from pyLikelihood_cpu import hdyn_wrap as hdyn_wrap_cpu
from pyLikelihood_cpu import direct_like_wrap as direct_like_wrap_cpu

from bbhx.utils.constants import *

from lisatools.sensitivity import get_sensitivity
from lisatools.sensitivity import SensitivityMatrix, AET1SensitivityMatrix


class Likelihood:
Expand Down Expand Up @@ -89,19 +89,16 @@ class Likelihood:
"""

def __init__(
self, template_gen, data_freqs, data_channels, psd, use_gpu=False,
self,
template_gen,
data_freqs,
data_channels,
psd,
use_gpu=False,
):

self.use_gpu = use_gpu

if use_gpu:
self.like_gen = direct_like_wrap_gpu
self.xp = xp

else:
self.like_gen = direct_like_wrap_cpu
self.xp = np

# store required information
self.data_freqs = data_freqs

Expand Down Expand Up @@ -138,6 +135,18 @@ def __init__(
4 * self.xp.sum((self.data_channels.conj() * self.data_channels)).real
).item()

@property
def like_gen(self):
"""Likelihood for either GPU or CPU."""
like_gen = direct_like_wrap_gpu if self.use_gpu else direct_like_wrap_cpu
return like_gen

@property
def xp(self):
"""Cupy or Numpy"""
xp = cp if self.use_gpu else np
return xp

@property
def citation(self):
return katz_citations
Expand Down Expand Up @@ -278,12 +287,8 @@ class HeterodynedLikelihood:
waveform will be interpolated. If ``length`` and ``direct`` are not given,
it will interpolate the signal with ``length=8096``.
(Default: ``{}``)
noise_kwargs_AE (dict, optional): Keywords arguments for generating the
noise with ``noisepsd_AE`` (A & E Channel) option in the ``get_sensitivity`` function
from ``lisatools`` TODO: add link. (Default: ``{}``)
noise_kwargs_T (dict, optional): Keywords arguments for generating the
noise with ``noisepsd_T`` (T Channel) option in the ``get_sensitivity`` function
from ``lisatools`` TODO: add link. (Default: ``{}``)
sens_mat (SensitivityMatrix, optional): :class:`SensitivityMatrix` object representing the AET channels.
If ``None``, defaults to class:`AET1SensitivityMatrix`. (default: ``None``)
use_gpu (bool, optional): If ``True``, use GPU.
Attributes:
Expand Down Expand Up @@ -334,8 +339,7 @@ def __init__(
length_f_het,
template_gen_kwargs={},
reference_gen_kwargs={},
noise_kwargs_AE={},
noise_kwargs_T={},
sens_mat=None,
use_gpu=False,
):

Expand All @@ -347,22 +351,41 @@ def __init__(

# direct based on GPU usage
self.use_gpu = use_gpu
if use_gpu:
self.like_gen = hdyn_wrap_gpu
self.xp = xp
else:
self.like_gen = hdyn_wrap_cpu
self.xp = np

self.sens_mat = sens_mat

# calculate all quantites related to the reference template
self.init_heterodyne_info(
reference_template_params,
template_gen_kwargs=template_gen_kwargs,
reference_gen_kwargs=reference_gen_kwargs,
noise_kwargs_AE=noise_kwargs_AE,
noise_kwargs_T=noise_kwargs_T,
)

@property
def sens_mat(self):
"""Sensitivity Matrix"""
return self._sens_mat

@sens_mat.setter
def sens_mat(self, sens_mat):
if sens_mat is None:
_f_not_needed = np.logspace(-5, -1, 1000)
sens_mat = AET1SensitivityMatrix(_f_not_needed)
assert isinstance(sens_mat, SensitivityMatrix)
self._sens_mat = sens_mat

@property
def like_gen(self):
"""C function on GPU/CPU"""
like_gen = hdyn_wrap_gpu if self.use_gpu else hdyn_wrap_cpu
return like_gen

@property
def xp(self):
"""Numpy or Cupy"""
xp = cp if self.use_gpu else np
return xp

@property
def citation(self):
"""Citations for this class"""
Expand All @@ -373,8 +396,6 @@ def init_heterodyne_info(
reference_template_params,
template_gen_kwargs={},
reference_gen_kwargs={},
noise_kwargs_AE={},
noise_kwargs_T={},
):
"""Prepare all information for Heterdyning
Expand All @@ -399,12 +420,6 @@ def init_heterodyne_info(
waveform will be interpolated. If ``length`` and ``direct`` are not given,
it will interpolate the signal with ``length=8096``.
(Default: ``{}``)
noise_kwargs_AE (dict, optional): Keywords arguments for generating the
noise with ``noisepsd_AE`` (A & E Channel) option in the ``get_sensitivity`` function
from ``lisatools`` TODO: add link. (Default: ``{}``)
noise_kwargs_T (dict, optional): Keywords arguments for generating the
noise with ``noisepsd_T`` (T Channel) option in the ``get_sensitivity`` function
from ``lisatools`` TODO: add link. (Default: ``{}``)
"""

Expand All @@ -419,7 +434,7 @@ def init_heterodyne_info(

if minF == 0.0:
minF = 1e-6

reference_gen_kwargs["squeeze"] = True
reference_gen_kwargs["compress"] = True
reference_gen_kwargs["fill"] = True
Expand Down Expand Up @@ -483,14 +498,10 @@ def init_heterodyne_info(
except AttributeError:
f_n_host = self.f_dense

self.sens_mat.update_frequency_arr(f_n_host)

# compute sensitivity at dense frequencies
S_n = self.xp.asarray(
[
get_sensitivity(f_n_host, sens_fn="noisepsd_AE", **noise_kwargs_AE),
get_sensitivity(f_n_host, sens_fn="noisepsd_AE", **noise_kwargs_AE),
get_sensitivity(f_n_host, sens_fn="noisepsd_T", **noise_kwargs_T),
]
)
S_n = self.xp.asarray([self.sens_mat[0], self.sens_mat[1], self.sens_mat[2]])

# compute the individual frequency contributions to A0, A1 (see paper)
A0_flat = 4 * (h0.conj() * self.d) / S_n * df
Expand Down
Binary file modified docs/doctrees/README.doctree
Binary file not shown.
Binary file modified docs/doctrees/bbhx_tutorial.doctree
Binary file not shown.
Binary file modified docs/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/doctrees/index.doctree
Binary file not shown.
220 changes: 96 additions & 124 deletions docs/doctrees/nbsphinx/bbhx_tutorial.ipynb

Large diffs are not rendered by default.

Binary file modified docs/doctrees/nbsphinx/bbhx_tutorial_10_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/doctrees/nbsphinx/bbhx_tutorial_13_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/doctrees/nbsphinx/bbhx_tutorial_16_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/doctrees/nbsphinx/bbhx_tutorial_19_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/doctrees/nbsphinx/bbhx_tutorial_22_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/doctrees/nbsphinx/bbhx_tutorial_24_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/doctrees/nbsphinx/bbhx_tutorial_27_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/doctrees/nbsphinx/bbhx_tutorial_29_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/doctrees/nbsphinx/bbhx_tutorial_32_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/doctrees/nbsphinx/bbhx_tutorial_34_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/doctrees/nbsphinx/bbhx_tutorial_40_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/doctrees/nbsphinx/bbhx_tutorial_43_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/doctrees/nbsphinx/bbhx_tutorial_44_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/doctrees/nbsphinx/bbhx_tutorial_7_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/doctrees/user/like.doctree
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/html/README.html
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ <h3>Versioning<a class="headerlink" href="#versioning" title="Link to this headi
<p>We use <a class="reference external" href="http://semver.org/">SemVer</a> for versioning. For the versions
available, see the <a class="reference external" href="https://github.com/mikekatz04/BBHx/tags">tags on this
repository</a>.</p>
<p>Current Version: 1.0.6</p>
<p>Current Version: 1.0.7</p>
</section>
<section id="authors">
<h3>Authors<a class="headerlink" href="#authors" title="Link to this heading"></a></h3>
Expand Down
Binary file modified docs/html/_images/bbhx_tutorial_10_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/html/_images/bbhx_tutorial_13_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/html/_images/bbhx_tutorial_16_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/html/_images/bbhx_tutorial_19_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/html/_images/bbhx_tutorial_22_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/html/_images/bbhx_tutorial_24_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/html/_images/bbhx_tutorial_27_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/html/_images/bbhx_tutorial_29_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/html/_images/bbhx_tutorial_32_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/html/_images/bbhx_tutorial_34_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/html/_images/bbhx_tutorial_40_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/html/_images/bbhx_tutorial_43_1.png
Binary file modified docs/html/_images/bbhx_tutorial_44_2.png
Binary file modified docs/html/_images/bbhx_tutorial_7_1.png
2 changes: 1 addition & 1 deletion docs/html/_sources/README.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ We use `SemVer <http://semver.org/>`__ for versioning. For the versions
available, see the `tags on this
repository <https://github.com/mikekatz04/BBHx/tags>`__.

Current Version: 1.0.6
Current Version: 1.0.7

Authors
-------
Expand Down
220 changes: 96 additions & 124 deletions docs/html/_sources/bbhx_tutorial.ipynb.txt

Large diffs are not rendered by default.

Loading

0 comments on commit 4fff509

Please sign in to comment.