Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/29/17 23:04:03 (7 years ago)
Author:
abeham
Message:

#2797:

  • Added SPSO 2007 and SPSO 2011 particle updaters
  • Unhide particle updater parameter
  • Changed default parameters of sample
  • Changed max velocity to very high value by default (no speed limit)
  • Adapted unit test
File:
1 edited

Legend:

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

    r15091 r15096  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
    25 using HeuristicLab.Optimization;
    2625using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2726using HeuristicLab.PluginInfrastructure;
     
    3130  [StorableClass]
    3231  [NonDiscoverableType]
    33   [Obsolete("Same as the RealVectorNeighborhoodParticleUpdate")]
     32  [Obsolete("Replaced by SPSO2007ParticleUpdater")]
    3433  internal sealed class RealVectorTotallyConnectedParticleUpdater : RealVectorParticleUpdater {
    3534
     
    4443    #endregion
    4544
     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;
     53
     54      var random = RandomParameter.ActualValue;
     55
     56      for (int i = 0; i < velocity.Length; i++) {
     57        double r_p = random.NextDouble();
     58        double r_g = random.NextDouble();
     59        velocity[i] =
     60          velocity[i] * inertia +
     61          (personalBest[i] - position[i]) * personalBestAttraction * r_p +
     62          (neighborBest[i] - position[i]) * neighborBestAttraction * r_g;
     63      }
     64
     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
    4697    public override IOperation Apply() {
    4798      UpdateVelocity();
Note: See TracChangeset for help on using the changeset viewer.