Talk:Evolutionary algorithm: Difference between revisions

Content added Content deleted
(→‎Problem in previous Python implementation: use syntaxhighlight tags instead of lang)
Line 78: Line 78:
== Problem in previous Python implementation ==
== Problem in previous Python implementation ==
In the first Python example:
In the first Python example:
<lang Python>def mutaterate():
<syntaxhighlight lang="python">def mutaterate():
'Less mutation the closer the fit of the parent'
'Less mutation the closer the fit of the parent'
#This formula does not work as intended because it performs int division
#This formula does not work as intended because it performs int division
return 1-((perfectfitness - fitness(parent)) / perfectfitness * (1 - minmutaterate))</lang>
return 1-((perfectfitness - fitness(parent)) / perfectfitness * (1 - minmutaterate))
</syntaxhighlight>
For ex- ((20 - 10)/20*(1-0.09)) will evaluate to 0
For ex- ((20 - 10)/20*(1-0.09)) will evaluate to 0
Thus it gets stuck in an infinite loop waiting for mutation to occur.
Thus it gets stuck in an infinite loop waiting for mutation to occur.