Beispiel #1
0
# Refer: https://arxiv.org/pdf/1308.4008.pdf (Momin, J. A. M. I. L., & Yang, X. S. (2013). A literature survey of benchmark functions for global optimization problems. Journal of Mathematical Modelling and Numerical Optimisation, 4(2), 150-194.)

import numpy as np
import matplotlib.pyplot as plt
import pso_solver

pso_solver.setSeed(1)
lower = xlower = ylower = zlower = -20
upper = xupper = yupper = zupper = 20
particleList = pso_solver.createRandomParticleList(3, numParticles=100, lower=lower, upper=upper)

# Testing on Rosenbrock function
f = lambda x, y, z: 100 * ((z - y**2)**2 + (y - x**2)**2) + ((x-1)**2 + (y-1)**2 + (z-1)**2)

pso_solver.psoVisualizeTrivariate(particleList, f, xlower, xupper, ylower, yupper, zlower, zupper, c1=1, c2=1, W=0.5, numIters=20, maxFlag=False, sleepTime=0.5, accuracy=2, verbose=False)
Beispiel #2
0
import numpy as np
import matplotlib.pyplot as plt
import pso_solver

pso_solver.setSeed()

lower = xlower = 0
upper = xupper = 2 * np.pi
particleList = pso_solver.createRandomParticleList(1,
                                                   numParticles=10,
                                                   lower=lower,
                                                   upper=upper)

# Testing on a univariate function
f = lambda x: np.cos(x)

pso_solver.psoVisualizeUnivariate(particleList,
                                  f,
                                  xlower,
                                  xupper,
                                  c1=1,
                                  c2=1,
                                  W=0.5,
                                  numIters=30,
                                  maxFlag=False,
                                  sleepTime=0.1,
                                  density=100,
                                  fColor='b',
                                  particleColor='r',
                                  accuracy=2,
                                  verbose=False)