Perform the hoist mutation operation on the program. Hoist mutation selects a random subtree from the embedded program to be replaced. A random subtree of that subtree is then selected and this is 'hoisted' into the original subtrees location to form an offspring.
(self, random_state)
| 674 | return self.crossover(chicken, random_state) |
| 675 | |
| 676 | def hoist_mutation(self, random_state): |
| 677 | """Perform the hoist mutation operation on the program. |
| 678 | |
| 679 | Hoist mutation selects a random subtree from the embedded program to |
| 680 | be replaced. A random subtree of that subtree is then selected and this |
| 681 | is 'hoisted' into the original subtrees location to form an offspring. |
| 682 | This method helps to control bloat. |
| 683 | |
| 684 | Parameters |
| 685 | ---------- |
| 686 | random_state : RandomState instance |
| 687 | The random number generator. |
| 688 | |
| 689 | Returns |
| 690 | ------- |
| 691 | program : list |
| 692 | The flattened tree representation of the program. |
| 693 | |
| 694 | """ |
| 695 | program = self.program.copy() |
| 696 | # Get a subtree to replace |
| 697 | start, end = get_subtree_func(random_state, program) |
| 698 | subtree = program[start:end] |
| 699 | # Get a subtree of the subtree to hoist |
| 700 | sub_start, sub_end = get_subtree_func(random_state, subtree) |
| 701 | hoist = subtree[sub_start:sub_end] |
| 702 | # Determine which nodes were removed for plotting |
| 703 | removed = list(set(range(start, end)) - |
| 704 | set(range(start + sub_start, start + sub_end))) |
| 705 | return self.program[:start] + hoist + self.program[end:], removed |
| 706 | |
| 707 | def point_mutation(self, random_state): |
| 708 | """Perform the point mutation operation on the program. |
no test coverage detected