Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmj3197 committed Mar 11, 2024
1 parent 86b7470 commit ab59d49
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 9 deletions.
Binary file removed .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,5 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.vscode/
htmlcov/
htmlcov/
.DS_Store
Binary file removed QuadratiK/.DS_Store
Binary file not shown.
Binary file removed QuadratiK/datasets/.DS_Store
Binary file not shown.
Binary file removed QuadratiK/datasets/data/.DS_Store
Binary file not shown.
4 changes: 2 additions & 2 deletions QuadratiK/kernel_test/_h_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def select_h(
elif isinstance(y, pd.DataFrame):
y = y.values
else:
raise ValueError(
raise TypeError(
"y must be a list, numpy.ndarray, \
or a pandas DataFrame with one column (for k-sample case) or more"
)
Expand All @@ -563,7 +563,7 @@ def select_h(
elif alternative == "skewness":
delta = np.array([0.2, 0.3, 0.6])

if alternative is None:
if (alternative is None) or (alternative not in ["location","scale","skewness"]):
raise ValueError(
"Please specify alternative from 'location', 'scale' or 'skewness'"
)
Expand Down
Binary file removed QuadratiK/ui/.DS_Store
Binary file not shown.
Binary file removed doc/.DS_Store
Binary file not shown.
Binary file removed doc/build/.DS_Store
Binary file not shown.
Binary file removed doc/source/.DS_Store
Binary file not shown.
Binary file removed tests/.DS_Store
Binary file not shown.
104 changes: 99 additions & 5 deletions tests/test_select_h.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
import numpy as np
import pandas as pd
from QuadratiK.kernel_test import select_h


Expand All @@ -11,6 +12,7 @@ def test_select_h_one_sample_skewness(self):
x=x, alternative="skewness", random_state=42, power_plot=True
)
self.assertIsInstance(h_sel, (int, float))
self.assertIsInstance(all_powers, pd.DataFrame)
self.assertIsNotNone(plot)

def test_select_h_one_sample_location(self):
Expand All @@ -20,6 +22,7 @@ def test_select_h_one_sample_location(self):
x=x, alternative="location", random_state=42, power_plot=True
)
self.assertIsInstance(h_sel, (int, float))
self.assertIsInstance(all_powers, pd.DataFrame)
self.assertIsNotNone(plot)

def test_select_h_one_sample_scale(self):
Expand All @@ -29,8 +32,9 @@ def test_select_h_one_sample_scale(self):
x=x, alternative="scale", random_state=42, power_plot=True
)
self.assertIsInstance(h_sel, (int, float))
self.assertIsInstance(all_powers, pd.DataFrame)
self.assertIsNotNone(plot)

def test_select_h_two_sample_skewness(self):
np.random.seed(42)
x = np.random.randn(200, 2)
Expand All @@ -40,6 +44,7 @@ def test_select_h_two_sample_skewness(self):
x=x, y=y, alternative="skewness", random_state=42, power_plot=True
)
self.assertIsInstance(h_sel, (int, float))
self.assertIsInstance(all_powers, pd.DataFrame)
self.assertIsNotNone(plot)

def test_select_h_two_sample_location(self):
Expand All @@ -51,6 +56,7 @@ def test_select_h_two_sample_location(self):
x=x, y=y, alternative="location", random_state=42, power_plot=True
)
self.assertIsInstance(h_sel, (int, float))
self.assertIsInstance(all_powers, pd.DataFrame)
self.assertIsNotNone(plot)

def test_select_h_two_sample_scale(self):
Expand All @@ -62,25 +68,113 @@ def test_select_h_two_sample_scale(self):
x=x, y=y, alternative="scale", random_state=42, power_plot=True
)
self.assertIsInstance(h_sel, (int, float))
self.assertIsInstance(all_powers, pd.DataFrame)
self.assertIsNotNone(plot)

def test_select_h_k_sample_location(self):
np.random.seed(42)
x = np.random.randn(100 * 3, 2)
y = np.repeat(np.arange(1, 4), repeats=100)
h_sel, all_powers = select_h(x=x, y=y, alternative="location", random_state=42)
h_sel, all_powers, plot = select_h(
x=x, y=y, alternative="location", random_state=42, power_plot=True
)
self.assertIsInstance(all_powers, pd.DataFrame)
self.assertIsInstance(h_sel, (int, float))
self.assertIsNotNone(plot)

