Skip to content

Commit 861c29e

Browse files
committed
Updated the usage of CIT calling
1 parent 64e58b1 commit 861c29e

File tree

5 files changed

+101
-18
lines changed

5 files changed

+101
-18
lines changed

docs/source/independence_tests_index/chisq.rst

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,29 @@ Chi-Square test
55

66
Perform an independence test on discrete variables using Chi-Square test.
77

8-
(We have updated the independence test class and the usage example hasn't been updated yet. For new class, please refer to `TestCIT.py <https://github.com/cmu-phil/causal-learn/blob/main/tests/TestCIT.py>`_ or `TestCIT_KCI.py <https://github.com/cmu-phil/causal-learn/blob/main/tests/TestCIT_KCI.py>`_.)
9-
108
Usage
119
--------
1210
.. code-block:: python
1311
12+
from causallearn.utils.cit import CIT
13+
chisq_obj = CIT(data, "chisq") # construct a CIT instance with data and method name
14+
pValue = chisq_obj(X, Y, S)
15+
16+
Please be kindly informed that we have refactored the independence tests from functions to classes since the release `v0.1.2.8 <https://github.com/cmu-phil/causal-learn/releases/tag/0.1.2.8>`_. Speed gain and a more flexible parameters specification are enabled.
17+
18+
For users, you may need to adjust your codes accordingly. Specifically, if you are
19+
20+
+ running a constraint-based algorithm from end to end: then you don't need to change anything. Old codes are still compatible. For example,
21+
.. code-block:: python
22+
23+
from causallearn.search.ConstraintBased.PC import pc
1424
from causallearn.utils.cit import chisq
15-
p = chisq(data, X, Y, conditioning_set)
25+
cg = pc(data, 0.05, chisq)
26+
27+
+ explicitly calculating the p-value of a test: then you need to declare the :code:`chisq_obj` and then call it as above, instead of using :code:`chisq(data, X, Y, condition_set)` as before. Note that now :code:`causallearn.utils.cit.chisq` is a string :code:`"chisq"`, instead of a function.
28+
29+
Please see `CIT.py <https://github.com/cmu-phil/causal-learn/blob/main/causallearn/utils/cit.py>`_
30+
for more details on the implementation of the (conditional) independent tests.
1631

1732

1833
Parameters

docs/source/independence_tests_index/fisherz.rst

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,31 @@ Fisher-z test
55

66
Perform an independence test using Fisher-z's test [1]_. This test is optimal for linear-Gaussian data.
77

8-
(We have updated the independence test class and the usage example hasn't been updated yet. For new class, please refer to `TestCIT.py <https://github.com/cmu-phil/causal-learn/blob/main/tests/TestCIT.py>`_ or `TestCIT_KCI.py <https://github.com/cmu-phil/causal-learn/blob/main/tests/TestCIT_KCI.py>`_.)
9-
108

119
Usage
1210
--------
1311
.. code-block:: python
1412
13+
from causallearn.utils.cit import CIT
14+
fisherz_obj = CIT(data, "fisherz") # construct a CIT instance with data and method name
15+
pValue = fisherz_obj(X, Y, S)
16+
17+
Please be kindly informed that we have refactored the independence tests from functions to classes since the release `v0.1.2.8 <https://github.com/cmu-phil/causal-learn/releases/tag/0.1.2.8>`_. Speed gain and a more flexible parameters specification are enabled.
18+
19+
For users, you may need to adjust your codes accordingly. Specifically,
20+
21+
+ If you are running a constraint-based algorithm from end to end: then you don't need to change anything. Old codes are still compatible. For example,
22+
.. code-block:: python
23+
24+
from causallearn.search.ConstraintBased.PC import pc
1525
from causallearn.utils.cit import fisherz
16-
p = fisherz(data, X, Y, condition_set, correlation_matrix)
26+
cg = pc(data, 0.05, fisherz)
27+
28+
+ If you are explicitly calculating the p-value of a test: then you need to declare the :code:`fisherz_obj` and then call it as above, instead of using :code:`fisherz(data, X, Y, condition_set)` as before. Note that now :code:`causallearn.utils.cit.fisherz` is a string :code:`"fisherz"`, instead of a function.
29+
30+
31+
Please see `CIT.py <https://github.com/cmu-phil/causal-learn/blob/main/causallearn/utils/cit.py>`_
32+
for more details on the implementation of the (conditional) independent tests.
1733

1834
Parameters
1935
------------

docs/source/independence_tests_index/gsq.rst

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,29 @@ G-Square test
55

66
Perform an independence test using G-Square test [1]_. This test is based on the log likelihood ratio test.
77

8-
(We have updated the independence test class and the usage example hasn't been updated yet. For new class, please refer to `TestCIT.py <https://github.com/cmu-phil/causal-learn/blob/main/tests/TestCIT.py>`_ or `TestCIT_KCI.py <https://github.com/cmu-phil/causal-learn/blob/main/tests/TestCIT_KCI.py>`_.)
9-
10-
118
Usage
129
--------
1310
.. code-block:: python
1411
12+
from causallearn.utils.cit import CIT
13+
gsq_obj = CIT(data, "gsq") # construct a CIT instance with data and method name
14+
pValue = gsq_obj(X, Y, S)
15+
16+
Please be kindly informed that we have refactored the independence tests from functions to classes since the release `v0.1.2.8 <https://github.com/cmu-phil/causal-learn/releases/tag/0.1.2.8>`_. Speed gain and a more flexible parameters specification are enabled.
17+
18+
For users, you may need to adjust your codes accordingly. Specifically, if you are
19+
20+
+ running a constraint-based algorithm from end to end: then you don't need to change anything. Old codes are still compatible. For example,
21+
.. code-block:: python
22+
23+
from causallearn.search.ConstraintBased.PC import pc
1524
from causallearn.utils.cit import gsq
16-
p = gsq(data, X, Y, conditioning_set)
25+
cg = pc(data, 0.05, gsq)
26+
27+
+ explicitly calculating the p-value of a test: then you need to declare the :code:`gsq_obj` and then call it as above, instead of using :code:`gsq(data, X, Y, condition_set)` as before. Note that now :code:`causallearn.utils.cit.gsq` is a string :code:`"gsq"`, instead of a function.
28+
29+
Please see `CIT.py <https://github.com/cmu-phil/causal-learn/blob/main/causallearn/utils/cit.py>`_
30+
for more details on the implementation of the (conditional) independent tests.
1731

1832
Parameters
1933
-------------

docs/source/independence_tests_index/kci.rst

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,39 @@ Kernel-based conditional independence (KCI) test and independence test [1]_.
77
To test if x and y are conditionally or unconditionally independent on Z. For unconditional independence tests,
88
Z is set to the empty set.
99

10-
(We have updated the independence test class and the usage example hasn't been updated yet. For new class, please refer to `TestCIT.py <https://github.com/cmu-phil/causal-learn/blob/main/tests/TestCIT.py>`_ or `TestCIT_KCI.py <https://github.com/cmu-phil/causal-learn/blob/main/tests/TestCIT_KCI.py>`_.)
11-
12-
1310
Usage
1411
--------
1512
.. code-block:: python
1613
14+
from causallearn.utils.cit import CIT
15+
kci_obj = CIT(data, "kci") # construct a CIT instance with data and method name
16+
pValue = kci_obj(X, Y, S)
17+
18+
The above code runs KCI with the default parameters. Or instead if you would like to specify some parameters of KCI, you may do it by e.g.,
19+
20+
.. code-block:: python
21+
22+
kci_obj = CIT(data, "kci", kernelZ='Polynomial', approx=False, est_width='median', ...)
23+
24+
See `KCI.py <https://github.com/cmu-phil/causal-learn/blob/main/causallearn/utils/KCI/KCI.py>`_
25+
for more details on the parameters options of the KCI tests.
26+
27+
28+
Please be kindly informed that we have refactored the independence tests from functions to classes since the release `v0.1.2.8 <https://github.com/cmu-phil/causal-learn/releases/tag/0.1.2.8>`_. Speed gain and a more flexible parameters specification are enabled.
29+
30+
For users, you may need to adjust your codes accordingly. Specifically, if you are
31+
32+
+ running a constraint-based algorithm from end to end: then you don't need to change anything. Old codes are still compatible. For example,
33+
.. code-block:: python
34+
35+
from causallearn.search.ConstraintBased.PC import pc
1736
from causallearn.utils.cit import kci
18-
p = kci(data, X, Y, condition_set, kernelX, kernelY, kernelZ, est_width, polyd, kwidthx, kwidthy, kwidthz)
37+
cg = pc(data, 0.05, kci)
38+
39+
+ explicitly calculating the p-value of a test: then you need to declare the :code:`kci_obj` and then call it as above, instead of using :code:`kci(data, X, Y, condition_set)` as before. Note that now :code:`causallearn.utils.cit.kci` is a string :code:`"kci"`, instead of a function.
40+
41+
Please see `CIT.py <https://github.com/cmu-phil/causal-learn/blob/main/causallearn/utils/cit.py>`_
42+
for more details on the implementation of the (conditional) independent tests.
1943

2044
Parameters
2145
-------------

docs/source/independence_tests_index/mvfisherz.rst

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,29 @@ Missing-value Fisher-z test
66
Perform a testwise-deletion Fisher-z independence test to data sets with missing values.
77
With testwise-deletion, the test makes use of all data points that do not have missing values for the variables involved in the test.
88

9-
(We have updated the independence test class and the usage example hasn't been updated yet. For new class, please refer to `TestCIT.py <https://github.com/cmu-phil/causal-learn/blob/main/tests/TestCIT.py>`_ or `TestCIT_KCI.py <https://github.com/cmu-phil/causal-learn/blob/main/tests/TestCIT_KCI.py>`_.)
10-
11-
129
Usage
1310
--------
1411
.. code-block:: python
1512
13+
from causallearn.utils.cit import CIT
14+
mv_fisherz_obj = CIT(data_with_missingness, "mv_fisherz") # construct a CIT instance with data and method name
15+
pValue = mv_fisherz_obj(X, Y, S)
16+
17+
Please be kindly informed that we have refactored the independence tests from functions to classes since the release `v0.1.2.8 <https://github.com/cmu-phil/causal-learn/releases/tag/0.1.2.8>`_. Speed gain and a more flexible parameters specification are enabled.
18+
19+
For users, you may need to adjust your codes accordingly. Specifically, if you are
20+
21+
+ running a constraint-based algorithm from end to end: then you don't need to change anything. Old codes are still compatible. For example,
22+
.. code-block:: python
23+
24+
from causallearn.search.ConstraintBased.PC import pc
1625
from causallearn.utils.cit import mv_fisherz
17-
p = mv_fisherz(mvdata, X, Y, condition_set)
26+
cg = pc(data_with_missingness, 0.05, mv_fisherz)
27+
28+
+ explicitly calculating the p-value of a test: then you need to declare the :code:`mv_fisherz_obj` and then call it as above, instead of using :code:`mv_fisherz(data, X, Y, condition_set)` as before. Note that now :code:`causallearn.utils.cit.mv_fisherz` is a string :code:`"mv_fisherz"`, instead of a function.
29+
30+
Please see `CIT.py <https://github.com/cmu-phil/causal-learn/blob/main/causallearn/utils/cit.py>`_
31+
for more details on the implementation of the (conditional) independent tests.
1832

1933

2034
Parameters

0 commit comments

Comments
 (0)