hill_climbing#

causalbase.search.hill_climbing(score, initial_graph=None, *, tabu_length=0, max_tabu_moves=0, n_restarts=0, perturbation=1, time_limit=None, random_state=None)[source]#

Run hill climbing, or tabu search, over DAGs.

Each step applies the valid arc addition, deletion or reversal of largest gain, the smallest move number on ties (see the module docstring), until none improves.

Parameters:
scoreFamilyScore

The score to climb: BDeu with either prior (scored with its compiled engine), BIC, Gaussian BIC or BGe, or a score of one’s own.

initial_graphDAG, optional

Where the first climb starts. The empty graph by default.

tabu_lengthint, default=0

With a positive value, tabu search: the best valid move is applied even if it loses score, as long as its DAG is not among the last tabu_length visited.

max_tabu_movesint, default=0

Tabu search stops after this many moves without improving its best DAG.

n_restartsint, default=0

Climbs after the first, each from the best DAG so far perturbed by perturbation random valid moves.

perturbationint, default=1

Random moves before each restart.

time_limitfloat or None, default=None

Wall-clock budget in seconds for the whole run.

random_stateint or None, default=None

Seeds the perturbations; None draws a fresh seed.

Returns:
SearchResult

n_iter is the number of moves applied, perturbations excluded, and the iterations of trace count moves too. info holds "climbs" (climbs run, 1 + restarts done), "time" (seconds of the whole run), "time_first" and "score_first" (seconds to the end of the first climb, and its score).

Raises:
ValueError

If initial_graph has another number of nodes, or an option is out of range.

Examples

>>> from causalbase.datasets import load_asia
>>> from causalbase.scores import BDeuScore
>>> from causalbase.search import hill_climbing
>>> result = hill_climbing(BDeuScore(load_asia().data), n_restarts=2, random_state=0)
>>> result.info["climbs"]
3