-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from OliverSchacht/causallearn-pr
Add two variants of the KCI test
- Loading branch information
Showing
8 changed files
with
1,069 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import unittest | ||
|
||
import numpy as np | ||
|
||
import causallearn.utils.cit as cit | ||
|
||
|
||
class TestCIT_FastKCI(unittest.TestCase): | ||
def test_Gaussian_dist(self): | ||
np.random.seed(10) | ||
X = np.random.randn(1200, 1) | ||
X_prime = np.random.randn(1200, 1) | ||
Y = X + 0.5 * np.random.randn(1200, 1) | ||
Z = Y + 0.5 * np.random.randn(1200, 1) | ||
data = np.hstack((X, X_prime, Y, Z)) | ||
|
||
pvalue01 = [] | ||
pvalue03 = [] | ||
pvalue032 = [] | ||
for K in [3, 10]: | ||
for J in [8, 16]: | ||
for use_gp in [True, False]: | ||
cit_CIT = cit.CIT(data, 'fastkci', K=K, J=J, use_gp=use_gp) | ||
pvalue01.append(round(cit_CIT(0, 1), 4)) | ||
pvalue03.append(round(cit_CIT(0, 3), 4)) | ||
pvalue032.append(round(cit_CIT(0, 3, {2}), 4)) | ||
|
||
pvalue01 = np.array(pvalue01) | ||
pvalue03 = np.array(pvalue03) | ||
pvalue032 = np.array(pvalue032) | ||
self.assertTrue(np.all((0.0 <= pvalue01) & (pvalue01 <= 1.0)), | ||
"pvalue01 contains invalid values") | ||
self.assertTrue(np.all((0.0 <= pvalue03) & (pvalue03 <= 1.0)), | ||
"pvalue03 contains invalid values") | ||
self.assertTrue(np.all((0.0 <= pvalue032) & (pvalue032 <= 1.0)), | ||
"pvalue032 contains invalid values") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import unittest | ||
|
||
import numpy as np | ||
|
||
import causallearn.utils.cit as cit | ||
|
||
|
||
class TestCIT_RCIT(unittest.TestCase): | ||
def test_Gaussian_dist(self): | ||
np.random.seed(10) | ||
X = np.random.randn(300, 1) | ||
X_prime = np.random.randn(300, 1) | ||
Y = X + 0.5 * np.random.randn(300, 1) | ||
Z = Y + 0.5 * np.random.randn(300, 1) | ||
data = np.hstack((X, X_prime, Y, Z)) | ||
|
||
pvalue01 = [] | ||
pvalue03 = [] | ||
pvalue032 = [] | ||
for approx in ["lpd4", "hbe", "gamma", "chi2", "perm"]: | ||
for num_f in [50, 100]: | ||
for num_f2 in [5, 10]: | ||
for rcit in [True, False]: | ||
cit_CIT = cit.CIT(data, 'rcit', approx=approx, num_f=num_f, | ||
num_f2=num_f2, rcit=rcit) | ||
pvalue01.append(round(cit_CIT(0, 1), 4)) | ||
pvalue03.append(round(cit_CIT(0, 3), 4)) | ||
pvalue032.append(round(cit_CIT(0, 3, {2}), 4)) | ||
|
||
pvalue01 = np.array(pvalue01) | ||
pvalue03 = np.array(pvalue03) | ||
pvalue032 = np.array(pvalue032) | ||
self.assertTrue(np.all((0.0 <= pvalue01) & (pvalue01 <= 1.0)), | ||
"pvalue01 contains invalid values") | ||
self.assertTrue(np.all((0.0 <= pvalue03) & (pvalue03 <= 1.0)), | ||
"pvalue03 contains invalid values") | ||
self.assertTrue(np.all((0.0 <= pvalue032) & (pvalue032 <= 1.0)), | ||
"pvalue032 contains invalid values") |