Constrained cfg
neps.search_spaces.architecture.cfg_variants.constrained_cfg
#
ConstrainedGrammar
#
Bases: Grammar
Source code in neps/search_spaces/architecture/cfg_variants/constrained_cfg.py
rand_subtree
#
Helper function to choose a random subtree in a given parse tree. Runs a single pass through the tree (stored as string) to look for the location of swappable nonterminal symbols.
PARAMETER | DESCRIPTION |
---|---|
tree |
parse tree.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[str, int]
|
Tuple[str, int]: return the parent node of the subtree and its index. |
Source code in neps/search_spaces/architecture/cfg.py
remove_subtree
staticmethod
#
Helper functioon to remove a subtree from a parse tree given its index. E.g. '(S (S (T 2)) (ADD +) (T 1))' becomes '(S (S (T 2)) ', '(T 1))' after removing (ADD +)
PARAMETER | DESCRIPTION |
---|---|
tree |
parse tree
TYPE:
|
index |
index of the subtree root node
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[str, str, str]
|
Tuple[str, str, str]: part before the subtree, subtree, part past subtree |