Professional Documents
Culture Documents
2022/23
Assignment 3
Particle Swarm Optimisation algorithm:
Function minimisation
DEADLINE : 23/12/2022
DELIVERY: Brightspace (see “Delivery” for instructions)
GENERAL
For this assignment you will create a PSO algorithm that minimises the
following function:
2 2
(x-π) + (y-e) + sin(3*x+0.75) + cos(4*y-2.13)
In order to do so, remember the update rule of PSO that you will use to “move”
the particles:
V = w * V + c1*r1*(pbest - X) + c2*r2*(gbest - X)
X=X+V
where:
TIPS
• the function should be minimised which means that you are looking for the
smallest value(s)
• careful to avoid getting stuck in local minima, play with the parameters (w, c1
and c2) to confirm that you are getting to the absolute minimum
• be always aware of the shape of your arrays, you cannot use “+” between
differently shaped arrays. However, you can always reshape them...
STEPS
In case you need help to start, here are some useful steps. Try to tackle them
in order one at the time while keeping track of what the overall algorithm
does.
5 - Iterations:
• create an array with two random numbers to drive the particles’ movement
(r)
• update the array of velocities following the rule described in ”Introduction”
• update the array of positions by using the array of velocities to ”move” the
particles
• calculate again the function values based on the new positions
• for each particle, if the new function value is better than the old one, update
pbest
• now select the new gbest from all the pbests
6 - After iterations:
• print final gbest and respective function value
GRADING
Functionality: the code uses PSO to find the global minimum with a good
approximation (~3.3, ~2.8). It could be easily used for another function. 6
points
Structure: the code is divided into functions, the amount of global code is
minimised. 1 point
Comments: the code is well commented (the right amount of information to
understand what the code does). 0.5 point
Numpy: the code uses numpy arrays and related functions instead of lists
(besides eventual array creation). 1 point
Values: the values used for c1, c2 and w are indeed optimised through
experimentation. 0.5 point
Visualization: the student visualises in a graph the location of the minimum in
the function (besides this, you are free to pick the type of representation). 1
point
DELIVERY
After you are sure about the result, compress the code into a .zip file.
Rename the .zip file using your student number + “_3” like in the following
example:
Upload the resulting .zip file on Brightspace under “Assignments” > “Assignment
3 - PSO”