OrderScorer#
- class causalbase.order.OrderScorer(score, max_steps=1000, incremental=True, memo_slots=8, exact_cap=1024, n_restarts=0, cache_mb=None)[source]#
Hill climbing restricted to an order, with exact incremental replay.
Parent sets are bitmasks internally, and local scores are cached here per node and parent mask, so each family is scored once: by the compiled engine of a
BDeuScore(which does not cache them), by the score itself otherwise.- Parameters:
- scoreFamilyScore
The score, kept as
family_score; aBDeuScorescores the families with its compiled engine. Any other object withn_varsandlocal_score(node, parents)(and, optionally, the batchlocal_scores_add(node, parents, candidates)) is used as it is.- max_stepsint, default=1000
Maximum number of moves per node (1000 in the Java implementation).
- incrementalbool, default=True
Replay the stored greedy path when a node’s predecessors change, instead of climbing again from the empty parent set.
- memo_slotsint, default=8
Greedy paths kept per node. A new predecessor set is replayed from the stored one closest to it (fewest predecessors added or removed), which matters when rollouts alternate between several base orders.
- exact_capint, default=1024
Answers kept per node for predecessor sets met before, oldest dropped first; 0 keeps none. A node often meets a set again after it has left the slots (same base order, prefix variables already in front).
- n_restartsint, default=0
Extra greedy climbs per node. Climb
i + 1runs on the predecessors of climbiminus the first parent climbiadded (its best single parent), and the node keeps the best of all climbs (the earliest on ties). This gets past a parent that wins alone but blocks better sets, such as a variable with many states whose CPT leaves no room for more parents. Each climb is an ordinary greedy climb on a smaller predecessor set, so it reuses the memos and replays, andbreaks()andpath_moves()stay exact.- cache_mbfloat or None, default=None
Memory budget of the caches, in MiB; None leaves them unbounded. When a query leaves them above it, every cache drops its oldest quarter (least recently used, for the neighbour vectors) until they fit. Answers do not change, since dropped entries are recomputed when needed; a budget far below what a search visits only costs time.
- Attributes:
- cache_nbytesint
Estimated bytes held by the caches the budget covers: family scores, neighbour vectors, final-state verdicts and stored answers. The greedy paths in the slots (
memo_slotsper node) are not counted.- n_evictedint
Cache entries dropped to keep within cache_mb.
- path_moves(node, preds)[source]#
Return the bitmask of the candidates toggled along the greedy path of
node.The path is the one given
preds. Removing a predecessor outside this mask leaves the result oflocal()unchanged. With restarts it is the union over the climbs of the chain: a predecessor off every path changes no climb, hence no first parent either.
- breaks(node, preds)[source]#
For each variable
coutsidepreds, where adding it would alter the greedy path.Entry
cis the first step of the path ofnodethatcwould beat (the path length if it only improves on the final state), or -1 if addingctopredsleaves the result oflocal()unchanged. Entries fornodeand forpredsare -1. The test is the one_replay()applies, done for all candidates at once, so their neighbour vectors are filled in large batches. With restarts an entry is non-negative whencwould alter any climb of the chain (the value is then only a flag): if it alters none, every climb and every first parent stay as they were.