liveBook · Manning

Position vector

As explained in Grokking AI Algorithms, Second Edition

A position is the point or vector in a search space that represents a particle's candidate solution in particle swarm optimization.

A position vector is a particle’s location in the search space: its coordinates represent one candidate solution. In particle swarm optimization (PSO), each particle keeps its current position alongside its velocity and the best position it has found so far. section 7.4 section 7.5

Think of each particle as a scout exploring possible answers. Its position says where it is now; its best position records a promising place it has already visited. A fitness function scores a position so the algorithm can compare solutions. section 7.4 section 7.5

Positions change throughout a PSO search:

  • Initialize particles at random positions in every dimension. Spreading them across the search space helps avoid leaving regions unexplored. section 7.6
  • Evaluate fitness, then update each particle’s velocity and position. Movement is influenced by inertia, the particle’s best position, and the swarm’s best position. section 7.5 section 7.8
  • Evaluate the new positions and repeat until the stopping condition is met. Return the best position found by the swarm. section 7.5

A two-coordinate position

A particle starts at (-10, 1), where the coordinates represent aluminum and plastic. After an update, its position is approximately (-7.71, 3.3). Its fitness improves from 801 to 358.8, so the new position becomes its recorded best. section 7.6 section 7.8

class Particle:
    def __init__(self, x, y, inertia,
    ➥cognitive_constant, social_constant):
        self.x = x #A
        self.y = y #A
        self.fitness = math.inf
        self.velocity = (0.0, 0.0) #B
        self.best_x = x
        self.best_y = y #C
        self.best_fitness = math.inf #D
        self.inertia = inertia
        self.cognitive_constant = cognitive_constant
        self.social_constant = social_constant

See how a Python particle stores current coordinates, velocity, and best coordinates separately. section 7.4

Table 7.6 Data attributes for each particle

Particle

Velocity

Current aluminum

Current plastic

Current fitness

Best aluminum

Best plastic

Best fitness

1

0

7

1

104

7

1

104

2

1.52

0.52

10.52

255.3

-1

9

104

3

2.295

-7.71

3.3

358.8

-7.71

3.3

358.8

4

1.46

–0.54

-3.54

306.3

-0.54

-3.54

306.3

Compare current and best coordinates after particles move and their fitness is evaluated again. section 7.8

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Explains initialization, fitness evaluation, and position updates, with a worked two-coordinate particle example.
Examples
Traces particles with aluminum and plastic coordinates through initialization and an update.
What you can do after
Evaluate and understand how particle positions change during particle swarm optimization.
How it connects
Connects position to velocity, fitness, inertia, and personal and swarm best positions.

Also explained in

Compare how 3 books explain position vector →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking AI Algorithms, Second Edition. The section links point to the parts of the book it draws on.