order_search#
- causalbase.order.order_search(score, initial_order=None, *, polish='ges', n_restarts=2, n_pair_candidates=0, n_swaps=None, max_iter=None, time_limit=None, random_state=None, cache_mb=2048)[source]#
Learn a network by iterated local search over orders, each local search polished by GES.
A local search climbs over orders by insertion moves, scoring each order by the best network consistent with it (
OrderScorer, a greedy climb per node), and ends with GES (or XGES) started from that network, so that arcs the order forbids can still be added. Each iteration kicks the best network found so far (a random topological order of it, half the time with n_swaps random transpositions), runs a local search from there, and keeps the result if it scores at least as well.- Parameters:
- scoreFamilyScore
The score: BDeu with either prior, BIC, Gaussian BIC or BGe. Orders and networks are scored with it (with its compiled engine for BDeu); GES and XGES search it as
ges()does.- initial_ordersequence of int, optional
Order the first local search starts from. By default a topological order of the network GES learns on the same score, learned before the time limit starts.
- polish{“ges”, “xges”}, default=”ges”
Search over equivalence classes that ends each local search.
- n_restartsint, default=2
Extra greedy climbs per node in the order evaluator, each without the first parent the previous climb chose (see
OrderScorer).- n_pair_candidatesint, default=0
When positive, each local search also tries adding pairs of parents drawn from this many best single candidates (
pair_polish()), and polishes again if that added any.- n_swapsint or None, default=None
Transpositions of a kick;
ceil(ln p)forpvariables when None.- max_iterint or None, default=None
Kicks, each followed by a local search, after the first local search.
- time_limitfloat or None, default=None
Seconds of search, checked inside the local searches too. At least one of max_iter and time_limit must be set.
- random_stateint or None, default=None
Seeds every random choice; None draws a fresh seed. With an integer and max_iter (and no time limit) the result is reproducible.
- cache_mbfloat or None, default=2048
Memory budget of the order evaluator’s caches, in MiB (see
OrderScorer); None leaves them unbounded. The search does not change, a tight budget only slows it down.
- Returns:
- SearchResult
n_itercounts the kicks;info["accepted"]those whose local search scored at least as well as the best, which then moved there.
- Raises:
- ValueError
If neither limit is set, or an option is out of range.
Examples
>>> from causalbase.datasets import load_asia >>> from causalbase.order import order_search >>> from causalbase.scores import BDeuScore >>> result = order_search(BDeuScore(load_asia().data), max_iter=3, random_state=0) >>> result.n_iter 3