polarcbo.dynamic.CBO
- class polarcbo.dynamic.CBO(x, V, noise, beta=1.0, noise_decay=0.0, diff_exp=1.0, tau=0.1, sigma=1.0, lamda=1.0, M=None, overshoot_correction=False, heavi_correction=False)[source]
Bases:
ParticleDynamic
Consensus-based optimization (CBO) class
This class implements the CBO algorithm as described in [1]. The algorithm is a particle dynamic algorithm that is used to minimize the objective function \(V(x)\).
- Parameters:
x (array_like, shape (J, d)) – The initial positions of the particles. For a system of \(J\) particles, the i-th row of this array
x[i,:]
represents the position \(x_i\) of the i-th particle.V (obejective) – The objective function \(V(x)\) of the system.
beta (float, optional) – The heat parameter \(\beta\) 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(tau=0.1)
.noise_decay (float, optional) – The decay parameter \(\lambda\) of the noise model. The default is 0.0.
diff_exp (float, optional) – The exponent \(\alpha\) of the difference vector \(x_i - \mathsf{m}(x_i)\). The default is 1.0.
tau (float, optional) – The parameter \(\tau\) of the noise model. The default is 0.1.
sigma (float, optional) – The parameter \(\sigma\) of the noise model. The default is 1.0.
lamda (float, optional) – The decay parameter \(\lambda\) of the noise model. The default is 1.0.
M (int, optional) – The number of particles that are used to compute the batch mean \(\mathsf{m}(x_i)\) as described in [2]. The default is
None
. IfNone
, then \(M = J\).overshoot_correction (bool, optional) – If
True
, then the overshoot correction is used as described in [3]. The default isFalse
.heavi_correction (bool, optional) – If
True
, then the Heaviside correction is used as described in [4]. The default isFalse
.
References
- step(time=0.0)[source]
Performs one step of the CBO algorithm.
- Parameters:
time (float, optional) – The current time of the algorithm. The default is 0.0.
- compute_mean(ind=None)[source]
Computes the mean of the particles.
- Parameters:
ind (array_like, optional) – The indices of the particles that are used to compute the mean. The default is
None
. IfNone
, then all particles are used.- Returns:
m_beta – The mean of the particles.
- Return type:
numpy.ndarray