0% found this document useful (0 votes)
3 views

Lecture07-Testing

The document provides an overview of Particle Swarm Optimization (PSO), a computational method inspired by the behavior of swarms, such as bees, to find optimal solutions in complex search spaces. It details the PSO algorithm's life cycle, including the initialization of particles, fitness calculation, and updating positions and velocities based on cognitive and social components. The document also discusses the importance of stopping criteria to determine when the algorithm has converged on a solution.

Uploaded by

dekukunmc
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lecture07-Testing

The document provides an overview of Particle Swarm Optimization (PSO), a computational method inspired by the behavior of swarms, such as bees, to find optimal solutions in complex search spaces. It details the PSO algorithm's life cycle, including the initialization of particles, fitness calculation, and updating positions and velocities based on cognitive and social components. The document also discusses the importance of stopping criteria to determine when the algorithm has converged on a solution.

Uploaded by

dekukunmc
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

ARTIFICIAL

INTELLIGENCE
DR. MANAL TANTAWI
ASSOCIATE PROFESSOR
IN
SCIENTIFIC COMPUTING DEPARTMENT
FACULTY OF COMPUTER & INFORMATION
SCIENCES
AIN SHAMS UNIVERSITY
PART 6

➢Particle Swarm Optimization (PSO)


WHAT IS PARTICLE SWARM OPTIMIZATION?
Particle swarm optimization (PSO) involves a group of individuals at different points in the solution space,
all using real-life swarm concepts to find an optimal solution in the space. Imagine a swarm of bees that
spreads out looking for flowers and gradually converges on an area that has the most density of flowers.
As more bees find the flowers, more are attracted to the flowers. At its core, this example is what particle
swarm optimization entails.
OPTIMIZATION PROBLEMS: A SLIGHTLY MORE
TECHNICAL PERSPECTIVE
OPTIMIZATION PROBLEMS: A SLIGHTLY MORE
TECHNICAL PERSPECTIVE
OPTIMIZATION PROBLEMS: A SLIGHTLY MORE
TECHNICAL PERSPECTIVE
It is to complex. Thus,
it is difficult to find
the optimum x and
y that minimize the
function. What about
higher dimensions!?
PARTICLE SWARM OPTIMIZATION
(PSO)
• PARTICLE SWARM OPTIMIZATION ALGORITHMS ARE PARTICULARLY
USEFUL IN THE FOLLOWING SCENARIOS:
• LARGE SEARCH SPACES—THERE ARE MANY DATA POINTS AND
POSSIBILITIES OF COMBINATIONS.
• SEARCH SPACES WITH HIGH DIMENSIONS—THERE IS
COMPLEXITY IN HIGH DIMENSIONS. MANY DIMENSIONS OF A
PROBLEM ARE REQUIRED TO FIND A GOOD SOLUTION.
APPLY PSO FOR DRONE EXAMPLE

The fitness function for the ratio between aluminum (x) and plastic (y). The result is a
performance score based on drag and wobble, given the input values for x and y. we need
to find the optimum values for x and y to minimize the score.
WHAT DO PARTICLES LOOK LIKE?

Current Position

Best Position

Velocity

The following represent the concept of a particle:


➢ Position—The position of the particle in all dimensions.

➢ Best position—The best position found using the fitness function.

➢ Velocity—The current velocity of the particle’s movement.


PARTICLE SWARM OPTIMIZATION (PSO) ALGORITHM
LIFE CYCLE
SET UP THE POPULATION OF PARTICLES
The three factors that are important in initializing the particles are:

➢ Number of particles—The number of particles influences computation. The more particles that exist, the
more computation is required. Additionally, more particles will likely mean that converging on a global best
solution will take longer because more particles are attracted to their local best solutions. The constraints of
the problem also affect the number of particles. A larger search space may need more particles to explore it.
There could be as many as 1,000 particles or as few as 4. Usually, 50 to 100 particles produce good solutions
without being too computationally expensive.

➢ Starting position for each particle—The starting position for each particle should be a random position in all
the respective dimensions. It is important that the particles are distributed evenly across the search space. If
most of the particles are in a specific region of the search space, they will struggle to find solutions outside
that area.

➢ Starting velocity for each particle: The velocity of particles is initialized to 0 because the particles have not
been affected yet. A good analogy is that birds begin takeoff for flight from a stationary position.
SET UP THE POPULATION OF PARTICLES

Data attributes for each particle:


