causaldag.structure_learning.sparsest_permutation

causaldag.structure_learning.sparsest_permutation(nodes, ci_tester, progress=False)[source]

Estimate the Markov equivalence class of a DAG using the Sparsest Permutations (SP) algorithm.

Parameters:
  • nodes – list of nodes.
  • ci_tester – object for testing conditional independence.
  • progress – if True, show a progress bar over the enumeration of permutations.

Examples

>>> from causaldag.utils.ci_tests import MemoizedCI_Tester, partial_correlation_test, partial_correlation_suffstat
>>> import causaldag as cd
>>> import random
>>> import numpy as np
>>> random.seed(1212)
>>> np.random.seed(12131)
>>> nnodes = 7
>>> d = cd.rand.directed_erdos(nnodes, exp_nbrs=2)
>>> g = cd.rand.rand_weights(d)
>>> samples = g.sample(1000)
>>> suffstat = partial_correlation_suffstat(samples)
>>> ci_tester = MemoizedCI_Tester(partial_correlation_test, suffstat, alpha=1e-3)
>>> est_dag = cd.sparsest_permutation(set(range(nnodes)), ci_tester, progress=True)
>>> true_cpdag = d.cpdag()
>>> est_cpdag = est_dag.cpdag()
>>> print(true_cpdag.shd(est_cpdag))
>>> 0