In [1]:
import numpy as np
from plotPSO import plotPSO_2D, plotPSO_1D
from optitestfuns import ackley, griewangk, rastrigin, salomon, odd_square, schwefel, rana

In [2]:
# Testing 2D plot ackley

limits=([-5,5],
        [-5,5])

x_lo = limits[0][0]
x_up = limits[0][1]
y_lo = limits[1][0]
y_up = limits[1][1]

n_particles = 10

x_particles = np.random.uniform(x_lo, x_up, size=n_particles)
y_particles = np.random.uniform(y_lo, y_up, size=n_particles)

particle_xycoordinates = (x_particles, y_particles)

fig, ax = plotPSO_2D(ackley, particle_xycoordinates, limits)



In [3]:
# Testing 1D plot

limits=(-5,5)

x_lo = limits[0]
x_up = limits[1]

n_particles = 10

x_particles = np.random.uniform(x_lo, x_up, size=n_particles)
y_particles = np.random.uniform(y_lo, y_up, size=n_particles)

particle_xycoordinates = x_particles

fig, ax = plotPSO_1D(ackley, particle_xycoordinates, limits )



In [4]:
# Testing 2D plot Griewangk

limits=([-100,100],
        [-100,100])
0
x_lo = limits[0][0]
x_up = limits[0][1]
y_lo = limits[1][0]
y_up = limits[1][1]

n_particles = 10

x_particles = np.random.uniform(x_lo, x_up, size=n_particles)
y_particles = np.random.uniform(y_lo, y_up, size=n_particles)

particle_xycoordinates = (x_particles, y_particles)

fig, ax = plotPSO_2D(griewangk, particle_xycoordinates, limits)



In [5]:
# Testing 1D plot griewangk

limits=(-100,100)

x_lo = limits[0]
x_up = limits[1]

n_particles = 10

x_particles = np.random.uniform(x_lo, x_up, size=n_particles)
y_particles = np.random.uniform(y_lo, y_up, size=n_particles)

particle_xycoordinates = x_particles

fig, ax = plotPSO_1D(griewangk, particle_xycoordinates, limits )



In [6]:
# Testing 2D plot Rastrigin

limits=([-5.12,5.12],
        [-5.12,5.12])

x_lo = limits[0][0]
x_up = limits[0][1]
y_lo = limits[1][0]
y_up = limits[1][1]

n_particles = 10

x_particles = np.random.uniform(x_lo, x_up, size=n_particles)
y_particles = np.random.uniform(y_lo, y_up, size=n_particles)

particle_xycoordinates = (x_particles, y_particles)

fig, ax = plotPSO_2D(rastrigin, particle_xycoordinates, limits)



In [7]:
# Testing 1D plot Rastrigin

limits=(-5.12,5.12)

x_lo = limits[0]
x_up = limits[1]

n_particles = 10

x_particles = np.random.uniform(x_lo, x_up, size=n_particles)
y_particles = np.random.uniform(y_lo, y_up, size=n_particles)

particle_xycoordinates = x_particles

fig, ax = plotPSO_1D(rastrigin, particle_xycoordinates, limits )



In [8]:
# Testing 2D plot Salomon

limits=([-2,2],
        [-2,2])

x_lo = limits[0][0]
x_up = limits[0][1]
y_lo = limits[1][0]
y_up = limits[1][1]

n_particles = 10

x_particles = np.random.uniform(x_lo, x_up, size=n_particles)
y_particles = np.random.uniform(y_lo, y_up, size=n_particles)

particle_xycoordinates = (x_particles, y_particles)

fig, ax = plotPSO_2D(salomon, particle_xycoordinates, limits)



In [9]:
# Testing 1D plot Salomon

limits=(-2,2)

x_lo = limits[0]
x_up = limits[1]

n_particles = 10

x_particles = np.random.uniform(x_lo, x_up, size=n_particles)
y_particles = np.random.uniform(y_lo, y_up, size=n_particles)

particle_xycoordinates = x_particles

fig, ax = plotPSO_1D(salomon, particle_xycoordinates, limits )



In [10]:
# Testing 2D plot Odd Square

limits=([-5,5],
        [-5,5])

x_lo = limits[0][0]
x_up = limits[0][1]
y_lo = limits[1][0]
y_up = limits[1][1]

n_particles = 10

x_particles = np.random.uniform(x_lo, x_up, size=n_particles)
y_particles = np.random.uniform(y_lo, y_up, size=n_particles)

particle_xycoordinates = (x_particles, y_particles)

fig, ax = plotPSO_2D(odd_square, particle_xycoordinates, limits)



In [11]:
# Testing 1D plot Odd_square

limits=(-5,5)

x_lo = limits[0]
x_up = limits[1]

n_particles = 10

x_particles = np.random.uniform(x_lo, x_up, size=n_particles)
y_particles = np.random.uniform(y_lo, y_up, size=n_particles)

particle_xycoordinates = x_particles

fig, ax = plotPSO_1D(odd_square, particle_xycoordinates, limits )



In [12]:
# Testing 2D plot Schwefel
limits=([-500,500],
        [-500,500])

x_lo = limits[0][0]
x_up = limits[0][1]
y_lo = limits[1][0]
y_up = limits[1][1]

n_particles = 10

x_particles = np.random.uniform(x_lo, x_up, size=n_particles)
y_particles = np.random.uniform(y_lo, y_up, size=n_particles)

particle_xycoordinates = (x_particles, y_particles)

fig, ax = plotPSO_2D(schwefel, particle_xycoordinates, limits)