Skip to content

Commit

Permalink
Updated tests, UI, removed redundant import & latex from h_selection
Browse files Browse the repository at this point in the history
  • Loading branch information
rmj3197 committed Apr 29, 2024
1 parent 61ca4a8 commit 4f0648a
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 49 deletions.
3 changes: 0 additions & 3 deletions QuadratiK/kernel_test/_h_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import pandas as pd
from scipy.stats import skew, skewnorm
from sklearn.utils.parallel import Parallel, delayed
import matplotlib

usetex = matplotlib.checkdep_usetex(True)
import matplotlib.pyplot as plt

from ._utils import stat_ksample, stat_two_sample, stat_normality_test
Expand Down
19 changes: 15 additions & 4 deletions QuadratiK/ui/pages/1_Normality_Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,23 @@ def run_normality_test(h_val, num_iter, b, x):
res = pd.DataFrame()
res["Value"] = [
norm_test.test_type_,
norm_test.test_statistic_,
norm_test.cv_,
norm_test.h0_rejected_,
norm_test.un_test_statistic_,
norm_test.un_cv_,
norm_test.un_h0_rejected_,
norm_test.vn_test_statistic_,
norm_test.vn_cv_,
norm_test.vn_h0_rejected_,
]
res = res.set_axis(
["Test Type", "Test Statistic", "Critical Value", "Reject H0"]
[
"Test Type",
"Un Test Statistic",
"Un Critical Value",
"Un Reject H0",
"Vn Test Statistic",
"Vn Critical Value",
"Vn Reject H0",
]
)
st.table(res)
csv_res = res.to_csv().encode()
Expand Down
8 changes: 4 additions & 4 deletions QuadratiK/ui/pages/2_Two_Sample_Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ def run_twosample_test(h_val, num_iter, b, X, Y):
res = pd.DataFrame()
res["Value"] = [
two_sample_test.test_type_,
two_sample_test.test_statistic_,
two_sample_test.cv_,
two_sample_test.h0_rejected_,
two_sample_test.un_test_statistic_,
two_sample_test.un_cv_,
two_sample_test.un_h0_rejected_,
]
res = res.set_axis(
["Test Type", "Test Statistic", "Critical Value", "Reject H0"]
["Test Type", "Un Test Statistic", "Un Critical Value", "Un Reject H0"]
)

