corrected PSO dummy errors and completed documentation

This commit is contained in:
tlegrand 2008-01-08 14:50:13 +00:00
commit 4b99bc8bc9
12 changed files with 581 additions and 281 deletions

View file

@ -18,7 +18,8 @@
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: clive.canape@inria.fr
Contact: thomas.legrand@lifl.fr
clive.canape@inria.fr
*/
//-----------------------------------------------------------------------------
@ -35,8 +36,9 @@
//-----------------------------------------------------------------------------
/** Standard velocity performer for particle swarm optimization. Derivated from abstract eoVelocity,
* At step t: v(t+1)= int (v(t) + c1*r1* ( xbest(t)-x(t) ) + c2*r2* ( gbest(t) - x(t) ))
/** Integer 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) )
* v(t) is an INT for any time step
* (ci given and Ri chosen at random in [0;1]).
*/
template < class POT > class eoIntegerVelocity:public eoVelocity < POT >
@ -51,22 +53,25 @@ public:
/** Full constructor: Bounds and bound modifier required
* @param _topology - The topology to get the global/local/other best
* @param _c1 - The first learning factor used for the particle's best. Type must be POT::ParticleVelocityType
* @param _c2 - The second learning factor used for the local/global best(s). Type must be POT::ParticleVelocityType
* @param _c1 - The first learning factor quantify how much the particle trusts itself. Type must be POT::ParticleVelocityType
* @param _c2 - 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 _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 ?
* @param _boundsModifier - An eoRealBoundModifier used to modify the bounds (for real bounds only).
* @param _gen - The eo random generator, default=rng
*/
eoIntegerVelocity (eoTopology < POT > & _topology,
const VelocityType & _c1,
const VelocityType & _c2 ,
const VelocityType & _c1,
const VelocityType & _c2,
const VelocityType & _c3,
eoRealVectorBounds & _bounds,
eoRealBoundModifier & _bndsModifier,
eoRng & _gen = rng):
topology(_topology),
c1 (_c1),
c2 (_c2),
c3 (_c3),
bounds(_bounds),
bndsModifier(_bndsModifier),
gen(_gen){}
@ -74,8 +79,9 @@ public:
/** Constructor: No bound updater required <-> fixed bounds
* @param _topology - The topology to get the global/local/other best
* @param _c1 - The first learning factor used for the particle's best. Type must be POT::ParticleVelocityType
* @param _c2 - The second learning factor used for the local/global best(s). Type must be POT::ParticleVelocityType
* @param _c1 - The first learning factor quantify how much the particle trusts itself. Type must be POT::ParticleVelocityType
* @param _c2 - 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 _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 ?
* @param _gen - The eo random generator, default=rng
@ -83,29 +89,33 @@ public:
eoIntegerVelocity (eoTopology < POT > & _topology,
const VelocityType & _c1,
const VelocityType & _c2,
const VelocityType & _c3,
eoRealVectorBounds & _bounds,
eoRng & _gen = rng):
topology(_topology),
c1 (_c1),
c2 (_c2),
c3 (_c3),
bounds(_bounds),
bndsModifier(dummyModifier),
gen(_gen){}
/** Constructor: Neither bounds nor bound updater required <-> free velocity
* @param _topology - The topology to get the global/local/other best
* @param _c1 - The first learning factor used for the particle's best. Type must be POT::ParticleVelocityType
* @param _c2 - The second learning factor used for the local/global best(s). Type must be POT::ParticleVelocityType
* @param _c1 - The first learning factor quantify how much the particle trusts itself. Type must be POT::ParticleVelocityType
* @param _c2 - 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 _gen - The eo random generator, default=rng
*/
eoIntegerVelocity (eoTopology < POT > & _topology,
const VelocityType & _c1,
const VelocityType & _c2,
const VelocityType & _c3,
eoRng & _gen = rng):
topology(_topology),
c1 (_c1),
c1 (_c1),
c2 (_c2),
c3 (_c3),
bounds(*(new eoRealVectorNoBounds(0))),
bndsModifier(dummyModifier),
gen(_gen)
@ -120,14 +130,14 @@ public:
*/
void operator () (POT & _po,unsigned _indice)
{
VelocityType r1;
VelocityType r2;
VelocityType r3;
VelocityType newVelocity;
// cast the learning factors to VelocityType
r1 = (VelocityType) rng.uniform (1) * c1;
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
bounds.adjust_size(_po.size());
@ -135,7 +145,7 @@ public:
// assign the new velocities
for (unsigned j = 0; j < _po.size (); j++)
{
newVelocity= round(_po.velocities[j] + r1 * (_po.bestPositions[j] - _po[j]) + r2 * (topology.best (_indice)[j] - _po[j]));
newVelocity= round (c1 * _po.velocities[j] + r2 * (_po.bestPositions[j] - _po[j]) + r3 * (topology.best (_indice)[j] - _po[j]));
/* check bounds */
if (bounds.isMinBounded(j))
@ -154,8 +164,8 @@ public:
{
topology.updateNeighborhood(_po,_indice);
}
//! eoTopology<POT> getTopology
//! eoTopology<POT> getTopology
//! @return topology
eoTopology<POT> & getTopology ()
@ -165,8 +175,9 @@ public:
protected:
eoTopology < POT > & topology;
const VelocityType & c1; // learning factor 1
const VelocityType & c2; // learning factor 2
const VelocityType & c1; // 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.
eoRealBoundModifier & bndsModifier;