将粒子群优化算法应用于多维搜索空间?

时间:2019-07-16 13:32:07

标签: python optimization particle-swarm

谁能帮助我了解如何将PSO算法(粒子群优化)应用于N维搜索空间中某个函数的优化问题,例如,我有一个函数,该函数具有7个参数,每个参数在其适当的间隔[min,max]与不同 一步步前进!

1 个答案:

答案 0 :(得分:0)

通过阅读PSO算法,我了解到,它已经具备处理多维空间中的功能的能力,因为它在N维矢量上运行。

您可以将要优化的每个参数等效为向量中的一个不同维度,并考虑函数(f)采用7维矢量而不是7个参数。

维基百科上的算法如下:

Let S be the number of particles in the swarm, each having a position xi ∈ ℝn in the search-space and a velocity vi ∈ ℝn.
Let pi be the best known position of particle i and let g be the best known position of the entire swarm. A basic PSO algorithm is then:[10]

for each particle i = 1, ..., S do
   Initialize the particle's position with a uniformly distributed random vector: x_i ~ U(b_lo, b_up)
   Initialize the particle's best known position to its initial position: p_i ← x_i
   if f(p_i) < f(g) then
       update the swarm's best known  position: g ← p_i
   Initialize the particle's velocity: vi ~ U(-|b_up-b_lo|, |b_up-b_lo|)
while a termination criterion is not met do:
   for each particle i = 1, ..., S do
      """for each dimension d = 1, ..., n do"""
         Pick random numbers: r_p, r_g ~ U(0,1)
         Update the particle's velocity: v_(i,d) ← ω v_(i,d) + φ_p r_p (p_(i,d)-x_(i,d)) + φ_g r_g (g_d-x_(i,d))
      Update the particle's position: x_i ← x_i + v_i
      if f(x_i) < f(p_i) then
         Update the particle's best known position: p_i ← x_i
         if f(p_i) < f(g) then
            Update the swarm's best known position: g ← p_i

The values b_lo and b_up represents the lower and upper boundaries of the search-space. 
The termination criterion can be the number of iterations performed, or a solution where the adequate objective function value is found.[11] 
The parameters ω, φ_p, and φ_g are selected by the practitioner and control the behaviour and efficacy of the PSO method, see below...

正如您在三重引号中看到的那样,对于每个粒子,它将更新每个单个维(即您的每个参数),因此您不必担心拥有N维。

您还可以将7个下边界写为向量b_lo,将7个上边界写为另一个向量b_up。似乎您担心的边界也只会影响使用b_lo和b_up的循环的初始迭代。


-由OP更新为问题-

因此,间隔似乎仅与b_lob_up有关。因此,在您的情况下,b_lo看起来像[7, 30, ...],而b_up看起来像[13, 90, ...]

有关步长,请在此处

Update the particle's velocity: v_(i,d) ← ω v_(i,d) + φ_p r_p (p_(i,d)-x_(i,d)) + φ_g r_g (g_d-x_(i,d))
      Update the particle's position: x_i ← x_i + v_i

如果要使每个维度中的步长保持不变,则必须为位置更新添加条件。我不建议这种情况发生,因为这样可能会花费更长的时间进行优化,并且您会失去这种优化的某些优势。

所以首先要有条件的:

if v_(i,d) < 0:
    Update the particle's position x_i ← x_i - (step_size for that dimension)
elif v_(i,d) > 0:
    Update the particle's position x_i ← x_i + (step_size for that dimension)
else v_(i,d) is 0:
    # You can either do one of the above updates or pass and not move the particle in this dimension

您也可以绝对简化速度的更新,但我建议您仅遵循公式给出的速度。