slim_gsgp.algorithms.GSGP.operators
slim_gsgp.algorithms.GSGP.operators.crossover_operators module
Geometric crossover implementation for genetic programming trees.
- slim_gsgp.algorithms.GSGP.operators.crossover_operators.geometric_crossover(tree1, tree2, random_tree, testing, new_data=False)[source]
Performs geometric crossover between two trees using a random tree.
- Parameters:
tree1 (Tree or torch.Tensor) – The first parent tree. If geometric_crossover is called with new_data=True, it means the final tree is being evaluated on testing data and tree1 is a torch.Tensor. Otherwise, during training, the individuals are Tree instances.
tree2 (Tree or torch.Tensor) – The second parent tree. If geometric_crossover is called with new_data=True, it means the final tree is being evaluated on testing data and tree2 is a torch.Tensor. Otherwise, during training, the individuals are Tree instances.
random_tree (Tree or torch.Tensor) – The random tree used for crossover. If geometric_crossover is called with new_data=True, it means the final tree is being evaluated on testing data and random_tree is a torch.Tensor. Otherwise, during training, random_tree is a Tree instance.
testing (bool) – Flag indicating whether to use test semantics or train semantics.
new_data (bool) – Flag indicating whether the trees are exposed to new data, outside the evolution process. In this case, operations are performed on the inputs rather than semantics.
- Returns:
The semantics of the individual, resulting from geometric crossover.
- Return type:
torch.Tensor
slim_gsgp.algorithms.GSGP.operators.mutators
Geometric Mutation Functions for Tree Structures using PyTorch.
- slim_gsgp.algorithms.GSGP.operators.mutators.product_one_trees_geometric_mutation(tree, random_tree_1, ms, testing, new_data=False)[source]
Apply product-based geometric mutation on tree semantics using one random tree.
- Parameters:
tree (Tree or torch.Tensor) – The target tree whose semantics are to be mutated. If product_one_trees_geometric_mutation is called with new_data=True, it means the final tree is being evaluated on testing data and tree is a torch.Tensor. Otherwise, during training, the individuals are Tree instances.
random_tree_1 (Tree or torch.Tensor) – The random tree for mutation. If product_one_trees_geometric_mutation is called with new_data=True, it means the final tree is being evaluated on testing data and random_tree_1 is a torch.Tensor. Otherwise, during training, random_tree_1 is a Tree instance.
ms (float) – Mutation step.
testing (bool) – Boolean indicating if the operation is on test semantics.
new_data (bool, optional) – Flag indicating whether the tree is exposed to new data outside the evolution process. If True, operations are performed on the inputs rather than semantics. Defaults to False.
- Returns:
Mutated semantics as a torch tensor.
- Return type:
torch.Tensor
- slim_gsgp.algorithms.GSGP.operators.mutators.product_two_trees_geometric_mutation(tree, random_tree_1, random_tree_2, ms, testing, new_data=False)[source]
Apply product-based geometric mutation on tree semantics using two random trees.
- Parameters:
tree (Tree or torch.Tensor) – The target tree whose semantics are to be mutated. If product_two_trees_geometric_mutation is called with new_data=True, it means the final tree is being evaluated on testing data and tree is a torch.Tensor. Otherwise, during training, the individuals are Tree instances.
random_tree_1 (Tree or torch.Tensor) – The first random tree for mutation. If product_two_trees_geometric_mutation is called with new_data=True, it means the final tree is being evaluated on testing data and random_tree_1 is a torch.Tensor. Otherwise, during training, random_tree_1 is a Tree instance.
random_tree_2 (Tree or torch.Tensor) – The second random tree for mutation. If product_two_trees_geometric_mutation is called with new_data=True, it means the final tree is being evaluated on testing data and random_tree_2 is a torch.Tensor. Otherwise, during training, random_tree_2 is a Tree instance.
ms (float) – Mutation step.
testing (bool) – Indicates if the operation is on test semantics.
new_data (bool, optional) – Flag indicating whether the tree is exposed to new data outside the evolution process. If True, operations are performed on the inputs rather than semantics. Defaults to False.
- Returns:
Mutated semantics as a torch tensor.
- Return type:
torch.Tensor
- slim_gsgp.algorithms.GSGP.operators.mutators.standard_geometric_mutation(tree, random_tree_1, random_tree_2, ms, testing, new_data=False)[source]
Apply standard geometric mutation on tree semantics using two random trees.
- Parameters:
tree (Tree or torch.Tensor) – The target tree whose semantics are to be mutated. If standard_geometric_mutation is called with new_data=True, it means the final tree is being evaluated on testing data and tree is a torch.Tensor. Otherwise, during training, the individuals are Tree instances.
random_tree_1 (Tree or torch.Tensor) – The first random tree for mutation. If standard_geometric_mutation is called with new_data=True, it means the final tree is being evaluated on testing data and random_tree_1 is a torch.Tensor. Otherwise, during training, random_tree_1 is a Tree instance.
random_tree_2 (Tree or torch.Tensor) – The second random tree for mutation. If standard_geometric_mutation is called with new_data=True, it means the final tree is being evaluated on testing data and random_tree_2 is a torch.Tensor. Otherwise, during training, random_tree_2 is a Tree instance.
ms (float) – Mutation step.
testing (bool) – Indicates if the operation is on test semantics.
new_data (bool, optional) – Flag indicating whether the trees are exposed to new data outside the evolution process. If True, operations are performed on the inputs rather than semantics. Defaults to False.
- Returns:
Mutated semantics or data as a torch tensor.
- Return type:
torch.Tensor
- slim_gsgp.algorithms.GSGP.operators.mutators.standard_one_tree_geometric_mutation(tree, random_tree_1, ms, testing, new_data=False)[source]
Apply standard geometric mutation on tree semantics using one random tree.
- Parameters:
tree (Tree or torch.Tensor) – The target tree whose semantics are to be mutated. If standard_one_tree_geometric_mutation is called with new_data=True, it means the final tree is being evaluated on testing data and tree is a torch.Tensor. Otherwise, during training, the individuals are Tree instances.
random_tree_1 (Tree or torch.Tensor) – The random tree for mutation. If standard_one_tree_geometric_mutation is called with new_data=True, it means the final tree is being evaluated on testing data and random_tree_1 is a torch.Tensor. Otherwise, during training, random_tree_1 is a Tree instance.
ms (float) – Mutation step.
testing (bool) – Indicates if the operation is on test semantics.
new_data (bool, optional) – Flag indicating whether the tree is exposed to new data outside the evolution process. If True, operations are performed on the inputs rather than semantics. Defaults to False.
- Returns:
Mutated semantics of the individual.
- Return type:
torch.Tensor