For the real case. Particle positions are real vectors representing at each time step possible solutions to the problem you are trying to optimize. On the other hand, particle velocities are real vectors representing how these candidate solutions change in a step as the algorithm tries to find better optima during its search. In canonical PSO, velocities are updated based on the differences between particle current position and its best historical position and the best historical position find by all the swarm. Think of it as if the particle moves while being attracted by two centers of gravity denoted by its best historical position and the global best. Hope this helps. Cheers.
You have a function to optimize f(x). You can define random vectors x1, x2, x3,...xn, where n represents the number of particles. These vectors define initial positions of your particles and you can calculate current local optimal solutions as f(xloc(1)),...f(xloc(n)). Among them there will be current global optimal solution f(xglob). Then you define vectors of velocities corresponding to each particle v1, v2,...vn. These values can be initially random but then they update according to local and global optimal solutions. The velocity vectors are used to update the positions x1,...xn. So, at each iteration you basically move your particles in a certain direction, update f(xloc(1)),...f(xloc(n)) and f(xglob) if necessary, update v1, v2,...vn, move to a new x1, x2,...xn and repeat all the steps again until your f(xglob) does not change so much or until the iteration limit defined by you.
A particle' s position can be represented as a binary bit string of length N, where N is the total number of attributes. Every bit represents an attribute, the value ` 1'means the corresponding attribute is selected while ` 0'not selected. Each position is an attribute subset.
Example solution-position: Pi =[0 1 0 0 1 1 0 1 0 1]
Velocity representation
The velocity of each particle is represented as a positive integer, varying between 1and Vmax.
It implies how many of the particle’s bits (features) should be changed, at a particular moment in time, to be the same as that of the global best position, i.e. the velocity of the particle flying toward the best position.
The number of different bits between two particles relates to the difference between their positions.
For example, Pgbest=[1 0 1 1 1 0 1 0 0 1], Pi =[0 1 0 0 1 1 0 1 0 1]. The difference between gbest and the particle’s current position is Pgbest-Pi=[1 –1 1 1 0 –1 1 –1 0 0 ].
A value of 1 indicates that compared with the best position, this bit (feature) should be selected but is not, which will decrease classification quality and lead to a lower fitness value. On the other hand, a value of -1 indicates that, compared with the best position, this bit should not be selected, but is selected
Assume that the number of 1’s is a.
The number of -1’s is b.
We use the value of (a-b) to express the distance between two positions; (a-b) may be positive or negative. Such variation makes particles exhibit an exploration ability within the solution space. In this example, (a-b)=4-3=1, so Pg - Pi =1
Article Feature Selection based on Rough Sets and Particle Swarm Optimization