You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/independence_tests_index/chisq.rst
+20-6Lines changed: 20 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,25 +5,39 @@ Chi-Square test
5
5
6
6
Perform an independence test on discrete variables using Chi-Square test.
7
7
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
8
Usage
11
9
--------
12
10
.. code-block:: python
13
11
12
+
from causallearn.utils.cit importCIT
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.PCimport pc
14
24
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.
16
31
17
32
18
33
Parameters
19
34
----------------
20
35
**data**: numpy.ndarray, shape (n_samples, n_features). Data, where n_samples is the number of samples
21
36
and n_features is the number of features.
22
37
23
-
**X, Y and condition_set**: column indices of data.
38
+
**method**: string, "chisq".
24
39
25
-
**G_sq**: True means using G-Square test;
26
-
False means using Chi-Square test.
40
+
**kwargs**: e.g., :code:`cache_path`. See :ref:`Advanced Usages <Advanced Usages>`.
Copy file name to clipboardExpand all lines: docs/source/independence_tests_index/fisherz.rst
+21-5Lines changed: 21 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,24 +5,40 @@ Fisher-z test
5
5
6
6
Perform an independence test using Fisher-z's test [1]_. This test is optimal for linear-Gaussian data.
7
7
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
8
11
9
Usage
12
10
--------
13
11
.. code-block:: python
14
12
13
+
from causallearn.utils.cit importCIT
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.PCimport pc
15
25
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.
17
33
18
34
Parameters
19
35
------------
20
36
**data**: numpy.ndarray, shape (n_samples, n_features). Data, where n_samples is the number of samples
21
37
and n_features is the number of features.
22
38
23
-
**X, Y and condition_set**: column indices of data.
39
+
**method**: string, "fisherz".
24
40
25
-
**correlation_matrix**: correlation matrix; None means without the parameter of correlation matrix.
41
+
**kwargs**: e.g., :code:`cache_path`. See :ref:`Advanced Usages <Advanced Usages>`.
Copy file name to clipboardExpand all lines: docs/source/independence_tests_index/gsq.rst
+20-6Lines changed: 20 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,24 +5,38 @@ G-Square test
5
5
6
6
Perform an independence test using G-Square test [1]_. This test is based on the log likelihood ratio test.
7
7
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
-
11
8
Usage
12
9
--------
13
10
.. code-block:: python
14
11
12
+
from causallearn.utils.cit importCIT
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.PCimport pc
15
24
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.
17
31
18
32
Parameters
19
33
-------------
20
34
**data**: numpy.ndarray, shape (n_samples, n_features). Data, where n_samples is the number of samples
21
35
and n_features is the number of features.
22
36
23
-
**X, Y and condition_set**: column indices of data.
37
+
**method**: string, "gsq".
24
38
25
-
**G_sq**: True means using G-Square test; False means using Chi-Square test.
39
+
**kwargs**: e.g., :code:`cache_path`. See :ref:`Advanced Usages <Advanced Usages>`.
Copy file name to clipboardExpand all lines: docs/source/independence_tests_index/kci.rst
+41-13Lines changed: 41 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,37 +7,65 @@ Kernel-based conditional independence (KCI) test and independence test [1]_.
7
7
To test if x and y are conditionally or unconditionally independent on Z. For unconditional independence tests,
8
8
Z is set to the empty set.
9
9
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
-
13
10
Usage
14
11
--------
15
12
.. code-block:: python
16
13
14
+
from causallearn.utils.cit importCIT
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.,
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.PCimport pc
17
36
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.
19
43
20
44
Parameters
21
-
-------------
45
+
------------
22
46
**data**: numpy.ndarray, shape (n_samples, n_features). Data, where n_samples is the number of samples
23
47
and n_features is the number of features.
24
48
25
-
**X, Y, and condition_set**: column indices of data. condition_set could be None.
(For 'PolynomialKernel', the default degree is 2. Currently, users can change it by setting the 'degree' of 'class PolynomialKernel()'.
53
+
+ Either for specifying parameters of KCI, including:
29
54
30
-
**est_width**: set kernel width for Gaussian kernels.
55
+
**KernelX/Y/Z (condition_set)**: ['GaussianKernel', 'LinearKernel', 'PolynomialKernel']. (For 'PolynomialKernel', the default degree is 2. Currently, users can change it by setting the 'degree' of 'class PolynomialKernel()'.
56
+
57
+
**est_width**: set kernel width for Gaussian kernels.
31
58
- 'empirical': set kernel width using empirical rules (default).
32
59
- 'median': set kernel width using the median trick.
33
60
34
-
**polyd**: polynomial kernel degrees (default=2).
61
+
**polyd**: polynomial kernel degrees (default=2).
62
+
63
+
**kwidthx/y/z**: kernel width for data x/y/z (standard deviation sigma).
35
64
36
-
**kwidthx**: kernel width for data x (standard deviation sigma).
65
+
**and more**: aee `KCI.py <https://github.com/cmu-phil/causal-learn/blob/main/causallearn/utils/KCI/KCI.py>`_ for details.
37
66
38
-
**kwidthy**: kernel width for data y (standard deviation sigma).
67
+
+ Or for advanced usages of CIT, e.g., :code:`cache_path`. See :ref:`Advanced Usages <Advanced Usages>`.
39
68
40
-
**kwidthz**: kernel width for data z (standard deviation sigma).
Copy file name to clipboardExpand all lines: docs/source/independence_tests_index/mvfisherz.rst
+23-7Lines changed: 23 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,23 +6,39 @@ Missing-value Fisher-z test
6
6
Perform a testwise-deletion Fisher-z independence test to data sets with missing values.
7
7
With testwise-deletion, the test makes use of all data points that do not have missing values for the variables involved in the test.
8
8
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
-
12
9
Usage
13
10
--------
14
11
.. code-block:: python
15
12
13
+
from causallearn.utils.cit importCIT
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.PCimport pc
16
25
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.
18
32
19
33
20
34
Parameters
21
-
---------------
22
-
**mvdata**: numpy.ndarray, shape (n_samples, n_features). Data with missing value, where n_samples is the number of samples
35
+
------------
36
+
**data**: numpy.ndarray, shape (n_samples, n_features). Data, where n_samples is the number of samples
23
37
and n_features is the number of features.
24
38
25
-
**X, Y and condition_set**: column indices of data.
39
+
**method**: string, "mv_fisherz".
40
+
41
+
**kwargs**: e.g., :code:`cache_path`. See :ref:`Advanced Usages <Advanced Usages>`.
Copy file name to clipboardExpand all lines: docs/source/search_methods_index/Constraint-based causal discovery methods/PC.rst
+28-1Lines changed: 28 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,14 +35,41 @@ Usage
35
35
36
36
Visualization using pydot is recommended. If specific label names are needed, please refer to this `usage example <https://github.com/cmu-phil/causal-learn/blob/main/tests/TestGraphVisualization.py>`_ (e.g., 'cg.draw_pydot_graph(labels=["A", "B", "C"])' or 'GraphUtils.to_pydot(cg.G, labels=["A", "B", "C"])').
37
37
38
+
+++++++++++++++
39
+
Advanced Usages
40
+
+++++++++++++++
41
+
+ If you would like to specify parameters for the (conditional) independence test (if available), you may directly pass the parameters to the :code:`pc` call. E.g.,
42
+
43
+
.. code-block:: python
44
+
45
+
from causallearn.search.ConstraintBased.PCimport pc
+ If your graph is big and/or your independence test is slow (e.g., KCI), you may want to cache the p-value results to a local checkpoint. Then by reading values from this local checkpoint, no more repeated calculation will be wasted to resume from checkpoint / just finetune some PC parameters. This can be achieved by specifying :code:`cache_path`. E.g.,
If :code:`cache_path` does not exist in your local file system, a new one will be created. Otherwise, the cache will be first loaded from the json file to the CIT class and used during the runtime. Note that 1) data hash and parameters hash will first be checked at loading to ensure consistency, and 2) during runtime, the cache will be saved to the local file every 30 seconds.
61
+
62
+
+ The above advanced usages also apply to other constraint-based methods, e.g., FCI and CDNOD.
63
+
64
+
38
65
Parameters
39
66
-------------------
40
67
**data**: numpy.ndarray, shape (n_samples, n_features). Data, where n_samples is the number of samples
41
68
and n_features is the number of features.
42
69
43
70
**alpha**: desired significance level (float) in (0, 1). Default: 0.05.
44
71
45
-
**indep_test**: Independence test method function. Default: 'fisherz'.
72
+
**indep_test**: string, name of the independence test method. Default: 'fisherz'.
46
73
- ":ref:`fisherz <Fisher-z test>`": Fisher's Z conditional independence test.
0 commit comments