exact_search#
- causalbase.exact.exact_search(score, initial_order=None, *, max_parents=None, time_limit=None, prune=True, verbose=False)[source]#
Find the network of highest score, or the best one under a parent limit.
Without a limit, dynamic programming over variable subsets (Silander and Myllymaki, 2006) finds the global optimum; memory grows as
p 2^p, so about 27 variables fit in 32 GB. With max_parents, an integer program solved with SCIP (which needspip install "causalbase[exact]") finds the optimum among the DAGs whose parent sets have at most max_parents variables; seecausalbase.exact.ilp.- Parameters:
- scoreFamilyScore
The score. BDeu, the discrete BIC, the Gaussian BIC and BGe are scored by compiled kernels on as many threads as the score’s
n_jobs(the counting kernels of BDeu and the BIC on fewer than 32768 rows and at most 255 levels per variable; larger discrete data goes through the score’s own batches, more slowly). Any other score is scored family by family in Python.- initial_ordersequence of int, optional
Integer program only: a variable order whose best consistent network seeds SCIP with a first solution.
- max_parentsint or None, default=None
Most parents of a node. None runs the dynamic programming.
- time_limitfloat or None, default=None
Integer program only: SCIP’s time limit in seconds. The result is then the best network found, and
info["status"]says whether it is proved optimal.- prunebool, default=True
Dynamic programming only: skip the parent sets that the superset bound of the score proves useless (the result is the same). BGe has no bound, so it scores every set either way.
- verbosebool, default=False
Print progress per variable, and SCIP’s log.
- Returns:
- SearchResult
n_iteris 0 andtraceholds a single entry.infoholds"parents"(sorted parents per node),"n_candidates"and"n_scored"(parent sets kept and scored, per node),"max_candidate_size"(largest candidate per node),"time_scores"and"time_dp"(seconds scoring the parent sets and searching, by dynamic programming or the integer program), and, with max_parents, SCIP’s"status"(“optimal” when proved),"gap","dual_bound"and"n_clusters"(cluster constraints added).
- Raises:
- ValueError
If max_parents is out of range, or, with max_parents, there are more than 64 variables.
Examples
>>> from causalbase.datasets import load_asia >>> from causalbase.exact import exact_search >>> from causalbase.scores import BDeuScore >>> result = exact_search(BDeuScore(load_asia().data)) >>> result.dag.num_nodes 8