st.table(res)
Expand Down
13 changes: 8 additions & 5 deletions QuadratiK/ui/pages/3_K_Sample_Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,20 @@ def run_ksample_test(h_val, num_iter, b, X, y):
res = pd.DataFrame()
res["Value"] = [
k_samp_test.test_type_,
k_samp_test.test_statistic_,
k_samp_test.cv_,
k_samp_test.h0_rejected_,
k_samp_test.un_test_statistic_,
k_samp_test.un_cv_,
k_samp_test.un_h0_rejected_,
k_samp_test.vn_test_statistic_,
k_samp_test.vn_cv_,
k_samp_test.vn_h0_rejected_,
]
res = res.set_axis(
["Test Type", "Test Statistic", "Critical Value", "Reject H0"]
["Test Type", "Un Test Statistic", "Un Critical Value", "Un Reject H0","Vn Test Statistic", "Vn Critical Value", "Vn Reject H0"]
)
st.table(res)
csv_res = res.to_csv().encode()
st.download_button(
"Click to Download the test results",
"Click to download the test results",
csv_res,
"K_Sample_Test_results.csv",
"text/csv",
Expand Down
2 changes: 0 additions & 2 deletions QuadratiK/ui/pages/4_Tuning_Parameter_h_Selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import importlib
import matplotlib.pyplot as plt

plt.rcParams["text.usetex"] = True

select_h = importlib.import_module("QuadratiK.kernel_test").select_h

st.title("Tuning Parameter h selection")
Expand Down
24 changes: 12 additions & 12 deletions doc/source/user_guide/basic_usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
"normality_test = KernelTest(h=0.4, centering_type=\"param\", random_state=42).test(data)\n",
"print(\"Test : {}\".format(normality_test.test_type_))\n",
"print(\"Execution time: {:.3f}\".format(normality_test.execution_time))\n",
"print(\"H0 is Rejected : {}\".format(normality_test.h0_rejected_))\n",
"print(\"Test Statistic : {}\".format(normality_test.test_statistic_))\n",
"print(\"Critical Value (CV) : {}\".format(normality_test.cv_))\n",
"print(\"H0 is Rejected : {}\".format(normality_test.un_h0_rejected_))\n",
"print(\"Test Statistic : {}\".format(normality_test.un_test_statistic_))\n",
"print(\"Critical Value (CV) : {}\".format(normality_test.un_cv_))\n",
"print(\"CV Method : {}\".format(normality_test.cv_method_))\n",
"print(\"Selected tuning parameter : {}\".format(normality_test.h))"
]
Expand Down Expand Up @@ -87,9 +87,9 @@
"normality_test = KernelTest(h=0.4, centering_type=\"nonparam\").test(data)\n",
"print(\"Test : {}\".format(normality_test.test_type_))\n",
"print(\"Execution time: {:.3f}\".format(normality_test.execution_time))\n",
"print(\"H0 is Rejected : {}\".format(normality_test.h0_rejected_))\n",
"print(\"Test Statistic : {}\".format(normality_test.test_statistic_))\n",
"print(\"Critical Value (CV) : {}\".format(normality_test.cv_))\n",
"print(\"H0 is Rejected : {}\".format(normality_test.un_h0_rejected_))\n",
"print(\"Test Statistic : {}\".format(normality_test.un_test_statistic_))\n",
"print(\"Critical Value (CV) : {}\".format(normality_test.un_cv_))\n",
"print(\"CV Method : {}\".format(normality_test.cv_method_))\n",
"print(\"Selected tuning parameter : {}\".format(normality_test.h))"
]
Expand Down Expand Up @@ -149,9 +149,9 @@
"two_sample_test = KernelTest(h=0.4, random_state=42).test(X, Y)\n",
"print(\"Test : {}\".format(two_sample_test.test_type_))\n",
"print(\"Execution time: {:.3f}\".format(two_sample_test.execution_time))\n",
"print(\"H0 is Rejected : {}\".format(two_sample_test.h0_rejected_))\n",
"print(\"Test Statistic : {}\".format(two_sample_test.test_statistic_))\n",
"print(\"Critical Value (CV) : {}\".format(two_sample_test.cv_))\n",
"print(\"H0 is Rejected : {}\".format(two_sample_test.un_h0_rejected_))\n",
"print(\"Test Statistic : {}\".format(two_sample_test.un_test_statistic_))\n",
"print(\"Critical Value (CV) : {}\".format(two_sample_test.un_cv_))\n",
"print(\"CV Method : {}\".format(two_sample_test.cv_method_))\n",
"print(\"Selected tuning parameter : {}\".format(two_sample_test.h))"
]
Expand Down Expand Up @@ -195,9 +195,9 @@
"\n",
"print(\"Test : {}\".format(k_sample_test.test_type_))\n",
"print(\"Execution time: {:.3f} seconds\".format(k_sample_test.execution_time))\n",
"print(\"H0 is Rejected : {}\".format(k_sample_test.h0_rejected_))\n",
"print(\"Test Statistic : {}\".format(k_sample_test.test_statistic_))\n",
"print(\"Critical Value (CV) : {}\".format(k_sample_test.cv_))\n",
"print(\"H0 is Rejected : {}\".format(k_sample_test.un_h0_rejected_))\n",
"print(\"Test Statistic : {}\".format(k_sample_test.un_test_statistic_))\n",
"print(\"Critical Value (CV) : {}\".format(k_sample_test.un_cv_))\n",
"print(\"CV Method : {}\".format(k_sample_test.cv_method_))\n",
"print(\"Selected tuning parameter : {}\".format(k_sample_test.h))"
]
Expand Down
38 changes: 19 additions & 19 deletions tests/test_kernel_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ def test_normality(self):
dataframe_x = pd.DataFrame(x)
normality_test_numpy = KernelTest(h=0.5, random_state=42).test(x)
normality_test_dataframe = KernelTest(h=0.5, random_state=42).test(dataframe_x)
self.assertFalse(normality_test_numpy.h0_rejected_)
self.assertTrue(isinstance(normality_test_numpy.test_statistic_, (int, float)))
self.assertFalse(normality_test_dataframe.h0_rejected_)
self.assertFalse(normality_test_numpy.un_h0_rejected_)
self.assertTrue(isinstance(normality_test_numpy.un_test_statistic_, (int, float)))
self.assertFalse(normality_test_dataframe.un_h0_rejected_)
self.assertTrue(
isinstance(normality_test_dataframe.test_statistic_, (int, float))
isinstance(normality_test_dataframe.un_test_statistic_, (int, float))
)
self.assertEqual(
normality_test_numpy.h0_rejected_, normality_test_dataframe.h0_rejected_
normality_test_numpy.un_h0_rejected_, normality_test_dataframe.un_h0_rejected_
)
self.assertEqual(
normality_test_numpy.test_statistic_,
normality_test_dataframe.test_statistic_,
normality_test_numpy.un_test_statistic_,
normality_test_dataframe.un_test_statistic_,
)

