From: Tomas Musil Date: Tue, 10 Dec 2013 15:39:05 +0000 (+0100) Subject: restarting the search X-Git-Url: http://git.tomasm.cz/imago.git/commitdiff_plain/676b17ccc2d334fd2574bd26aef14c8381f6aaaa restarting the search --- diff --git a/imago_pack/cs.py b/imago_pack/cs.py index 7c91119..6273651 100644 --- a/imago_pack/cs.py +++ b/imago_pack/cs.py @@ -14,10 +14,10 @@ class Space(object): self.best_value, self.best = max(self.nests) def new_nest(space): - position = [2 * space.bound * random.random() - - space.bound for _ in xrange(space.dimension)] - value = space.d_function(*position) - return (value, position) + position = [2 * space.bound * random.random() + - space.bound for _ in xrange(space.dimension)] + value = space.d_function(*position) + return (value, position) def get_cuckoos(space): beta = 1.5 @@ -64,8 +64,13 @@ def next_turn(space): space.nests = [max(n, m) for (n, m) in zip(space.nests, nests)] space.best_value, space.best = max(space.nests) -def optimize(dimension, boundary, function_d, n_nest, n_turns): - space = Space(dimension, boundary, function_d, n_nest) - for _ in xrange(n_turns): - next_turn(space) - return space.best +def optimize(dimension, boundary, function_d, n_nest, n_turns, reset=1): + best_list = [] + for i in xrange(reset): + space = Space(dimension, boundary, function_d, n_nest) + for _ in xrange(n_turns / reset): + next_turn(space) + best_list.append((space.best_value, space.best)) + print space.best_value + + return max(best_list)[1] diff --git a/imago_pack/gridf.py b/imago_pack/gridf.py index 3bb7c54..6a80c44 100644 --- a/imago_pack/gridf.py +++ b/imago_pack/gridf.py @@ -62,7 +62,7 @@ def find(lines, size, l1, l2, bounds, hough, show_all, do_something): f_dist = partial(job_4, im_l=im_l_s, v1=v1, v2=v2, h1=h1, h2=h2, dv=delta_v, dh=delta_h, size=size) - x_v, y_v, x_h, y_h = Optimizer.optimize(4, 30, f_dist, 128, 256) + x_v, y_v, x_h, y_h = Optimizer.optimize(4, 30, f_dist, 64, 256, 4) v1 = (v1[0] + x_v * delta_v, v1[1] + x_v) v2 = (v2[0] + y_v * delta_v, v2[1] + y_v)