From: Tomas Musil Date: Tue, 24 Jun 2014 14:47:50 +0000 (+0200) Subject: comments for pso X-Git-Url: http://git.tomasm.cz/imago.git/commitdiff_plain/0d4f4f5ff9d00a9a6f180dc2946767ffb154811a?hp=27d47d4ee9a7efae9a9e8660ae5343a7bd01f4dc comments for pso --- diff --git a/imago_pack/pso.py b/imago_pack/pso.py index 6d6fada..061fe3e 100644 --- a/imago_pack/pso.py +++ b/imago_pack/pso.py @@ -7,6 +7,7 @@ from functools import partial import lhs def particle(dimension, bound, v_max, func_d, pos=None): + """Create a new particle.""" if not pos: position = [2 * bound * random.random() - bound for _ in xrange(dimension)] else: @@ -16,6 +17,7 @@ def particle(dimension, bound, v_max, func_d, pos=None): return value, position, velocity, value, position def move(particle, omega, phi_p, phi_g, v_max, global_best, func_d): + """Move the *particle*.""" _, position, velocity, best_value, best_position = particle position = [p + v for (p, v) in zip(position, velocity)] velocity = [omega * v @@ -30,6 +32,8 @@ def move(particle, omega, phi_p, phi_g, v_max, global_best, func_d): return value, position, velocity, best_value, best_position 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)