graphdot.model.tree_search package¶
-
class
graphdot.model.tree_search.
MCTSGraphTransformer
(rewriter, surrogate, exploration_bias=1.0, precision=0.01)[source]¶ Bases:
object
A varient of Monte Carlo tree search for optimization and root-finding in a space of graphs.
Parameters: - rewriter (callable) – A callable that implements the
Rewriter
abstract class. - surrogate (object) – A predictor used to calculate the target property of a given graph.
- exploration_bias (float) – Tunes the preference of the MCTS model between exploitation and exploration of the search space.
- precision (float) – Target precision of MCTS search outcome.
-
seek
(g0, target, maxiter=500, return_tree=False, random_state=None)[source]¶ Transforms an initial graph into one with a specific desired target property value.
Parameters: - g0 (object) – A graph to start the tree search with.
- target (float) – Target property value of the desired graph.
- maxiter (int) – Maximum number of MCTS iterations to perform.
- return_tree (Boolean) – Whether or not to return the search tree in its original form or as a flattened dataframe.
- random_state (int or :py:`np.random.Generator`) – The seed to the random number generator (RNG), or the RNG itself. If None, the default RNG in numpy will be used.
Returns: tree – If return_tree is True, a hierarchical dataframe representing the search tree will be returned; otherwise, a flattened dataframe will be returned.
Return type:
- rewriter (callable) – A callable that implements the
-
class
graphdot.model.tree_search.
LookAheadSequenceRewriter
(n=1, b=3, min_edits=1, max_edits=5, p_insert=1, p_mutate=1, p_delete=1, random_state=None)[source]¶ Bases:
graphdot.model.tree_search._rewriter.AbstractRewriter
A sequence rewriter that performs contextual updates to a symbol sequence using the n-gram preceding the location of modification. It can carry out three types of operations:
- Insertion: insert an symbol at a random location. The symbol inserted should be probabilistically determined by up to n items in front of it unless when there are less than n symbols in the front, or when there is no matching n-gram in the training set. In that case, the longest matching k-gram (k < n) is used.
- Mutation: replace an symbol by a random one. This is context-sensitive.
- Deletion: remove an symbol at random from a sequence. This is context-insensitive.
Parameters: - n (int) – The maximum number of items to look ahead for contextual rewrites.
- b (int) – The branching factor, i.e. the number of new sequences to create from each input sequence.
- min_edits (int) – The minimum number of edits made to create a new sequence.
- max_edits (int) – The maximum number of edits made to create a new sequence.
- p (list of three numbers) – The relative frequencies of insertation, mutation, and deletion operations.
- random_state (np.random.Generator or int) – Initial state for the internal RNG.
-
__call__
(s)[source]¶ Generate
b
offspring sequences, each being rewritten at leastmin_edits
and at mostmax_edits
times.Parameters: s (sequence) – The sequence to be rewritten. Returns: T – A collection of unique offspring sequences Return type: list of sequences
-
fit
(X)[source]¶ Learn the n-gram distribution from the given dataset.
Parameters: X (list of sequences) – The training set.
-
tree
¶ A tree-representation of the 1- to n-gram distributions of the training set.