Example #1
0
 def __init__(self, dimension, bound, d_function, n_nest):
     self.pa = 0.25 #parameter
     self.dimension = dimension
     self.bound = bound
     self.d_function = d_function
     self.nests = [(d_function(*p), p) for p in lhs.latin_hypercube(dimension, bound, n_nest)]
     self.best_value, self.best = max(self.nests)
Example #2
0
File: cs.py Project: wilsonsd/imago
 def __init__(self, dimension, bound, d_function, n_nest):
     self.pa = 0.25  #parameter
     self.dimension = dimension
     self.bound = bound
     self.d_function = d_function
     self.nests = [(d_function(*p), p)
                   for p in lhs.latin_hypercube(dimension, bound, n_nest)]
     self.best_value, self.best = max(self.nests)
Example #3
0
def optimize(dimension, boundary, function_d, n_parts, n_turns):
    """Optimize *function_d* of given *dimension* in space bounded by
    symmetrical *boundary*. Use *n_parts* particles for *n_turn* turns."""
    pool = multiprocessing.Pool(None)
    v_max = boundary
    particles = [
        particle(dimension, boundary, v_max, function_d, pos)
        for pos in lhs.latin_hypercube(dimension, bound, n_parts)
    ]
    gl_best = max(particles)
    for _ in xrange(n_turns):
        move_p = partial(move,
                         omega=0.98,
                         phi_p=2.75,
                         phi_g=3.,
                         v_max=v_max,
                         global_best=gl_best[1],
                         func_d=function_d)
        particles = pool.map(move_p, particles)
        gl_best = max(max(particles), gl_best)
    pool.terminate()
    pool.join()
    return gl_best[1]