ml4gw.distributions

Module containing callables classes for generating samples from specified distributions. Each callable should map from an integer N to a 1D torch Tensor containing N samples from the corresponding distribution.

Classes

Cosine([low, high, validate_args])

Cosine distribution based on torch.distributions.TransformedDistribution (see documentation).

DeltaFunction([peak, validate_args])

LogNormal(mean, std[, low, validate_args])

LogUniform(low, high[, validate_args])

Sample from a log uniform distribution

PowerLaw(minimum, maximum, index[, ...])

Sample from a power law distribution,

RateEvolution(rate_function, *args, **kwargs)

Wrapper around UniformComovingVolume() to allow for arbitrary rate evolution functions.

Sine([low, high, validate_args])

Sine distribution based on torch.distributions.TransformedDistribution.

UniformComovingVolume(minimum, maximum[, ...])

Sample either redshift, comoving distance, or luminosity distance such that they are uniform in comoving volume, assuming a flat lambda-CDM cosmology.

class ml4gw.distributions.Cosine(low=-1.5707963267948966, high=1.5707963267948966, validate_args=None)

Bases: Distribution

Cosine distribution based on torch.distributions.TransformedDistribution (see documentation).

Parameters:
  • low (float)

  • high (float)

arg_constraints = {}
log_prob(value)
Return type:

Float[Tensor, '']

Parameters:

value (float)

rsample(sample_shape=None)
Return type:

Tensor

Parameters:

sample_shape (Size | None)

class ml4gw.distributions.DeltaFunction(peak=0.0, validate_args=None)

Bases: Distribution

Parameters:

peak (float)

arg_constraints = {}
rsample(sample_shape=None)
Return type:

Tensor

Parameters:

sample_shape (Size | None)

class ml4gw.distributions.LogNormal(mean, std, low=None, validate_args=None)

Bases: LogNormal

Parameters:
  • mean (float)

  • std (float)

  • low (float | None)

support()
class ml4gw.distributions.LogUniform(low, high, validate_args=None)

Bases: TransformedDistribution

Sample from a log uniform distribution

Parameters:
  • low (float)

  • high (float)

class ml4gw.distributions.PowerLaw(minimum, maximum, index, validate_args=None)

Bases: TransformedDistribution

Sample from a power law distribution,

\[p(x) \approx x^{\alpha}.\]

Index alpha cannot be 0, since it is equivalent to a Uniform distribution. This could be used, for example, as a universal distribution of signal-to-noise ratios (SNRs) from uniformly volume distributed sources

\[p(\rho) = 3\;\rho_0^3 / \rho^4\]

where \(\rho_0\) is a representative minimum SNR considered for detection. See, for example, Schutz (2011). Or, for example, index=2 for uniform in Euclidean volume.

Parameters:
  • minimum (float)

  • maximum (float)

  • index (float)

support = GreaterThanEq(lower_bound=0.0)
class ml4gw.distributions.RateEvolution(rate_function, *args, **kwargs)

Bases: UniformComovingVolume

Wrapper around UniformComovingVolume() to allow for arbitrary rate evolution functions. E.g., if rate_function = lambda z: 1 / (1 + z), then the distribution will sample values such that they occur uniform in source frame time.

Parameters:
  • rate_function (Callable) -- Callable that takes redshift as input and returns the rate evolution factor.

  • *args -- Arguments passed to UniformComovingVolume() constructor.

  • **kwargs -- Keyword arguments passed to UniformComovingVolume() constructor.

class ml4gw.distributions.Sine(low=0.0, high=3.141592653589793, validate_args=None)

Bases: TransformedDistribution

Sine distribution based on torch.distributions.TransformedDistribution.

Parameters:
  • low (float)

  • high (float)

class ml4gw.distributions.UniformComovingVolume(minimum, maximum, distance_type='redshift', h0=67.66, omega_m=0.30966, z_grid_max=5, grid_size=10000, validate_args=None)

Bases: Distribution

Sample either redshift, comoving distance, or luminosity distance such that they are uniform in comoving volume, assuming a flat lambda-CDM cosmology. Default H0 and Omega_M values match Planck18 parameters in Astropy.

Parameters:
  • minimum (float) -- Minimum distance in the specified distance type

  • maximum (float) -- Maximum distance in the specified distance type

  • distance_type (str) -- Type of distance to sample from. Can be redshift, comoving_distance, or luminosity_distance

  • h0 (float) -- Hubble constant in km/s/Mpc

  • omega_m (float) -- Matter density parameter

  • z_max -- Maximum redshift for the grid

  • grid_size (int) -- Number of points in the grid for interpolation

  • validate_args (Optional[bool]) -- Whether to validate arguments

  • z_grid_max (float)

arg_constraints = {}
log_prob(value)
Return type:

Tensor

Parameters:

value (Tensor)

rsample(sample_shape=None)
Return type:

Tensor

Parameters:

sample_shape (Size | None)

support = GreaterThanEq(lower_bound=0.0)