corrected weight factor and updated doc
This commit is contained in:
parent
ef252cf7de
commit
f3e1e35ea3
2 changed files with 26 additions and 24 deletions
|
|
@ -37,7 +37,7 @@
|
||||||
|
|
||||||
|
|
||||||
/** Standard velocity performer for particle swarm optimization. Derivated from abstract eoVelocity,
|
/** Standard velocity performer for particle swarm optimization. Derivated from abstract eoVelocity,
|
||||||
* At step t: v(t+1)= c1 * v(t) + c2 * r2 * ( xbest(t)-x(t) ) + c3 * r3 * ( gbest(t) - x(t) )
|
* At step t: v(t+1)= w * v(t) + c1 * r1 * ( xbest(t)-x(t) ) + c2 * r2 * ( gbest(t) - x(t) )
|
||||||
* (ci given and Ri chosen at random in [0;1]).
|
* (ci given and Ri chosen at random in [0;1]).
|
||||||
*/
|
*/
|
||||||
template < class POT > class eoStandardVelocity:public eoVelocity < POT >
|
template < class POT > class eoStandardVelocity:public eoVelocity < POT >
|
||||||
|
|
@ -52,25 +52,25 @@ public:
|
||||||
|
|
||||||
/** Full constructor: Bounds and bound modifier required
|
/** Full constructor: Bounds and bound modifier required
|
||||||
* @param _topology - The topology to get the global/local/other best
|
* @param _topology - The topology to get the global/local/other best
|
||||||
* @param _c1 - The first learning factor quantify how much the particle trusts itself. Type must be POT::ParticleVelocityType
|
* @param _w - The weight factor.
|
||||||
* @param _c2 - The second learning factor used for the particle's best. Type must be POT::ParticleVelocityType
|
* @param _c1 - The second learning factor used for the particle's best. Type must be POT::ParticleVelocityType
|
||||||
* @param _c3 - The third learning factor used for the local/global best(s). Type must be POT::ParticleVelocityType
|
* @param _c2 - The third learning factor used for the local/global best(s). Type must be POT::ParticleVelocityType
|
||||||
* @param _bounds - An eoRealBaseVectorBounds: real bounds for real velocities.
|
* @param _bounds - An eoRealBaseVectorBounds: real bounds for real velocities.
|
||||||
* If the velocities are not real, they won't be bounded by default. Should have a eoBounds ?
|
* If the velocities are not real, they won't be bounded by default. Should have a eoBounds ?
|
||||||
* @param _boundsModifier - An eoRealBoundModifier used to modify the bounds (for real bounds only).
|
* @param _boundsModifier - An eoRealBoundModifier used to modify the bounds (for real bounds only).
|
||||||
* @param _gen - The eo random generator, default=rng
|
* @param _gen - The eo random generator, default=rng
|
||||||
*/
|
*/
|
||||||
eoStandardVelocity (eoTopology < POT > & _topology,
|
eoStandardVelocity (eoTopology < POT > & _topology,
|
||||||
const VelocityType & _c1,
|
const VelocityType & _w,
|
||||||
|
const VelocityType & _c1,
|
||||||
const VelocityType & _c2,
|
const VelocityType & _c2,
|
||||||
const VelocityType & _c3,
|
|
||||||
eoRealVectorBounds & _bounds,
|
eoRealVectorBounds & _bounds,
|
||||||
eoRealBoundModifier & _bndsModifier,
|
eoRealBoundModifier & _bndsModifier,
|
||||||
eoRng & _gen = rng):
|
eoRng & _gen = rng):
|
||||||
topology(_topology),
|
topology(_topology),
|
||||||
|
omega (_w),
|
||||||
c1 (_c1),
|
c1 (_c1),
|
||||||
c2 (_c2),
|
c2 (_c2),
|
||||||
c3 (_c3),
|
|
||||||
bounds(_bounds),
|
bounds(_bounds),
|
||||||
bndsModifier(_bndsModifier),
|
bndsModifier(_bndsModifier),
|
||||||
gen(_gen){}
|
gen(_gen){}
|
||||||
|
|
@ -78,43 +78,43 @@ public:
|
||||||
|
|
||||||
/** Constructor: No bound updater required <-> fixed bounds
|
/** Constructor: No bound updater required <-> fixed bounds
|
||||||
* @param _topology - The topology to get the global/local/other best
|
* @param _topology - The topology to get the global/local/other best
|
||||||
* @param _c1 - The first learning factor quantify how much the particle trusts itself. Type must be POT::ParticleVelocityType
|
* @param _w - The weight factor.
|
||||||
* @param _c2 - The second learning factor used for the particle's best. Type must be POT::ParticleVelocityType
|
* @param _c1 - The second learning factor used for the particle's best. Type must be POT::ParticleVelocityType
|
||||||
* @param _c3 - The third learning factor used for the local/global best(s). Type must be POT::ParticleVelocityType
|
* @param _c2 - The third learning factor used for the local/global best(s). Type must be POT::ParticleVelocityType
|
||||||
* @param _bounds - An eoRealBaseVectorBounds: real bounds for real velocities.
|
* @param _bounds - An eoRealBaseVectorBounds: real bounds for real velocities.
|
||||||
* If the velocities are not real, they won't be bounded by default. Should have a eoBounds ?
|
* If the velocities are not real, they won't be bounded by default. Should have a eoBounds ?
|
||||||
* @param _gen - The eo random generator, default=rng
|
* @param _gen - The eo random generator, default=rng
|
||||||
*/
|
*/
|
||||||
eoStandardVelocity (eoTopology < POT > & _topology,
|
eoStandardVelocity (eoTopology < POT > & _topology,
|
||||||
|
const VelocityType & _w,
|
||||||
const VelocityType & _c1,
|
const VelocityType & _c1,
|
||||||
const VelocityType & _c2,
|
const VelocityType & _c2,
|
||||||
const VelocityType & _c3,
|
|
||||||
eoRealVectorBounds & _bounds,
|
eoRealVectorBounds & _bounds,
|
||||||
eoRng & _gen = rng):
|
eoRng & _gen = rng):
|
||||||
topology(_topology),
|
topology(_topology),
|
||||||
|
omega (_w),
|
||||||
c1 (_c1),
|
c1 (_c1),
|
||||||
c2 (_c2),
|
c2 (_c2),
|
||||||
c3 (_c3),
|
|
||||||
bounds(_bounds),
|
bounds(_bounds),
|
||||||
bndsModifier(dummyModifier),
|
bndsModifier(dummyModifier),
|
||||||
gen(_gen){}
|
gen(_gen){}
|
||||||
|
|
||||||
|
|
||||||
/** Constructor: Neither bounds nor bound updater required <-> free velocity
|
/** Constructor: Neither bounds nor bound updater required <-> free velocity
|
||||||
* @param _c1 - The first learning factor quantify how much the particle trusts itself. Type must be POT::ParticleVelocityType
|
* @param _w - The weight factor.
|
||||||
* @param _c2 - The second learning factor used for the particle's best. Type must be POT::ParticleVelocityType
|
* @param _c1 - The second learning factor used for the particle's best. Type must be POT::ParticleVelocityType
|
||||||
* @param _c3 - The third learning factor used for the local/global best(s). Type must be POT::ParticleVelocityType
|
* @param _c2 - The third learning factor used for the local/global best(s). Type must be POT::ParticleVelocityType
|
||||||
* @param _gen - The eo random generator, default=rng
|
* @param _gen - The eo random generator, default=rng
|
||||||
*/
|
*/
|
||||||
eoStandardVelocity (eoTopology < POT > & _topology,
|
eoStandardVelocity (eoTopology < POT > & _topology,
|
||||||
|
const VelocityType & _w,
|
||||||
const VelocityType & _c1,
|
const VelocityType & _c1,
|
||||||
const VelocityType & _c2,
|
const VelocityType & _c2,
|
||||||
const VelocityType & _c3,
|
|
||||||
eoRng & _gen = rng):
|
eoRng & _gen = rng):
|
||||||
topology(_topology),
|
topology(_topology),
|
||||||
c1 (_c1),
|
omega (_w),
|
||||||
|
c1 (_c1),
|
||||||
c2 (_c2),
|
c2 (_c2),
|
||||||
c3 (_c3),
|
|
||||||
bounds(*(new eoRealVectorNoBounds(0))),
|
bounds(*(new eoRealVectorNoBounds(0))),
|
||||||
bndsModifier(dummyModifier),
|
bndsModifier(dummyModifier),
|
||||||
gen(_gen)
|
gen(_gen)
|
||||||
|
|
@ -129,14 +129,14 @@ public:
|
||||||
*/
|
*/
|
||||||
void operator () (POT & _po,unsigned _indice)
|
void operator () (POT & _po,unsigned _indice)
|
||||||
{
|
{
|
||||||
|
VelocityType r1;
|
||||||
VelocityType r2;
|
VelocityType r2;
|
||||||
VelocityType r3;
|
|
||||||
|
|
||||||
VelocityType newVelocity;
|
VelocityType newVelocity;
|
||||||
|
|
||||||
// cast the learning factors to VelocityType
|
// cast the learning factors to VelocityType
|
||||||
|
r1 = (VelocityType) rng.uniform (1) * c1;
|
||||||
r2 = (VelocityType) rng.uniform (1) * c2;
|
r2 = (VelocityType) rng.uniform (1) * c2;
|
||||||
r3 = (VelocityType) rng.uniform (1) * c3;
|
|
||||||
|
|
||||||
// need to resize the bounds even if there are dummy because of "isBounded" call
|
// need to resize the bounds even if there are dummy because of "isBounded" call
|
||||||
bounds.adjust_size(_po.size());
|
bounds.adjust_size(_po.size());
|
||||||
|
|
@ -144,7 +144,7 @@ public:
|
||||||
// assign the new velocities
|
// assign the new velocities
|
||||||
for (unsigned j = 0; j < _po.size (); j++)
|
for (unsigned j = 0; j < _po.size (); j++)
|
||||||
{
|
{
|
||||||
newVelocity= c1 * _po.velocities[j] + r2 * (_po.bestPositions[j] - _po[j]) + r3 * (topology.best (_indice)[j] - _po[j]);
|
newVelocity= omega * _po.velocities[j] + r1 * (_po.bestPositions[j] - _po[j]) + r2 * (topology.best (_indice)[j] - _po[j]);
|
||||||
|
|
||||||
/* check bounds */
|
/* check bounds */
|
||||||
if (bounds.isMinBounded(j))
|
if (bounds.isMinBounded(j))
|
||||||
|
|
@ -174,9 +174,9 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
eoTopology < POT > & topology;
|
eoTopology < POT > & topology;
|
||||||
|
const VelocityType & omega; // social/cognitive coefficient
|
||||||
const VelocityType & c1; // social/cognitive coefficient
|
const VelocityType & c1; // social/cognitive coefficient
|
||||||
const VelocityType & c2; // social/cognitive coefficient
|
const VelocityType & c2; // social/cognitive coefficient
|
||||||
const VelocityType & c3; // social/cognitive coefficient
|
|
||||||
|
|
||||||
eoRealVectorBounds bounds; // REAL bounds even if the velocity could be of another type.
|
eoRealVectorBounds bounds; // REAL bounds even if the velocity could be of another type.
|
||||||
eoRealBoundModifier & bndsModifier;
|
eoRealBoundModifier & bndsModifier;
|
||||||
|
|
|
||||||
|
|
@ -77,9 +77,11 @@ int main()
|
||||||
// Terminators
|
// Terminators
|
||||||
eoGenContinue <Particle> genCont (50);
|
eoGenContinue <Particle> genCont (50);
|
||||||
|
|
||||||
|
// the full initializer
|
||||||
|
eoInitializer <Particle> init(eval,veloRandom,localInit,topology,pop);
|
||||||
|
|
||||||
// PS flight
|
// PS flight
|
||||||
eoEasyPSO<Particle> pso(genCont, eval, velocity, flight);
|
eoEasyPSO<Particle> pso(init,genCont, eval, velocity, flight);
|
||||||
|
|
||||||
|
|
||||||
// flight
|
// flight
|
||||||
|
|
|
||||||
Reference in a new issue