Lecture07-Testing
Lecture07-Testing
INTELLIGENCE
DR. MANAL TANTAWI
ASSOCIATE PROFESSOR
IN
SCIENTIFIC COMPUTING DEPARTMENT
FACULTY OF COMPUTER & INFORMATION
SCIENCES
AIN SHAMS UNIVERSITY
PART 6
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
➢ 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
➢ 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.
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.