View Source PSO (Bia v0.1.0)

Implementation of Particle Swarm Optimization in Elixir.

Velocity is updated with

$$ v_{i,d} \leftarrow \omega v_{i,d} + \phi_p r_p (p_{i,d}-x_{i,d}) + \phi_g r_g (g_d-x_{i,d}) $$

Summary

Functions

Creates a new instance of a PSO.

Runs a given instance of an initialized Swarm with pid supervisor and options opts.

Types

@type config() :: keyword()
@type results() :: map()
@type supervisor() :: pid()

Functions

@spec new(keyword()) :: {supervisor(), config()}

Creates a new instance of a PSO.

Options

  • :population_size (pos_integer/0) - The number of particles to be used in the optimization. The default value is 10.

  • :num_iterations (non_neg_integer/0) - The number of iterations to be done in the optimization. The default value is 100.

  • :dimensions (pos_integer/0) - The dimensions of the search space. The default value is 2.

  • :bound_up (float/0) - The upper boundary of the search space. The default value is 5.12.

  • :bound_down (float/0) - The lower boundary of the search space. The default value is -5.12.

  • :inertia (float/0) - The inertia each particle carries each move. Should be smaller than 1. The default value is 0.6.

  • :coeff_p (float/0) - The cognitive coefficient. The default value is 1.0.

  • :coeff_g (float/0) - The social coefficient. The default value is 3.0.

  • :fun (function of arity 1) - The function to optimize. The default value is &Nx.sum/1.

  • :callback (function of arity 1) - A function to be called after each iteration. The default value is &PSO.callback/1.

  • :widget (term/0) - A widget for getting the data visualized. The default value is nil.

Return Values

The function returns a tuple of two values:

  • supervisor - the pid of the created Swarm supervisor.

  • opts - the parameters of the initialized Swarm.

@spec run({supervisor(), config()}) :: results()

Runs a given instance of an initialized Swarm with pid supervisor and options opts.

Return Values

The function returns a map with the following:

  • best_position - the position of the best result found.

  • best - the best result found.