flop#
- causalbase.order.flop(score, initial_order=None, *, max_iter=None, time_limit=None, random_state=None, cache_mb=2048)[source]#
Run FLOP: its local search over orders, then its iterated local search.
One iteration is one kick of the iterated local search:
round(ln p)random swaps of the best order, a local search from there with the parent sets rebuilt from scratch, and a move there if it is strictly better.- Parameters:
- scoreFamilyScore
The score: BDeu with either prior (scored with its compiled engine), BIC, Gaussian BIC or BGe, or a score of one’s own.
- 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.
- max_iterint or None, default=None
Kicks after the first local search; 0 runs the first local search only.
- 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 the candidate orders of the grow-shrink and the kicks; None draws a fresh seed.
- cache_mbfloat or None, default=2048
Memory budget of the cache of local scores, in MiB; None leaves it unbounded. Past it, every node drops its oldest quarter of scores. The search does not change, only how many families it scores again.
flopsearchkeeps no such cache (it updates Cholesky factors of the Gaussian BIC); with BDeu, scoring a family means counting the data.
- Returns:
- SearchResult
n_itercounts the kicks.infoholds"order"(the best order),"parents"(the parent set of each node, as frozensets, consistent with that order),"restarts"(local searches run,n_iter + 1) and"cache_evicted"(scores dropped to keep within cache_mb).
- 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 flop >>> from causalbase.scores import BDeuScore >>> flop(BDeuScore(load_asia().data), max_iter=2, random_state=0).n_iter 2