def selStochasticUniversalSampling(individuals, k):
 s_inds = sorted(individuals, key=attrgetter('fitness'), reverse=True)
 sum_fits = sum((ind.fitness.values[0] for ind in individuals))
 distance = (sum_fits / float(k))
 start = random.uniform(0, distance)
 points = [(start + (i * distance)) for i in xrange(k)]
 chosen = []
 for p in points:
  i = 0
  sum_ = s_inds[i].fitness.values[0]
  while (sum_ < p):
   i += 1
   sum_ += s_inds[i].fitness.values[0]
  chosen.append(s_inds[i])
 return chosen

def selStochasticUniversalSampling ( individuals , k ) : s_inds = sorted ( individuals , key = attrgetter ( 'fitness' ) , reverse = True ) sum_fits = sum ( ( ind . fitness . values [ 0 ] for ind in individuals ) ) distance = ( sum_fits / float ( k ) ) start = random . uniform ( 0 , distance ) points = [ ( start + ( i * distance ) ) for i in xrange ( k ) ] chosen = [ ] for p in points : i = 0 sum_ = s_inds [ i ] . fitness . values [ 0 ] while ( sum_ < p ) : i += 1 sum_ += s_inds [ i ] . fitness . values [ 0 ] chosen . append ( s_inds [ i ] ) return chosen
select the *k* individuals among the input *individuals* .