optimization

Particle Swarm Optimization

Implementation of a particle swarm optimization.

Created on Fri Mar 8, 13:51:45 2019.

@author: HugoFara

pylinkage.optimization.particle_swarm.particle_swarm_optimization(eval_func, linkage, center=None, dimensions=None, n_particles=100, leader=3.0, follower=0.1, inertia=0.6, neighbors=17, iters=200, bounds=None, order_relation=<built-in function max>, verbose=True, **kwargs)

Particle Swarm Optimization wrapper for pyswarms.

This function is a simple wrapper to optimize a linkage using PSO. It will mainly call the LocalBestPSO function from pyswarms.single.

Parameters:
  • eval_func (Callable -> float) – The evaluation function. Input: (linkage, num_constraints, initial_coordinates). Output: score (float). The swarm will look for the HIGHEST score.

  • linkage (pylinkage.linkage.Linkage) – Linkage to be optimized. Make sure to give an optimized linkage for better results

  • center (list) – A list of initial dimensions. If None, dimensions will be generated randomly between bounds. The default is None.

  • dimensions (int) – Number of dimensions of the swarm space, number of parameters. If None, it takes the value len(tuple(linkage.get_num_constraints())). The default is None.

  • n_particles (float) – Number of particles in the swarm. The default is 100.

  • inertia (float) – Inertia of each particle, w in pyswarms. The default is .3.

  • leader (float) – Learning coefficient of each particle, c1 in pyswarms. The default is .2.

  • follower (float) – Social coefficient, c2 in pyswarms. The default is .5.

  • neighbors (int) – Number of neighbors to consider. The default is 17.

  • iters (int) – Number of iterations to describe. The default is 200.

  • bounds (sequence of two list of float) – Bounds to the space, in format (lower_bound, upper_bound). (Default value = None)

  • order_relation (Callable(float, float) -> float) – How to compare scores. There should not be anything else than the built-in max and min functions. The default is max.

  • verbose (bool) – The optimization state will be printed in the console if True. (Default value = True).

  • kwargs (dict) – keyword arguments to pass to pyswarm.local.single.LocalBestPSO.

Returns:

List of 3 elements: best score, best dimensions and initial positions.

Return type:

Agent

Utility

Utility for optimization.

pylinkage.optimization.utils.generate_bounds(center, min_ratio=5, max_factor=5)

Simple function to generate bounds from a linkage.

Parameters:
  • center (Iterable) – 1-D sequence, often in the form of linkage.get_num_constraints().

  • min_ratio (float) – Minimal compression ratio for the bounds. Minimal bounds will be of the shape center[x] / min_ratio. (Default value = 5)

  • max_factor (float) – Dilation factor for the upper bounds. Maximal bounds will be of the shape center[x] * max_factor. (Default value = 5)