Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions meegkit/utils/covariances.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
unsqueeze,
)

rng = np.random.default_rng()


def block_covariance(data, window=128, overlap=0.5, padding=True, estimator="cov"):
"""Compute blockwise covariance.
Expand Down Expand Up @@ -486,9 +484,9 @@ def ehess(X, U):
alpha * np.diagflat(mldivide(L, rhoX)) @ U
return h

# Initialization as suggested in above referenced paper.
# randomly generate starting point for svd
x = rng.standard_normal((n, k))
# Initialization as suggested in above referenced paper. Use a fixed seed
# so results are reproducible (the starting point only affects convergence).
x = np.random.default_rng(1468432035).standard_normal((n, k))
[U, S, V] = linalg.svd(x, full_matrices=False)
x = U.dot(V.T)
S0, U0 = linalg.eig(
Expand Down
11 changes: 11 additions & 0 deletions tests/test_cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@
from numpy.testing import assert_almost_equal

from meegkit.utils import convmtx, tscov, tsxcov
from meegkit.utils.covariances import nonlinear_eigenspace

rng = np.random.default_rng(10)


def test_nonlinear_eigenspace_reproducible():
"""nonlinear_eigenspace returns identical results across calls."""
A = rng.standard_normal((6, 6))
L = A @ A.T + np.eye(6)
d1, v1 = nonlinear_eigenspace(L, 6)
d2, v2 = nonlinear_eigenspace(L, 6)
np.testing.assert_array_equal(np.real(d1), np.real(d2))
np.testing.assert_array_equal(v1, v2)

def test_tscov():
"""Test time-shift covariance."""
x = 2 * np.eye(3) + 0.1 * rng.random(3)
Expand Down
Loading