Skip to content

Commit 97a1091

Browse files
committed
Updated some advanced usages for PC
1 parent 861c29e commit 97a1091

File tree

1 file changed

+28
-1
lines changed
  • docs/source/search_methods_index/Constraint-based causal discovery methods

1 file changed

+28
-1
lines changed

docs/source/search_methods_index/Constraint-based causal discovery methods/PC.rst

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,41 @@ Usage
3535
3636
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"])').
3737

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.PC import pc
46+
from causallearn.utils.cit import kci
47+
cg = pc(data, 0.05, kci, kernelZ='Polynomial', approx=False, est_width='median', ...)
48+
49+
+ 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.,
50+
51+
.. code-block:: python
52+
53+
citest_cache_file = "/my/path/to/citest_cache_dataname_kci.json" # .json file
54+
cg1 = pc(data, 0.05, kci, cache_path=citest_cache_file) # after the long run
55+
56+
# just finetune uc_rule. p-values are reused, and thus cg2 is done in almost no time.
57+
cg2 = pc(data, 0.05, kci, cache_path=citest_cache_file, uc_rule=1)
58+
..
59+
60+
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+
3865
Parameters
3966
-------------------
4067
**data**: numpy.ndarray, shape (n_samples, n_features). Data, where n_samples is the number of samples
4168
and n_features is the number of features.
4269

4370
**alpha**: desired significance level (float) in (0, 1). Default: 0.05.
4471

45-
**indep_test**: Independence test method function. Default: 'fisherz'.
72+
**indep_test**: string, name of the independence test method. Default: 'fisherz'.
4673
- ":ref:`fisherz <Fisher-z test>`": Fisher's Z conditional independence test.
4774
- ":ref:`chisq <Chi-Square test>`": Chi-squared conditional independence test.
4875
- ":ref:`gsq <G-Square test>`": G-squared conditional independence test.

0 commit comments

Comments
 (0)