CALCULATE THE FITNESS OF EACH PARTICLE
➢ The next step is calculating the fitness of each particle at its current position. The fitness of particles is
calculated every time the entire swarm changes position.

➢ In the drone scenario, the scientists provided a function in which the result is the amount of drag and wobble
given a specific number of aluminum and plastic components. This function is used as the fitness function in the
particle swarm optimization algorithm in this example, If x is aluminum and y is plastic, the calculations can be
made for each particle to determine its fitness by substituting x and y for the values of aluminum and plastic.
CALCULATE THE FITNESS OF EACH PARTICLE
CALCULATE THE FITNESS OF EACH PARTICLE
UPDATE THE POSITION OF EACH PARTICLE
➢ The update step encompasses the properties of swarm intelligence in nature into a
mathematical model that allows the search space to be explored while homing in on good
solutions.

➢ Particles in the swarm update their position given a cognitive ability and factors in the
environment around them, such as inertia and what the swarm is doing. These factors influence
the velocity and position of each particle. The first step is understanding how velocity is
updated. The velocity determines the direction and speed of movement of the particle.

➢ The particles in the swarm move to different points in the search space to find better solutions.
Each particle relies on its memory of a good solution and the knowledge of the swarm’s best
solution.
UPDATE THE
POSITION OF
EACH PARTICLE
THE COMPONENTS OF UPDATING VELOCITY
THE COMPONENTS OF UPDATING VELOCITY
Three components are used to calculate the new velocity of each particle: inertia, cognitive, and social.
Each component influences the movement of the particle.

Inertia—The inertia component represents the resistance to movement or change in direction for a
specific particle that influences its velocity. The inertia component consists of two values: the inertia
magnitude and the current velocity of the particle. The inertia value is a number between 0 and 1.

A value closer to 0 translates to exploration, potentially taking more iterations.


A value closer to 1 translates to more exploration for particles in fewer iterations.

Cognitive—The cognitive component represents the internal cognitive ability of a specific particle. The
cognitive ability is a sense of a particle knowing its best position and using that position to influence its
movement. The cognitive constant is a number greater than 0 and less than 2. A greater cognitive
constant means more exploitation by the particles.
THE COMPONENTS OF UPDATING VELOCITY

Social—The social component represents the ability of a particle to interact with the swarm. A particle knows the
best position in the swarm and uses this information to influence its movement. Social acceleration is determined
by using a constant and scaling it with a random number. The social constant remains the same for the lifetime of
the algorithm, and the random factor encourages diversity in favoring the social factor. The greater the social
constant, the more exploration there will be, because the particle favors its social component more. The social
constant is a number between 0 and 2. A greater social constant means more exploration.
COMPUTING NEW VELOCITY
EXERCISE: CALCULATE THE NEW VELOCITY AND POSITION FOR PARTICLE 1 GIVEN THE FOLLOWING INFORMATION ABOUT THE
PARTICLES
Inertia is set to 0.1.
The cognitive constant is set to 0.5, and the cognitive random number is 0.2.
The social constant is set to 0.5, and the Social random number is 0.5.
COMPUTING NEW VELOCITY
COMPUTING NEW VELOCITY
COMPUTING NEW VELOCITY
By adding the current position and new velocity, we can determine the new position of each particle and
update the table of particle attributes with the new velocities. Then the fitness of each particle is
calculated again, given its new position, and its best position is remembered.

New position for first particle: (4+ 2.0426. 8+2.0426) = (6.0426, 10.0426)

Now particle1 is updated in the table you can also compute and update particles 2, 3 and 4.
STOPPING CRITERIA
The number of iterations influences several aspects of finding
solutions, including:
Exploration—Particles require time to explore the search space to find
areas with better solutions. Exploration is also influenced by the
constants defined in the update velocity function.
Exploitation—Particles should converge on a good solution after
reasonable exploration occurs.

A strategy to stop the algorithm is to examine the best solution in the


swarm and determine whether it is stagnating. Stagnation occurs
when the value of the best solution doesn’t change or doesn’t change
by a significant amount. Running more iterations in this scenario will
not help find better solutions. When the best solution stagnates, the
parameters in the update function can be adjusted to favor more
exploration. If more exploration is desired, this adjustment usually
means more iterations. Stagnation could mean that a good solution
was found or that that the swarm is stuck on a local best solution. If
enough exploration occurred at the start, and the swarm gradually
stagnates, the swarm has converged on a good solution
CREDIT FOR
Grokking-Artificial-Intelligence-Algorithms- rishal-hurbans
THANK YOU

You might also like