Pyevolve Score in Evaluation function
<p>Here is an example of pyevolve library of Python,</p>

<pre><code>from pyevolve import G1DList
from pyevolve import GSimpleGA
import time
def eval_func(chromosome):
     score = 0.0
     for value in chromosome:
         if value == 50:
            score += 1
return score

genome = G1DList.G1DList(20)
genome.evaluator.set(eval_func)
ga = GSimpleGA.GSimpleGA(genome)
ga.evolve(freq_stats=10)
print ga.bestIndividual()
</code></pre>

<p>In this example score makes sense as with every increment in score the output will get more accurate.</p>

<p>But if I want sum of chromosome element to be some particular value say 200, then how to determine the score or what is the best way to create score. </p>

<p>Thanks </p>

<p>EDIT:</p>

<p>Here is the code for sum, but its not giving the correct/desired output. It will always be either greater or less than the required answer. </p>

<pre><code>from pyevolve import G1DList
from pyevolve import GSimpleGA
import time

def eval_func(chromosome):
    score = 0.0
    sum_  = 0.0

    for value in chromosome:
        sum_ = sum_ + value

    score_ = abs(200 - sum_)
    score  = float(1/score_)
    return score

genome = G1DList.G1DList(20)
genome.evaluator.set(eval_func)
ga = GSimpleGA.GSimpleGA(genome)
ga.evolve(freq_stats=10)
print ga.bestIndividual()
</code></pre>

<p>Please suggest some better score evaluation method.</p>

<p>Have the evaluation function take every element of the list and add the value of every element of the list. Then subtract the desired value from the the value you get and take the absolute value of the result. Finally put this under a a fraction like 1/(value) to return the highest value for the smallest number.</p>

python algorithm artificial-intelligence genetic-algorithm pyevolve