根据我阅读 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_lo 和b_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
您当然也可以简化更新速度,但我建议您坚持公式给出的速度。