Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fast kmerf #369

Merged
merged 13 commits into from
May 24, 2023
Prev Previous commit
Next Next commit
fix kmerf unit tests
  • Loading branch information
sampan501 committed May 17, 2023
commit 65229d26ae910c655a308317c531dbe592cc575e
14 changes: 12 additions & 2 deletions hyppo/independence/kmerf.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ def __init__(
self.distance_kwargs = distance_kwargs
if not compute_distance:
self.is_distance = True
if "is_ksamp" in kwargs.keys():
self.is_ksamp = True
self.k_sample_transform = kwargs["is_ksamp"]
kwargs.pop("is_ksamp")
if forest in FOREST_TYPES.keys():
self.clf = FOREST_TYPES[forest](n_estimators=ntrees, **kwargs)
else:
Expand Down Expand Up @@ -233,8 +237,14 @@ def test(self, x, y, reps=1000, workers=1, auto=True, random_state=None):
if auto and x.shape[0] > 20:
n = x.shape[0]
stat = self.statistic(x, y)
statx = self.statistic(x, x)
staty = self.statistic(y, y)
if self.is_ksamp:
xs = self.k_sample_transform([x, x], test_type="rf")
ys = self.k_sample_transform([y, y], test_type="rf")
else:
xs = (x, x)
ys = (y, y)
statx = self.statistic(*xs)
staty = self.statistic(*ys)
pvalue = chi2.sf(stat / np.sqrt(statx * staty) * n + 1, 1)
# pvalue = chi2.sf(stat * n + 1, 1)
self.stat = stat
Expand Down
2 changes: 2 additions & 0 deletions hyppo/ksample/ksamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ def test(self, *args, reps=1000, workers=1, auto=True, random_state=None):
kwargs = {}
if self.indep_test_name in ["dcorr", "hsic"]:
kwargs = {"auto": auto}
elif self.indep_test_name in ["kmerf"]:
kwargs = {"auto": auto, "is_ksamp": k_sample_transform}

return self.indep_test.test(
u, v, reps, workers, **kwargs, random_state=random_state
Expand Down
2 changes: 1 addition & 1 deletion hyppo/tools/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"disco": "fast",
"manova": "analytical",
"hotelling": "analytical",
"kmerf": "fast"
"kmerf": "fast",
}


Expand Down