41 lines
2.9 KiB
Plaintext
41 lines
2.9 KiB
Plaintext
Starting with:
|
||
* The <code>target</code> string: <code>"METHINKS IT IS LIKE A WEASEL"</code>.
|
||
* An array of random characters chosen from the set of upper-case letters together with the space, and of the same length as the target string. (Call it the <code>parent</code>).
|
||
* A <code>fitness</code> function that computes the ‘closeness’ of its argument to the target string.
|
||
* A <code>mutate</code> function that given a string and a mutation rate returns a copy of the string, with some characters probably mutated.
|
||
* While the <code>parent</code> is not yet the <code>target</code>:
|
||
:* copy the <code>parent</code> C times, each time allowing some random probability that another character might be substituted using <code>mutate</code>.
|
||
:* Assess the <code>fitness</code> of the parent and all the copies to the <code>target</code> and make the most fit string the new <code>parent</code>, discarding the others.
|
||
:* repeat until the parent converges, (hopefully), to the target.
|
||
|
||
|
||
;See also:
|
||
* Wikipedia entry: [[wp:Weasel_program#Weasel_algorithm|Weasel algorithm]].
|
||
* Wikipedia entry: [[wp:Evolutionary algorithm|Evolutionary algorithm]].
|
||
|
||
<br>
|
||
<small>Note: to aid comparison, try and ensure the variables and functions mentioned in the task description appear in solutions</small>
|
||
|
||
<br>
|
||
A cursory examination of a few of the solutions reveals that the instructions have not been followed rigorously in some solutions. Specifically,
|
||
* While the <code>parent</code> is not yet the <code>target</code>:
|
||
:* copy the <code>parent</code> C times, each time allowing some random probability that another character might be substituted using <code>mutate</code>.
|
||
|
||
Note that some of the the solutions given retain characters in the mutated string that are ''correct'' in the target string. However, the instruction above does not state to retain any of the characters while performing the mutation. Although some may believe to do so is implied from the use of "converges"
|
||
|
||
(:* repeat until the parent converges, (hopefully), to the target.
|
||
|
||
Strictly speaking, the new parent should be selected from the new pool of mutations, and then the new parent used to generate the next set of mutations with parent characters getting retained only by ''not'' being mutated. It then becomes possible that the new set of mutations has no member that is fitter than the parent!
|
||
|
||
As illustration of this error, the code for 8th has the following remark.
|
||
|
||
Create a new string based on the TOS, '''changing randomly any characters which
|
||
don't already match the target''':
|
||
|
||
''NOTE:'' this has been changed, the 8th version is completely random now
|
||
|
||
Clearly, this algo will be applying the mutation function only to the parent characters that don't match to the target characters!
|
||
|
||
To ensure that the new parent is never less fit than the prior parent, both the parent and all of the latest mutations are subjected to the fitness test to select the next parent.
|
||
<br><br>
|