Ejemplo n.º 1
0
 def __call__(self, iteration, logdir, population, best, best_cost):
     # don't write images if no improvement
     if (self.best_so_far != -1 and best_cost >= self.best_so_far):
         return
     self.best_so_far = best_cost
     #-TODO eliminate dependence on logdir
     img_h, img_w = self.img_shape[:2]
     decoded = np.empty((img_h, img_w, 3), dtype=np.int)
     fitness_ext.decode_rectangles(best, decoded)
     save_array_as_image(decoded, '%s/%04d.png' % (logdir, iteration))
Ejemplo n.º 2
0
 def __call__(self, iteration, logdir,
         population, global_best, global_best_cost):
     # don't write images if no improvement
     if (self.best_so_far != -1 and
             global_best_cost >= self.best_so_far):
         return
     self.best_so_far = global_best_cost
     #-TODO eliminate dependence on logdir
     img_h, img_w = self.img_shape[:2]
     decoded = np.empty((img_h, img_w, 3), dtype = np.int)
     fitness_ext.decode_rectangles(global_best, decoded)
     save_array_as_image(decoded, '%s/%04d.png'%(logdir, iteration))
Ejemplo n.º 3
0
def test_mutate():
    mutators = [g.mutate_shape, g.mutate_color, g.mutate_reorder,
            g.mutate_position, g.mutate_noise]

    shape = (len(mutators) + 1, 4)

    ind = indfactory.build()
    decoded = np.empty(IMG_SHAPE, dtype = np.int)
    f.decode_rectangles(ind.data, decoded)
    orig_decoded = decoded.copy()
    draw_in_grid(decoded, shape, 0, 0)

    for row in xrange(1, shape[0]):
        for col in xrange(shape[1]):
            mutated = mutators[row - 1](ind)
            # mutated = g.mutate(ind)
            f.decode_rectangles(mutated.data, decoded)
            draw_in_grid(decoded, shape, row, col)
Ejemplo n.º 4
0
def test_mutate():
    mutators = [
        g.mutate_shape, g.mutate_color, g.mutate_reorder, g.mutate_position,
        g.mutate_noise
    ]

    shape = (len(mutators) + 1, 4)

    ind = indfactory.build()
    decoded = np.empty(IMG_SHAPE, dtype=np.int)
    f.decode_rectangles(ind.data, decoded)
    orig_decoded = decoded.copy()
    draw_in_grid(decoded, shape, 0, 0)

    for row in xrange(1, shape[0]):
        for col in xrange(shape[1]):
            mutated = mutators[row - 1](ind)
            # mutated = g.mutate(ind)
            f.decode_rectangles(mutated.data, decoded)
            draw_in_grid(decoded, shape, row, col)
Ejemplo n.º 5
0
def test_xover():
    xovers = [g.crossover_unif, g.crossover_arith]
    pa = indfactory.build()
    ma = indfactory.build()
    decoded = np.empty(IMG_SHAPE, dtype = np.int)
    shape = (len(xovers) + 1, 10)
    f.decode_rectangles(pa.data, decoded)
    draw_in_grid(decoded, shape, 0, 0)
    f.decode_rectangles(ma.data, decoded)
    draw_in_grid(decoded, shape, 0, 1)
    for row in xrange(1, shape[0]):
        for col in xrange(shape[1]):
            kid = xovers[row - 1](pa, ma)
            f.decode_rectangles(kid.data, decoded)
            draw_in_grid(decoded, shape, row, col)
Ejemplo n.º 6
0
def test_xover():
    xovers = [g.crossover_unif, g.crossover_arith]
    pa = indfactory.build()
    ma = indfactory.build()
    decoded = np.empty(IMG_SHAPE, dtype=np.int)
    shape = (len(xovers) + 1, 10)
    f.decode_rectangles(pa.data, decoded)
    draw_in_grid(decoded, shape, 0, 0)
    f.decode_rectangles(ma.data, decoded)
    draw_in_grid(decoded, shape, 0, 1)
    for row in xrange(1, shape[0]):
        for col in xrange(shape[1]):
            kid = xovers[row - 1](pa, ma)
            f.decode_rectangles(kid.data, decoded)
            draw_in_grid(decoded, shape, row, col)
Ejemplo n.º 7
0
 def decode(self, particle):
     fitness_ext.decode_rectangles(particle.position, self.decoded)
Ejemplo n.º 8
0
 def decode(self, individual):
     fitness_ext.decode_rectangles(individual.data, self.decoded)
Ejemplo n.º 9
0
 def decode(self, individual):
     fitness_ext.decode_rectangles(individual.data, self.decoded)