Skip to contents

The Python module morie.fn.pswrm is the seeded stochastic version of this method. It cannot be checked across languages: its numbers come from Python's native generator stream and this tree's Philox produces a different sequence from the same seed, so numeric parity between the arms is impossible by construction. This is the deterministic sibling – the same algorithm driven by a van der Corput sequence with a distinct prime base per coordinate, so both language arms visit the same points in the same order.

Usage

Psoop(f, bounds, n_particles = 20, w = 0.7, c1 = 1.5, c2 = 1.5, maxiter = 200)

Arguments

f

Objective f(x), minimised.

bounds

List or matrix of (lo, hi) pairs, one per dimension; at most 16 dimensions.

n_particles

Swarm size, at least 1.

w

Inertia coefficient, non-negative.

c1

Cognitive coefficient, non-negative.

c2

Social coefficient, non-negative.

maxiter

Iterations, non-negative.

Value

List with estimate, value, x, n_eval, n_particles, maxiter, d.

Details

Formula: v <- w v + c1 r1 (p_best - x) + c2 r2 (g_best - x), x <- clip(x + v, lo, hi), with r1, r2 from the low-discrepancy stream instead of a uniform generator.

References

Kennedy, J. & Eberhart, R. (1995). Particle swarm optimization. Proceedings of ICNN'95, volume 4, pages 1942-1948. doi:10.1109/ICNN.1995.488968 .

Examples

rosen <- function(x) (1 - x[1])^2 + 100 * (x[2] - x[1]^2)^2
Psoop(rosen, bounds = list(c(-2, 2), c(-1, 3)), n_particles = 30, maxiter = 150)$x
#> [1] 0.9993817 0.9987634