Perform the subtree mutation operation on the program. Subtree mutation selects a random subtree from the embedded program to be replaced. A donor subtree is generated at random and this is inserted into the original parent to form an offspring. This implementation u
(self, random_state)
| 648 | self.program[end:]), removed, donor_removed |
| 649 | |
| 650 | def subtree_mutation(self, random_state): |
| 651 | """Perform the subtree mutation operation on the program. |
| 652 | |
| 653 | Subtree mutation selects a random subtree from the embedded program to |
| 654 | be replaced. A donor subtree is generated at random and this is |
| 655 | inserted into the original parent to form an offspring. This |
| 656 | implementation uses the "headless chicken" method where the donor |
| 657 | subtree is grown using the initialization methods and a subtree of it |
| 658 | is selected to be donated to the parent. |
| 659 | |
| 660 | Parameters |
| 661 | ---------- |
| 662 | random_state : RandomState instance |
| 663 | The random number generator. |
| 664 | |
| 665 | Returns |
| 666 | ------- |
| 667 | program : list |
| 668 | The flattened tree representation of the program. |
| 669 | |
| 670 | """ |
| 671 | # Build a new naive program |
| 672 | chicken = self.build_program(random_state) |
| 673 | # Do subtree mutation via the headless chicken method! |
| 674 | return self.crossover(chicken, random_state) |
| 675 | |
| 676 | def hoist_mutation(self, random_state): |
| 677 | """Perform the hoist mutation operation on the program. |
no test coverage detected