PSO_optimizer

class nrv.optim.PSO_optimizer(n_particles=5, bounds=(0, 0), dimensions=50, options=None, maxiter=1, n_processes=None, init_pos=None, print_time=False, opt_type='global', static=False, ftol=None, ftol_iter=1, bh_strategy='nearest', oh_strategy=None, save_results=False, saving_file='pso_results.json', comment=None)[source]

Perform a Particle swarm optimization (PSO) on with a defined cost function using pyswarms library[1]

Parameters:
  • n_particles (int) – number of particle of the swarm, by default 5

  • dimensions (int) – number of dimensions of each particle

  • options (dict) – hyperparameter of the PSO

  • maxiter (int) – number of iteration of the PSO

  • n_processes (int) – number of process used to parallelize cost calculation, by default None

  • bounds (tupple) – bounds of the particle, if equal no bounds, by default (0, 0)

  • init_pos (array) – initial position of the particles if None random, by default None

  • print_time (bool) – if True, print the optimisation time, by default True

  • opt_type (str) –

    Neightboorhood type, by default “global” type possibly:

    • ”global” : Global best PSO (star topology)

    • ”local” : Local best PSO (ring topology)

  • static (bool) – if False and opt_type is local, update the neigthboorhood of each particle every iterations

  • bh_strategy (str) –

    out of bound position strategy for pyswarms optimizer [2]:

    • ”nearest” : Round the value to the nearest bound (default)

    • ”periodic” : set to the modulus of the value between the two bounds

    • ”random” : set to a random value

    • ”shrink” : reduce the velocity to finish land on the bound

    • ”reflective” : mirror the position form inside to ouside the bounds

    • ”intermediate” : set to intermediate value between previous pos and bound

  • oh_strategy (dict (like {"w":str, "c1":str, "c2":str})) –

    Dynamic options strategy for pyswarms optimizer [3], if None static options, by default None:

    • ”exp_decay” : Decreases the parameter exponentially between limits

    • ”lin_variation” : Decreases/increases the parameter linearly between limits

    • ”nonlin_mod”Decreases/increases the parameter between limits

      according to a nonlinear modulation index

    • ”rand” : takes a uniform random value between limits

  • ftol (int) – relative error in objective_func(best_pos) acceptable for convergence, if None -np.inf default None

  • ftol – number of iterations over which the relative error in objective_func(best_pos) is acceptable for convergence, by default 1

  • save_results (bool) – save or not the output in a .json file, by default False

  • saving_file (str) – name of the file on wich the output should be saved, by default “pso_results.json”

Returns:

results – contains all the parameters and outputs of the PSO

Return type:

optim_results

References

links to pyswarms doc:

[1] Pyswams

[2] Pyswams handlers

Methods

PSO_optimizer.__init__([n_particles, ...])

Init method for NRV_class

PSO_optimizer.get_parameters()

Generic method returning all the atributes of an NRV_class instance

PSO_optimizer.load(data[, blacklist])

Generic loading method for NRV_class instance

PSO_optimizer.minimize(f_swarm, **kwargs)

Perform a Particle swarm optimization

PSO_optimizer.save([save, fname, blacklist])

Generic saving method for NRV_class instance.

PSO_optimizer.set_parameters(**kawrgs)

Generic method to set any attribute of NRV_class instance