cbx.dynamics.PSO#

class cbx.dynamics.PSO(f, m=0.001, gamma=None, lamda_memory=0.4, sigma_memory=None, **kwargs)[source]#

Bases: CBXDynamic

Particle Swarm Optimization class

This class implements the PSO algorithm as described in [1] and [2]. The algorithm is a particle dynamic algorithm that is used to minimize the objective function \(f(x)\).

Parameters:
  • f (objective) – The objective function \(f(x)\) of the system.

  • x (array_like, shape (N, d)) – The initial positions of the particles. For a system of \(N\) particles, the i-th row of this array x[i,:] represents the position \(x_i\) of the i-th particle.

  • y (array_like, shape (N, d)) – The initial positions of the particles. For a system of \(N\) particles, the i-th row of this array y[i,:] represents the or an approximation of the historical best position \(y_i\) of the i-th particle.

  • v (array_like, shape (N, d)) – The initial velocities of the particles. For a system of \(N\) particles, the i-th row of this array y[i,:] represents the or an approximation of the historical best position \(y_i\) of the i-th particle.

  • dt (float, optional) – The parameter \(dt\) of the system. The default is 0.1.

  • alpha (float, optional) – The heat parameter \(\alpha\) of the system. The default is 1.0.

  • m (float, optional) – The inertia \(m\) of the system. The default is 0.1.

  • gamma (float, optional) – The friction coefficient \(\gamma\) of the system. The default is 1-m.

  • lamda (float, optional) – The decay parameter \(\lambda\) of the system. The default is 1.0.

  • noise (noise_model, optional) – The noise model that is used to compute the noise vector. The default is normal_noise(dt=0.1).

  • sigma (float, optional) – The parameter \(\sigma\) of the noise model. The default is 1.0.

  • lamda_memory (float, optional) – The decay parameter \(\lambda_{\text{memory}}\) of the system. The default is 1.0.

  • sigma_memory (float, optional) – The parameter \(\sigma_{\text{memory}}\) of the noise model. The default is 1.0.

References

pre_step()[source]#

The pre-step function. This function is used in meth:step before the inner step is performed. This function can be overwritten by subclasses to perform any pre-steps before the inner step.

Parameters:

None

Returns:

None

inner_step()[source]#

Performs one step of the PSO algorithm.

Parameters:

None

Return type:

None

compute_consensus(x_batch, energy)[source]#

Updates the weighted mean of the particles.

Parameters:

None

Return type:

None