예제 #1
0
 def frombounds(cls, func, lbound, ubound, npop, crossover_rate=0.5,
         scale=None, strategy=('rand', 2, 'bin'), eps=1e-6):
     lbound = sp.asarray(lbound)
     ubound = sp.asarray(ubound)
     pop0 = stats.rand(npop, len(lbound))*(ubound-lbound) + lbound
     return cls(func, pop0, crossover_rate=crossover_rate, scale=scale,
         strategy=strategy, eps=eps)
예제 #2
0
 def bin_crossover(self, oldgene, newgene):
     mask = stats.rand(self.ndim) < self.crossover_rate
     return sp.where(mask, newgene, oldgene)