ml4gw 0.4.2__py3-none-any.whl → 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ml4gw might be problematic. Click here for more details.
- ml4gw/constants.py +45 -0
- ml4gw/distributions.py +13 -9
- ml4gw/nn/norm.py +6 -0
- ml4gw/transforms/spectral.py +17 -5
- ml4gw/utils/interferometer.py +6 -0
- ml4gw/waveforms/__init__.py +2 -0
- ml4gw/waveforms/phenom_d.py +1334 -1254
- ml4gw/waveforms/phenom_p.py +779 -0
- ml4gw/waveforms/ringdown.py +110 -0
- ml4gw/waveforms/sine_gaussian.py +4 -5
- ml4gw/waveforms/taylorf2.py +297 -278
- {ml4gw-0.4.2.dist-info → ml4gw-0.5.0.dist-info}/METADATA +2 -1
- {ml4gw-0.4.2.dist-info → ml4gw-0.5.0.dist-info}/RECORD +14 -11
- {ml4gw-0.4.2.dist-info → ml4gw-0.5.0.dist-info}/WHEEL +0 -0
ml4gw/constants.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Various constants, all in SI units.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
EulerGamma = 0.577215664901532860606512090082402431
|
|
6
|
+
|
|
7
|
+
MSUN = 1.988409902147041637325262574352366540e30 # kg
|
|
8
|
+
"""Solar mass"""
|
|
9
|
+
|
|
10
|
+
MRSUN = 1.476625038050124729627979840144936351e3
|
|
11
|
+
"""Geometrized nominal solar mass, m"""
|
|
12
|
+
|
|
13
|
+
G = 6.67430e-11 # m^3 / kg / s^2
|
|
14
|
+
"""Newton's gravitational constant"""
|
|
15
|
+
|
|
16
|
+
C = 299792458.0 # m / s
|
|
17
|
+
"""Speed of light"""
|
|
18
|
+
|
|
19
|
+
"""Pi"""
|
|
20
|
+
PI = 3.141592653589793238462643383279502884
|
|
21
|
+
|
|
22
|
+
TWO_PI = 6.283185307179586476925286766559005768
|
|
23
|
+
|
|
24
|
+
gt = G * MSUN / (C**3.0)
|
|
25
|
+
"""
|
|
26
|
+
G MSUN / C^3 in seconds
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
MTSUN_SI = 4.925490947641266978197229498498379006e-6
|
|
30
|
+
"""1 solar mass in seconds. Same value as lal.MTSUN_SI"""
|
|
31
|
+
|
|
32
|
+
m_per_Mpc = 3.085677581491367278913937957796471611e22
|
|
33
|
+
"""
|
|
34
|
+
Meters per Mpc.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
MPC_SEC = m_per_Mpc / C
|
|
38
|
+
"""
|
|
39
|
+
1 Mpc in seconds.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
clightGpc = C / 3.0856778570831e22
|
|
43
|
+
"""
|
|
44
|
+
Speed of light in vacuum (:math:`c`), in gigaparsecs per second
|
|
45
|
+
"""
|
ml4gw/distributions.py
CHANGED
|
@@ -4,7 +4,7 @@ from specified distributions. Each callable should map from
|
|
|
4
4
|
an integer `N` to a 1D torch `Tensor` containing `N` samples
|
|
5
5
|
from the corresponding distribution.
|
|
6
6
|
"""
|
|
7
|
-
|
|
7
|
+
import math
|
|
8
8
|
from typing import Optional
|
|
9
9
|
|
|
10
10
|
import torch
|
|
@@ -21,14 +21,15 @@ class Cosine(dist.Distribution):
|
|
|
21
21
|
|
|
22
22
|
def __init__(
|
|
23
23
|
self,
|
|
24
|
-
low: float =
|
|
25
|
-
high: float =
|
|
24
|
+
low: float = -math.pi / 2,
|
|
25
|
+
high: float = math.pi / 2,
|
|
26
26
|
validate_args=None,
|
|
27
27
|
):
|
|
28
28
|
batch_shape = torch.Size()
|
|
29
29
|
super().__init__(batch_shape, validate_args=validate_args)
|
|
30
|
-
self.low = low
|
|
31
|
-
self.
|
|
30
|
+
self.low = torch.as_tensor(low)
|
|
31
|
+
self.high = torch.as_tensor(high)
|
|
32
|
+
self.norm = 1 / (torch.sin(self.high) - torch.sin(self.low))
|
|
32
33
|
|
|
33
34
|
def rsample(self, sample_shape: torch.Size = torch.Size()) -> torch.Tensor:
|
|
34
35
|
u = torch.rand(sample_shape, device=self.low.device)
|
|
@@ -48,13 +49,16 @@ class Sine(dist.TransformedDistribution):
|
|
|
48
49
|
|
|
49
50
|
def __init__(
|
|
50
51
|
self,
|
|
51
|
-
low: float =
|
|
52
|
-
high: float =
|
|
52
|
+
low: float = 0.0,
|
|
53
|
+
high: float = math.pi,
|
|
53
54
|
validate_args=None,
|
|
54
55
|
):
|
|
56
|
+
low = torch.as_tensor(low)
|
|
57
|
+
high = torch.as_tensor(high)
|
|
55
58
|
base_dist = Cosine(
|
|
56
59
|
low - torch.pi / 2, high - torch.pi / 2, validate_args
|
|
57
60
|
)
|
|
61
|
+
|
|
58
62
|
super().__init__(
|
|
59
63
|
base_dist,
|
|
60
64
|
[
|
|
@@ -153,12 +157,12 @@ class DeltaFunction(dist.Distribution):
|
|
|
153
157
|
|
|
154
158
|
def __init__(
|
|
155
159
|
self,
|
|
156
|
-
peak: float =
|
|
160
|
+
peak: float = 0.0,
|
|
157
161
|
validate_args=None,
|
|
158
162
|
):
|
|
159
163
|
batch_shape = torch.Size()
|
|
160
164
|
super().__init__(batch_shape, validate_args=validate_args)
|
|
161
|
-
self.peak = peak
|
|
165
|
+
self.peak = torch.as_tensor(peak)
|
|
162
166
|
|
|
163
167
|
def rsample(self, sample_shape: torch.Size = torch.Size()) -> torch.Tensor:
|
|
164
168
|
return self.peak * torch.ones(
|
ml4gw/nn/norm.py
CHANGED
|
@@ -32,6 +32,12 @@ class GroupNorm1D(torch.nn.Module):
|
|
|
32
32
|
self.bias = torch.nn.Parameter(torch.zeros(shape))
|
|
33
33
|
|
|
34
34
|
def forward(self, x):
|
|
35
|
+
if len(x.shape) != 3:
|
|
36
|
+
raise ValueError(
|
|
37
|
+
"GroupNorm1D requires 3-dimensional input, "
|
|
38
|
+
f"received {len(x.shape)} dimensional input"
|
|
39
|
+
)
|
|
40
|
+
|
|
35
41
|
keepdims = self.num_groups == self.num_channels
|
|
36
42
|
|
|
37
43
|
# compute group variance via the E[x**2] - E**2[x] trick
|
ml4gw/transforms/spectral.py
CHANGED
|
@@ -34,6 +34,10 @@ class SpectralDensity(torch.nn.Module):
|
|
|
34
34
|
average:
|
|
35
35
|
Aggregation method to use for combining windowed FFTs.
|
|
36
36
|
Allowed values are `"mean"` and `"median"`.
|
|
37
|
+
window:
|
|
38
|
+
Window array to multiply by each FFT window before
|
|
39
|
+
FFT computation. Should have length `nperseg`.
|
|
40
|
+
Defaults to a hanning window.
|
|
37
41
|
fast:
|
|
38
42
|
Whether to use a faster spectral density computation that
|
|
39
43
|
support cross spectral density, or a slower one which does
|
|
@@ -47,6 +51,7 @@ class SpectralDensity(torch.nn.Module):
|
|
|
47
51
|
fftlength: float,
|
|
48
52
|
overlap: Optional[float] = None,
|
|
49
53
|
average: str = "mean",
|
|
54
|
+
window: Optional[torch.Tensor] = None,
|
|
50
55
|
fast: bool = False,
|
|
51
56
|
) -> None:
|
|
52
57
|
if overlap is None:
|
|
@@ -63,11 +68,18 @@ class SpectralDensity(torch.nn.Module):
|
|
|
63
68
|
self.nperseg = int(fftlength * sample_rate)
|
|
64
69
|
self.nstride = self.nperseg - int(overlap * sample_rate)
|
|
65
70
|
|
|
66
|
-
#
|
|
67
|
-
#
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
# if no window is provided, default to a hanning window;
|
|
72
|
+
# validate that window is correct size
|
|
73
|
+
if window is None:
|
|
74
|
+
window = torch.hann_window(self.nperseg)
|
|
75
|
+
|
|
76
|
+
if window.size(0) != self.nperseg:
|
|
77
|
+
raise ValueError(
|
|
78
|
+
"Window must have length {} got {}".format(
|
|
79
|
+
self.nperseg, window.size(0)
|
|
80
|
+
)
|
|
81
|
+
)
|
|
82
|
+
self.register_buffer("window", window)
|
|
71
83
|
|
|
72
84
|
# scale corresponds to "density" normalization, worth
|
|
73
85
|
# considering adding this as a kwarg and changing this calc
|
ml4gw/utils/interferometer.py
CHANGED
|
@@ -35,6 +35,12 @@ class InterferometerGeometry:
|
|
|
35
35
|
self.vertex = torch.Tensor(
|
|
36
36
|
(4.54637409900e06, 8.42989697626e05, 4.37857696241e06)
|
|
37
37
|
)
|
|
38
|
+
elif name == "K1":
|
|
39
|
+
self.x_arm = torch.Tensor((-0.3759040, -0.8361583, 0.3994189))
|
|
40
|
+
self.y_arm = torch.Tensor((0.7164378, 0.01114076, 0.6975620))
|
|
41
|
+
self.vertex = torch.Tensor(
|
|
42
|
+
(-3777336.024, 3484898.411, 3765313.697)
|
|
43
|
+
)
|
|
38
44
|
else:
|
|
39
45
|
raise ValueError(
|
|
40
46
|
f"{name} is not recognized as an interferometer, "
|