with self.assertRaises(ValueError):
Expand All @@ -44,8 +44,8 @@ def test_normality(self):
normality_test_1d = KernelTest(
method="subsampling", b=0.5, random_state=42, alternative="scale"
).test(x_1d)
self.assertFalse(normality_test_1d.h0_rejected_)
self.assertTrue(isinstance(normality_test_1d.test_statistic_, (int, float)))
self.assertFalse(normality_test_1d.un_h0_rejected_)
self.assertTrue(isinstance(normality_test_1d.un_test_statistic_, (int, float)))

def test_twosample(self):
x = np.random.randn(100, 2)
Expand All @@ -55,9 +55,9 @@ def test_twosample(self):
two_sample_test_subsampling = KernelTest(
h=1.5, method="subsampling", b=0.5, random_state=42
).test(x, y)
self.assertTrue(two_sample_test_subsampling.h0_rejected_)
self.assertTrue(two_sample_test_subsampling.un_h0_rejected_)
self.assertTrue(
isinstance(two_sample_test_subsampling.test_statistic_, (int, float))
isinstance(two_sample_test_subsampling.un_test_statistic_, (int, float))
)

with self.assertRaises(ValueError):
Expand All @@ -79,9 +79,9 @@ def test_twosample(self):
centering_type="param",
random_state=42,
).test(x, y)
self.assertTrue(two_sample_test_h_selection.h0_rejected_)
self.assertTrue(two_sample_test_h_selection.un_h0_rejected_)
self.assertTrue(
isinstance(two_sample_test_h_selection.test_statistic_, (int, float))
isinstance(two_sample_test_h_selection.un_test_statistic_, (int, float))
)

def test_ksample(self):
Expand All @@ -94,20 +94,20 @@ def test_ksample(self):
k_sample_test = KernelTest(
h=1.5, method="subsampling", b=0.5, random_state=42
).test(x, y)
self.assertFalse(k_sample_test.h0_rejected_)
self.assertTrue(isinstance(k_sample_test.test_statistic_, np.ndarray))
self.assertFalse(k_sample_test.un_h0_rejected_)
self.assertTrue(isinstance(k_sample_test.un_test_statistic_, np.ndarray))

k_sample_test_without_h = KernelTest(
method="subsampling", b=0.5, random_state=42, alternative="location"
).test(x, y)
self.assertFalse(k_sample_test_without_h.h0_rejected_)
self.assertTrue(isinstance(k_sample_test_without_h.test_statistic_, np.ndarray))
self.assertFalse(k_sample_test_without_h.un_h0_rejected_)
self.assertTrue(isinstance(k_sample_test_without_h.un_test_statistic_, np.ndarray))

k_sample_test_1d = KernelTest(
h=1.5, method="subsampling", b=0.5, random_state=42
).test(x_1d, y_dataframe)
self.assertFalse(k_sample_test_1d.h0_rejected_)
self.assertTrue(isinstance(k_sample_test_1d.test_statistic_, np.ndarray))
self.assertFalse(k_sample_test_1d.un_h0_rejected_)
self.assertTrue(isinstance(k_sample_test_1d.un_test_statistic_, np.ndarray))

with self.assertRaises(ValueError):
KernelTest(h=1.5, method="subsampling", b=0.5, random_state=42).test(
Expand Down

0 comments on commit 4f0648a

Please sign in to comment.