Skip to content

Commit 3c68f62

Browse files
fix: ruff import order + drop unused import; correct the gamma test invariant
- ruff: SchurLedoitWolf import sorts before schurcov in __init__/registry; remove unused pytest import in the new test. - the previous 'gamma rises with n' test asserted a false property for an EWA estimator (effective sample ~1/r, not n, so gamma converges/forgets rather than climbing with n). Replace with the correct invariants: gamma rises with cross-block coupling STRENGTH and as the decay r shrinks (larger effective sample). Verified: ruff, mypy, pytest (204) all pass.
1 parent 8606f4f commit 3c68f62

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

precise/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
from precise.partialmoments import PartialMomentsCovariance
3737
from precise.recommend import covariance_features, suggest
3838
from precise.registry import all_estimators, estimator_from_name, estimator_names
39-
from precise.schurcov import SchurCovariance
4039
from precise.schur_ledoit_wolf import SchurLedoitWolfCovariance
40+
from precise.schurcov import SchurCovariance
4141
from precise.shrunk import ShrunkCovariance
4242
from precise.tyler import TylerCovariance
4343

precise/registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
from precise.ledoitwolf import LedoitWolfCovariance
2020
from precise.oas import OASCovariance
2121
from precise.partialmoments import PartialMomentsCovariance
22-
from precise.schurcov import SchurCovariance
2322
from precise.schur_ledoit_wolf import SchurLedoitWolfCovariance
23+
from precise.schurcov import SchurCovariance
2424
from precise.shrunk import ShrunkCovariance
2525
from precise.tyler import TylerCovariance
2626

tests/test_schur_ledoit_wolf.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from __future__ import annotations
99

1010
import numpy as np
11-
import pytest
1211

1312
from precise import SchurLedoitWolfCovariance, all_estimators
1413

@@ -33,15 +32,23 @@ def test_gamma_in_unit_interval_and_pd():
3332
assert np.all(np.linalg.eigvalsh(C) > 0)
3433

3534

36-
def test_gamma_rises_with_sample_size_when_coupling_is_real():
37-
# more data => the cross-block coupling becomes more reliable => larger gamma_
38-
gammas = []
39-
for n in (300, 3000):
40-
e = SchurLedoitWolfCovariance(n_blocks=3, r=0.005)
41-
e.partial_fit(_block_data(n, seed=1))
42-
_ = e.covariance_
43-
gammas.append(e.gamma_)
44-
assert gammas[1] > gammas[0]
35+
def _gamma(cross, r=0.02, n=2000):
36+
e = SchurLedoitWolfCovariance(n_blocks=3, r=r)
37+
e.partial_fit(_block_data(n, within=0.7, cross=cross, seed=1))
38+
_ = e.covariance_
39+
return e.gamma_
40+
41+
42+
def test_gamma_rises_with_coupling_strength():
43+
# stronger true cross-block coupling => higher reliability => larger gamma_
44+
# (the right invariant for an EWA estimator, whose effective sample is ~1/r, not n)
45+
g = [_gamma(c) for c in (0.0, 0.1, 0.3, 0.6)]
46+
assert g[0] < g[1] < g[2] < g[3]
47+
48+
49+
def test_gamma_rises_as_decay_shrinks():
50+
# smaller r => larger effective sample => the coupling is more reliably estimated
51+
assert _gamma(0.5, r=0.05) < _gamma(0.5, r=0.005)
4552

4653

4754
def test_gamma_low_when_coupling_is_noise():

0 commit comments

Comments
 (0)