def test_select_h_k_sample_skewness(self):
np.random.seed(42)
x = np.random.randn(100 * 3, 2)
y = np.repeat(np.arange(1, 4), repeats=100)
h_sel, all_powers = select_h(x=x, y=y, alternative="skewness", random_state=42)
h_sel, all_powers, plot = select_h(
x=x, y=y, alternative="skewness", random_state=42, power_plot=True
)
self.assertIsInstance(all_powers, pd.DataFrame)
self.assertIsInstance(h_sel, (int, float))
self.assertIsNotNone(plot)

def test_select_h_k_sample_scale(self):
np.random.seed(42)
x = np.random.randn(100 * 3, 2)
x = np.random.randn(100 * 3, 3)
y = np.repeat(np.arange(1, 4), repeats=100)
h_sel, all_powers = select_h(x=x, y=y, alternative="scale", random_state=42)
h_sel, all_powers, plot = select_h(
x=x, y=y, alternative="scale", random_state=42, power_plot=True
)
self.assertIsInstance(all_powers, pd.DataFrame)
self.assertIsInstance(h_sel, (int, float))
self.assertIsNotNone(plot)

def test_select_h_inputs(self):
x = pd.DataFrame(np.random.randn(100 * 3, 1))
y = pd.DataFrame(np.repeat(np.arange(1, 4), repeats=100))

with self.assertRaises(ValueError):
select_h(x=x, y=y, alternative="scale", random_state=[42], power_plot=True)

with self.assertRaises(TypeError):
x_list = [1, 2, 3, 4]
y_list = [1,1,2,2]
select_h(
x=x_list,
y=y_list,
alternative="scale",
random_state=42,
power_plot=True,
)

with self.assertRaises(TypeError):
x_df = pd.DataFrame(np.random.randn(100,2))
y_int = -1
select_h(
x=x_df,
y=y_int,
alternative="scale",
random_state=42,
power_plot=True,
)

with self.assertRaises(ValueError):
select_h(x=x, y=y, alternative="some", random_state=42, power_plot=True)

with self.assertRaises(ValueError):
select_h(
x=x,
y=y,
alternative="scale",
random_state=42,
power_plot=True,
delta_dim=[1, 1],
)

with self.assertRaises(ValueError):
x = (np.random.randn(100 * 3, 1))
select_h(
x=x,
y=None,
alternative="scale",
random_state=42,
power_plot=True,
delta_dim=[1, 1],
)

with self.assertRaises(ValueError):
x_two_sample = pd.DataFrame(np.random.randn(100 * 3, 5))
y_two_sample = pd.DataFrame(np.random.randn(100 * 3, 3))
select_h(
x=x_two_sample,
y=y_two_sample,
alternative="scale",
random_state=42,
power_plot=True,
)
with self.assertRaises(ValueError):
x_two_sample = pd.DataFrame(np.random.randn(100 * 3, 3))
y_two_sample = pd.DataFrame(np.random.randn(100 * 3, 3))
select_h(
x=x_two_sample,
y=y_two_sample,
alternative="scale",
random_state=42,
power_plot=True,
delta_dim=[1,1]
)
10 changes: 9 additions & 1 deletion tests/test_uniformity_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ def test_uniformity_test(self):
x_sp = dat / np.linalg.norm(dat)
uniformity_test = PoissonKernelTest(rho=0.8, random_state=42).test(x_sp)
self.assertIsInstance(uniformity_test.u_statistic_un_, (int, float))
self.assertIsInstance(uniformity_test.u_statistic_cv_ ,(int, float))
self.assertIsInstance(uniformity_test.u_statistic_h0_, np.bool_)
self.assertIsInstance(uniformity_test.v_statistic_vn_, (int, float))

self.assertIsInstance(uniformity_test.stats(), pd.DataFrame)
self.assertIsInstance(uniformity_test.summary(print_fmt="html"), str)
self.assertIsInstance(uniformity_test.summary(), str)
Expand All @@ -34,8 +37,13 @@ def test_uniformity_test(self):
x = [1, 2, 3, 4, 5]
PoissonKernelTest(rho=0.8, random_state=42).test(x)


def test_uniformity_no_rndm_state_dataframe(self):
x_sp = pd.DataFrame(sample_hypersphere(npoints=100, ndim=3))
uniformity_test = PoissonKernelTest(rho=0.8, random_state=None).test(x_sp)
uniformity_test = PoissonKernelTest(
rho=0.8, random_state=None, num_iter=10, n_jobs=4
).test(x_sp)
self.assertIsInstance(uniformity_test.u_statistic_un_, (int, float))
self.assertIsInstance(uniformity_test.v_statistic_vn_, (int, float))
self.assertIsInstance(uniformity_test.u_statistic_cv_ ,(int, float))
self.assertIsInstance(uniformity_test.v_statistic_h0_, np.bool_)

0 comments on commit ab59d49

Please sign in to comment.