Salp Swarm Algorithm (SSA)¶
A module for the Salp Swarm Algorithm with parallel computing support.
Original paper: Mirjalili, S., Gandomi, A. H., Mirjalili, S. Z., Saremi, S., Faris, H., & Mirjalili, S. M. (2017). Salp Swarm Algorithm: A bio-inspired optimizer for engineering design problems. Advances in Engineering Software, 114, 163-191.
What can you use?¶
Multi processing: ✔️
Discrete spaces: ✔️
Continuous spaces: ✔️
Mixed Discrete/Continuous spaces: ✔️
Parameters¶
-
class
neorl.evolu.ssa.SSA(mode, bounds, fit, nsalps=5, int_transform='nearest_int', ncores=1, seed=None)[source]¶ Salp Swarm Algorithm
- Parameters
mode – (str) problem type, either
minfor minimization problem ormaxfor maximizationbounds – (dict) input parameter type and lower/upper bounds in dictionary form. Example:
bounds={'x1': ['int', 1, 4], 'x2': ['float', 0.1, 0.8], 'x3': ['float', 2.2, 6.2]}fit – (function) the fitness function
nsalps – (int): number of salps in the swarm
int_transform – (str): method of handling int/discrete variables, choose from:
nearest_int,sigmoid,minmax.ncores – (int) number of parallel processors (must be
<= nsalps)seed – (int) random seed for sampling
-
evolute(ngen, x0=None, c1=None, verbose=False)[source]¶ This function evolutes the SSA algorithm for number of generations.
- Parameters
ngen – (int) number of generations to evolute
x0 – (list of lists) initial position of the salps (must be of same size as
nsalps)c1 – (float/list): a scalar value or a list of values with size
ngenfor the coefficient that controls exploration/exploitation. IfNone, default annealing formula forc1is used (see Notes below for more info).verbose – (bool) print statistics to screen
- Returns
(tuple) (best individual, best fitness, and dictionary containing major search results)
Example¶
from neorl import SSA
#Define the fitness function
def FIT(individual):
"""Sphere test objective function.
F(x) = sum_{i=1}^d xi^2
d=1,2,3,...
Range: [-100,100]
Minima: 0
"""
y=sum(x**2 for x in individual)
return y
#Setup the parameter space (d=5)
nx=5
BOUNDS={}
for i in range(1,nx+1):
BOUNDS['x'+str(i)]=['float', -100, 100]
nsalps=20
#setup and evolute SSA
ssa=SSA(mode='min', bounds=BOUNDS, fit=FIT, nsalps=nsalps, ncores=1, seed=1)
x_best, y_best, ssa_hist=ssa.evolute(ngen=100, c1=None, verbose=1)
Notes¶
SSA mimics the swarming behavior of salps when navigating and foraging in oceans. SSA cares mostly about the leading salp, where its position is optimized to achieve better food source (i.e. fitness).
Salp leader is mostly controlled by the coefficient
c1, which balances SSA exploration and exploitation. The default formula for \(c_1 = 2e^{-(4g/ngen)^2}\), where \(g\) is the current generation (goes from 1 tongen), and \(ngen\) is the total number of generations to evolute (ngen). Therefore,c1is typically annealed from a large value at the beginning to increase exploration, to a very small value toward the end of evolution to prioritize exploitation.The user can also provide a scalar/fixed value for
c1to overwrite the default annealing formula described above. Also, the user can provide a schedule forc1generated by another formula in alistform. The size of the list MUST equal tongen. For example, forngen=5, the user can providec1=[5, 0.5, 0.05, 0.005, 0.0005], where for every generation, the correspondingc1value is used.Therefore, if
c1=None, the user should notice thatngenvalue used within the.evolutefunction has an impact on thec1value and hence on SSA overall performance.ncoresargument evaluates the fitness of all salps in the swarm in parallel. Therefore, setncores <= nsalpsfor most optimal resource allocation.Look for an optimal balance between
nsalpsandngen, it is recommended to minimize the number ofnsalpsto allow for more updates and more generations.Total number of cost evaluations for SSA is
nsalps*(ngen + 1).