Skip to content

Covariance

Analytic covariance API.

Exposes the joint one-sided cross-spectral density in closed form for the scaffold's placeholder statistical model (a frequency-independent equicorrelation structure). No Newtonian-noise or seismic physics is modelled here; the physical model is the joint backend in :mod:gwmock_newtonian_noise.joint.

Cross-spectral density convention

This is the canonical statement for the whole package; every other module links here. Every cross-spectral matrix the package returns, for a set of real channels x_a sampled at fs over N samples, is the one-sided density

C_ab(f) = (2 / (fs N)) E[X_a conj(X_b)],   X = numpy.fft.rfft(x),

i.e. Harms' convention <x~(f) y~*(f')> = 1/2 delta(f - f') S_xy(f) (Harms, Living Rev. Relativ. 22, 6 (2019), eqs. 274-275), also used by gwmock-noise. Consequences:

  • C is Hermitian and positive semidefinite per frequency; a Cholesky/eigen factor L with L L^H = C synthesizes X = L w and reproduces C.
  • A pure delay, x_b(t) = x_a(t - tau), gives C_ab = C_aa exp(+2 pi i f tau).
  • Real (isotropic, untimed) matrices are identical in the conjugate convention.

.. warning:: scipy.signal.csd(x_a, x_b) estimates E[conj(X_a) X_b], which in this convention is C_ba = conj(C_ab). Use scipy.signal.csd(x_b, x_a) to compare with C_ab. Results of versions before 0.2.0 used the scipy order; conjugate any stored complex matrix to migrate.

analytic_covariance(channel_order, coupling, sampling_frequency, grid_size=DEFAULT_GRID_SIZE)

Return the exact, closed-form one-sided cross-spectral density.

Every channel is temporally white in this scaffold model, so the returned matrix is frequency-independent: 2 * Sigma / sampling_frequency at every frequency, where Sigma is :func:equicorrelation_matrix. This is an exact analytic value, not a statistical estimate off a realization -- the same convention the public gwmock_noise dummy backend uses, so it can be tested against a closed-form value rather than a statistical one.

Parameters:

Name Type Description Default
channel_order list[str]

Channel names, in the order the returned matrix indexes its last two axes.

required
coupling float

Equicorrelation coefficient, 0.0 <= coupling < 1.0.

required
sampling_frequency float

Sampling frequency in hertz.

required
grid_size int

Number of one-sided frequency points to report.

DEFAULT_GRID_SIZE

Returns:

Type Description
JointCovariance

The joint one-sided cross-spectral density as a

JointCovariance

class:~gwmock_noise.JointCovariance.

Source code in src/gwmock_newtonian_noise/covariance.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def analytic_covariance(
    channel_order: list[str],
    coupling: float,
    sampling_frequency: float,
    grid_size: int = DEFAULT_GRID_SIZE,
) -> JointCovariance:
    """Return the exact, closed-form one-sided cross-spectral density.

    Every channel is temporally white in this scaffold model, so the returned
    matrix is frequency-independent: ``2 * Sigma / sampling_frequency`` at
    every frequency, where ``Sigma`` is :func:`equicorrelation_matrix`. This is
    an exact analytic value, not a statistical estimate off a realization --
    the same convention the public ``gwmock_noise`` dummy backend uses, so it
    can be tested against a closed-form value rather than a statistical one.

    Args:
        channel_order: Channel names, in the order the returned matrix indexes
            its last two axes.
        coupling: Equicorrelation coefficient, ``0.0 <= coupling < 1.0``.
        sampling_frequency: Sampling frequency in hertz.
        grid_size: Number of one-sided frequency points to report.

    Returns:
        The joint one-sided cross-spectral density as a
        :class:`~gwmock_noise.JointCovariance`.
    """
    sigma = equicorrelation_matrix(channel_order, coupling)
    frequencies = np.fft.rfftfreq(2 * (grid_size - 1), d=1.0 / sampling_frequency)
    psd_matrix = (2.0 / sampling_frequency) * sigma.astype(complex)
    matrix = np.broadcast_to(psd_matrix, (frequencies.size, *psd_matrix.shape)).copy()
    return JointCovariance(frequencies=frequencies, matrix=matrix, channel_order=list(channel_order))

equicorrelation_matrix(channel_order, coupling)

Return the per-sample covariance matrix for the scaffold's placeholder model.

Every off-diagonal entry is coupling and every diagonal entry is :data:SAMPLE_VARIANCE; positive definite for any channel count whenever 0.0 <= coupling < 1.0 (eigenvalues are 1 + (n - 1) * coupling with multiplicity 1 and 1 - coupling with multiplicity n - 1).

Parameters:

Name Type Description Default
channel_order list[str]

Channel names; only len(channel_order) is used.

required
coupling float

Equicorrelation coefficient, 0.0 <= coupling < 1.0.

required

Returns:

Type Description
ndarray

An (n, n) real, symmetric, positive-definite covariance matrix.

Source code in src/gwmock_newtonian_noise/covariance.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def equicorrelation_matrix(channel_order: list[str], coupling: float) -> np.ndarray:
    """Return the per-sample covariance matrix for the scaffold's placeholder model.

    Every off-diagonal entry is ``coupling`` and every diagonal entry is
    :data:`SAMPLE_VARIANCE`; positive definite for any channel count whenever
    ``0.0 <= coupling < 1.0`` (eigenvalues are ``1 + (n - 1) * coupling`` with
    multiplicity 1 and ``1 - coupling`` with multiplicity ``n - 1``).

    Args:
        channel_order: Channel names; only ``len(channel_order)`` is used.
        coupling: Equicorrelation coefficient, ``0.0 <= coupling < 1.0``.

    Returns:
        An ``(n, n)`` real, symmetric, positive-definite covariance matrix.
    """
    n = len(channel_order)
    matrix = np.full((n, n), coupling, dtype=float)
    np.fill_diagonal(matrix, SAMPLE_VARIANCE)
    return matrix