(pop)
Linear Scaling scheme

   .. warning :: Linear Scaling is only for positive raw scores
Linear Scaling scheme
Linear Scaling scheme
def LinearScaling(pop):
   """ Linear Scaling scheme

   .. warning :: Linear Scaling is only for positive raw scores

   """
   logging.debug("Running linear scaling.")
   pop.statistics()
   c = Consts.CDefScaleLinearMultiplier
   a = b = delta = 0.0

   pop_rawAve = pop.stats["rawAve"]
   pop_rawMax = pop.stats["rawMax"]
   pop_rawMin = pop.stats["rawMin"]

   if pop_rawAve == pop_rawMax:
      a = 1.0
      b = 0.0
   elif pop_rawMin > (c * pop_rawAve - pop_rawMax / c - 1.0):
      delta = pop_rawMax - pop_rawAve
      a = (c - 1.0) * pop_rawAve / delta
      b = pop_rawAve * (pop_rawMax - (c * pop_rawAve)) / delta
   else:
      delta = pop_rawAve - pop_rawMin
      a = pop_rawAve / delta
      b = -pop_rawMin * pop_rawAve / delta

   for i in xrange(len(pop)):
      f = pop[i].score
      if f < 0.0:
         Util.raiseException("Score %r is negative, linear scaling not supported !" % (f,), ValueError)
      f = f * a + b
      if f < 0:
         f = 0.0
      pop[i].fitness = f
def LinearScaling ( pop ) : logging . debug ( "Running linear scaling." ) pop . statistics ( ) c = Consts . CDefScaleLinearMultiplier a = b = delta = 0.0 pop_rawAve = pop . stats [ "rawAve" ] pop_rawMax = pop . stats [ "rawMax" ] pop_rawMin = pop . stats [ "rawMin" ] if pop_rawAve == pop_rawMax : a = 1.0 b = 0.0 elif pop_rawMin > ( c * pop_rawAve - pop_rawMax / c - 1.0 ) : delta = pop_rawMax - pop_rawAve a = ( c - 1.0 ) * pop_rawAve / delta b = pop_rawAve * ( pop_rawMax - ( c * pop_rawAve ) ) / delta else : delta = pop_rawAve - pop_rawMin a = pop_rawAve / delta b = - pop_rawMin * pop_rawAve / delta for i in xrange ( len ( pop ) ) : f = pop [ i ] . score if f < 0.0 : Util . raiseException ( "Score %r is negative, linear scaling not supported !" % ( f , ) , ValueError ) f = f * a + b if f < 0 : f = 0.0 pop [ i ] . fitness = f