Ignore:
Timestamp:
06/30/17 21:57:38 (22 months ago)
Author:
abeham
Message:

#2797:

  • Recreated backwards compatibility by readding old operators and renaming new operators to SPSO*
    • If a previously configured algorithm is run again, the same results should be obtained
  • Set all old operators to internal, NonDiscoverableType, and Obsolete (they are also not fixed, e.g. PersonalBest update remains flawed)
  • Added SPSO 2007 velocity initializer and let users choose in SPSOParticleCreator
  • Changed description of PSO
  • Updated sample
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorNeighborhoodParticleUpdater.cs

    r15096 r15102  
    3030  [StorableClass]
    3131  [NonDiscoverableType]
    32   [Obsolete("Replaced by SPSO2007ParticleUpdater")]
     32  [Obsolete("Use SPSO2011ParticleUpdater")]
    3333  internal sealed class RealVectorNeighborhoodParticleUpdater : RealVectorParticleUpdater {
    3434
     
    4343    #endregion
    4444
    45     private void UpdateVelocity() {
    46       var velocity = VelocityParameter.ActualValue;
    47       var position = RealVectorParameter.ActualValue;
    48       var inertia = CurrentInertiaParameter.ActualValue.Value;
    49       var personalBest = PersonalBestParameter.ActualValue;
    50       var personalBestAttraction = PersonalBestAttractionParameter.ActualValue.Value;
    51       var neighborBest = NeighborBestParameter.ActualValue;
    52       var neighborBestAttraction = NeighborBestAttractionParameter.ActualValue.Value;
     45    public override IOperation Apply() {
     46      double inertia = Inertia.Value;
     47      double personalBestAttraction = PersonalBestAttraction.Value;
     48      double neighborBestAttraction = NeighborBestAttraction.Value;
    5349
    54       var random = RandomParameter.ActualValue;
     50      RealVector velocity = new RealVector(Velocity.Length);
     51      RealVector position = new RealVector(RealVector.Length);
     52      double r_p = Random.NextDouble();
     53      double r_g = Random.NextDouble();
    5554
    5655      for (int i = 0; i < velocity.Length; i++) {
    57         double r_p = random.NextDouble();
    58         double r_g = random.NextDouble();
    5956        velocity[i] =
    60           velocity[i] * inertia +
    61           (personalBest[i] - position[i]) * personalBestAttraction * r_p +
    62           (neighborBest[i] - position[i]) * neighborBestAttraction * r_g;
     57          Velocity[i] * inertia +
     58          (PersonalBest[i] - RealVector[i]) * personalBestAttraction * r_p +
     59          (BestPoint[i] - RealVector[i]) * neighborBestAttraction * r_g;
    6360      }
    6461
    65       var maxVelocity = CurrentMaxVelocityParameter.ActualValue.Value;
    66       var speed = Math.Sqrt(velocity.DotProduct(velocity));
    67       if (speed > maxVelocity) {
    68         for (var i = 0; i < velocity.Length; i++) {
    69           velocity[i] *= maxVelocity / speed;
    70         }
    71       }
    72     }
    73 
    74     private void UpdatePosition() {
    75       var velocity = VelocityParameter.ActualValue;
    76       var position = RealVectorParameter.ActualValue;
    77 
    78       for (int i = 0; i < velocity.Length; i++) {
    79         position[i] += velocity[i];
    80       }
    81 
    82       var bounds = BoundsParameter.ActualValue;
    83       for (int i = 0; i < position.Length; i++) {
    84         double min = bounds[i % bounds.Rows, 0];
    85         double max = bounds[i % bounds.Rows, 1];
    86         if (position[i] < min) {
    87           position[i] = min;
    88           velocity[i] = -0.5 * velocity[i]; // SPSO 2011
    89         }
    90         if (position[i] > max) {
    91           position[i] = max;
    92           velocity[i] = -0.5 * velocity[i]; // SPSO 2011
    93         }
    94       }
    95     }
    96 
    97     public override IOperation Apply() {
    98       UpdateVelocity();
    99       UpdatePosition();
     62      MoveParticle(velocity, position);
    10063
    10164      return base.Apply();
Note: See TracChangeset for help on using the changeset viewer.