opytimizer.optimizers.evolutionary.gp¶
Genetic Programming.
-
class
opytimizer.optimizers.evolutionary.gp.
GP
(params: Optional[Dict[str, Any]] = None)¶ A GP class, inherited from Optimizer.
This is the designed class to define GP-related variables and methods.
References
- Koza. Genetic programming: On the programming of computers by means of natural selection (1992).
-
__init__
(params: Optional[Dict[str, Any]] = None) → None¶ Initialization method.
Parameters: params – Contains key-value parameters to the meta-heuristics.
-
p_reproduction
¶ Probability of reproduction.
-
p_mutation
¶ Probability of mutation.
-
p_crossover
¶ Probability of crossover.
-
prunning_ratio
¶ Nodes’ prunning ratio.
-
_prune_nodes
(n_nodes: int) → int¶ Prunes the amount of possible nodes used for mutation and crossover.
Parameters: n_nodes – Number of current nodes. Returns: Amount of prunned nodes. Return type: (int)
-
_reproduction
(space: opytimizer.spaces.tree.TreeSpace) → None¶ Reproducts a number of individuals pre-selected through a tournament procedure (p. 99).
Parameters: space – A TreeSpace object.
-
_mutation
(space: opytimizer.spaces.tree.TreeSpace) → None¶ Mutates a number of individuals pre-selected through a tournament procedure.
Parameters: space – A TreeSpace object.
-
_mutate
(space: opytimizer.spaces.tree.TreeSpace, tree: opytimizer.core.node.Node, max_nodes: int) → opytimizer.core.node.Node¶ Actually performs the mutation on a single tree (p. 105).
Parameters: - space – A TreeSpace object.
- tree – A Node instance to be mutated.
- max_nodes – Maximum number of nodes to be searched.
Returns: A mutated tree.
Return type: (Node)
-
_crossover
(space: opytimizer.spaces.tree.TreeSpace) → None¶ Crossover a number of individuals pre-selected through a tournament procedure (p. 101).
Parameters: space – A TreeSpace object.
-
_cross
(father: opytimizer.core.node.Node, mother: opytimizer.core.node.Node, max_father: int, max_mother: int) → Tuple[opytimizer.core.node.Node, opytimizer.core.node.Node]¶ Actually performs the crossover over a father and mother nodes.
Parameters: - father – A father’s node to be crossed.
- mother – A mother’s node to be crossed.
- max_father – Maximum of nodes from father to be used.
- max_mother – Maximum of nodes from mother to be used.
Returns: Two offsprings based on the crossover operator.
Return type:
-
evaluate
(space: opytimizer.core.space.Space, function: opytimizer.core.function.Function) → None¶ Evaluates the search space according to the objective function.
Parameters: - space – A TreeSpace object.
- function – A Function object that will be used as the objective function.
-
update
(space: opytimizer.core.space.Space) → None¶ Wraps Genetic Programming over all trees and variables.
Parameters: space – TreeSpace containing agents and update-related information.