Skip to content

Commit

Permalink
Fix check efficient and reformat test
Browse files Browse the repository at this point in the history
  • Loading branch information
IlhaH committed Jul 19, 2024
1 parent 8bfc1ba commit 68a53cc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
29 changes: 27 additions & 2 deletions python/python/bystro/covariance/hypothesis_hd.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,36 @@ def t_func(lambda_: np.ndarray, gamma: float, eta0: float) -> float:
)


def check_efficient(
gamma: float,
lambda1: np.ndarray,
lambda2: np.ndarray,
epsilon: float = 0.05,
) -> bool:
"""
Check if the splitting is efficient.
Parameters
----------
gamma : float
Gamma value.
lambda1 : np.ndarray
First array of eigenvalues.
lambda2 : np.ndarray
Second array of eigenvalues.
epsilon : float, optional
Tolerance value, by default 0.05.
Returns
-------
is_efficient : bool
True if efficient, False otherwise.
"""
range1 = abs(lambda1[0] - lambda1[-1])
range2 = abs(lambda2[0] - lambda2[-1])
return not (
max(abs(gamma - lambda1[0]), abs(gamma - lambda1[-1])) > range1 - epsilon
or max(abs(gamma - lambda2[0]), abs(gamma - lambda2[-1])) > range2 - epsilon
max(abs(gamma - lambda1[0]), abs(gamma - lambda1[-1]))
> range1 - epsilon
or max(abs(gamma - lambda2[0]), abs(gamma - lambda2[-1]))
> range2 - epsilon
)


Expand Down
16 changes: 12 additions & 4 deletions python/python/bystro/covariance/tests/test_hypothesis_hd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@


def test_sy2010():
with open("python/bystro/covariance/tests/hypothesis_hd_data.pkl", "rb") as f:
with open(
"python/bystro/covariance/tests/hypothesis_hd_data.pkl", "rb"
) as f:
data = pickle.load(f)
X = data["X"]
Y = data["Y"]
Expand All @@ -26,7 +28,9 @@ def test_sy2010():


def test_clx2013():
with open("python/bystro/covariance/tests/hypothesis_hd_data.pkl", "rb") as f:
with open(
"python/bystro/covariance/tests/hypothesis_hd_data.pkl", "rb"
) as f:
data = pickle.load(f)
X = data["X"]
Y = data["Y"]
Expand All @@ -43,7 +47,9 @@ def test_clx2013():


def test_hc2018():
with open("python/bystro/covariance/tests/hypothesis_hd_data.pkl", "rb") as f:
with open(
"python/bystro/covariance/tests/hypothesis_hd_data.pkl", "rb"
) as f:
data = pickle.load(f)
X = data["X"]
Y = data["Y"]
Expand Down Expand Up @@ -111,7 +117,9 @@ def test_hc2018():


def test_two_sample_test():
with open("python/bystro/covariance/tests/hypothesis_hd_data.pkl", "rb") as f:
with open(
"python/bystro/covariance/tests/hypothesis_hd_data.pkl", "rb"
) as f:
data = pickle.load(f)
X = data["X"]
Y = data["Y"]
Expand Down

0 comments on commit 68a53cc

Please sign in to comment.