- [[PCアルゴリズム]]のPython実装。 - 元はRパッケージ - [GitHub - keiichishima/pcalg: CPDAG Estimation using PC-Algorithm](https://github.com/keiichishima/pcalg) - [GitHub - Renovamen/pcalg-py: Implement PC algorithm in Python | PC 算法的 Python 实现](https://github.com/Renovamen/pcalg-py) #### estimate_skeleton ```python def estimate_skeleton(indep_test_func, data_matrix, alpha, **kwargs): """Estimate a skeleton graph from the statistis information. Args: indep_test_func: the function name for a conditional independency test. data_matrix: data (as a numpy array). alpha: the significance level. kwargs: 'max_reach': maximum value of l (see the code). The value depends on the underlying distribution. 'method': if 'stable' given, use stable-PC algorithm (see [Colombo2014]). 'init_graph': initial structure of skeleton graph (as a networkx.Graph). If not specified, a complete graph is used. 'fixed_edges': Undirected edges marked here are not changed (as a networkx.Graph). If not specified, an empty graph is used. other parameters may be passed depending on the indep_test_func()s. Returns: g: a skeleton graph (as a networkx.Graph). sep_set: a separation set (as an 2D-array of set()). [Colombo2014] Diego Colombo and Marloes H Maathuis. Order-independent constraint-based causal structure learning. In The Journal of Machine Learning Research, Vol. 15, pp. 3741-3782, 2014. """ ``` - stable methodは [[2014__Order-Independent Constraint-Based Causal StructureLearning]] で提案された手法 - [[条件付き独立性検定]] で、エッジの削除をするときに、即座に削除せずに、ノードを探索したあとにまとめてエッジを削除しているだけにみえる。 #### estimate_cpdag - スケルトングラフからのCPDAGと、分離セットを推論する ```python def estimate_cpdag(skel_graph, sep_set): """Estimate a CPDAG from the skeleton graph and separation sets returned by the estimate_skeleton() function. Args: skel_graph: A skeleton graph (an undirected networkx.Graph). sep_set: An 2D-array of separation set. The contents look like something like below. sep_set[i][j] = set([k, l, m]) Returns: An estimated DAG. """ ```