Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/21/17 11:18:40 (7 years ago)
Author:
abeham
Message:

#2797: merged revisions 15071, 15076, 15091, 15092, 15093, 15096, 15102, 15114, 15181, 15201, 15214, 15223, 15224, 15228 to stable

Location:
stable
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Encodings.RealVectorEncoding

  • stable/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/SPSO2011ParticleUpdater.cs

    r15096 r15277  
    2525using HeuristicLab.Data;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.Random;
    2728
    2829namespace HeuristicLab.Encodings.RealVectorEncoding {
    2930  [Item("SPSO 2011 Particle Updater", "Updates the particle's position according to the formulae described in SPSO 2011.")]
    3031  [StorableClass]
    31   public sealed class SPSO2011ParticleUpdater : RealVectorParticleUpdater {
    32 
     32  public sealed class SPSO2011ParticleUpdater : SPSOParticleUpdater {
    3333    #region Construction & Cloning
    3434    [StorableConstructor]
     
    4141    #endregion
    4242   
    43     public static void UpdateVelocity(IRandom random, RealVector velocity, double maxVelocity, RealVector position, double inertia, RealVector personalBest, double personalBestAttraction, RealVector neighborBest, double neighborBestAttraction) {
     43    public static void UpdateVelocity(IRandom random, RealVector velocity, RealVector position, RealVector personalBest, RealVector neighborBest, double inertia = 0.721, double personalBestAttraction = 1.193, double neighborBestAttraction = 1.193, double maxVelocity = double.MaxValue) {
    4444      var gravity = new double[velocity.Length];
    45       var direct = new RealVector(velocity.Length);
     45      var direction = new RealVector(velocity.Length);
    4646      var radius = 0.0;
    4747
     48      var nd = new NormalDistributedRandom(random, 0, 1);
     49
    4850      for (int i = 0; i < velocity.Length; i++) {
    49         var g_id = 1.193 * ((personalBest[i] + neighborBest[i] - 2 * position[i]) / 3.0);
     51        var g_id = (personalBestAttraction * personalBest[i]
     52          + neighborBestAttraction * neighborBest[i]
     53          - position[i] * (neighborBestAttraction + personalBestAttraction)) / 3.0;
     54        // center of the hyper-sphere
    5055        gravity[i] = g_id + position[i];
    51         direct[i] = (random.NextDouble() - 0.5) * 2;
     56        // a random direction vector uniform over the surface of hyper-sphere, see http://mathworld.wolfram.com/HyperspherePointPicking.html
     57        direction[i] = nd.NextDouble();
    5258        radius += g_id * g_id;
    5359      }
    5460
     61      // randomly choose a radius within the hyper-sphere
    5562      radius = random.NextDouble() * Math.Sqrt(radius);
    5663
    57       var unitscale = Math.Sqrt(direct.DotProduct(direct));
     64      // unitscale is used to rescale the random direction vector to unit length, resp. length of the radius
     65      var unitscale = Math.Sqrt(direction.DotProduct(direction));
    5866      if (unitscale > 0) {
    5967        for (var i = 0; i < velocity.Length; i++) {
    60           velocity[i] = velocity[i] * inertia + gravity[i] + direct[i] * radius / unitscale - position[i];
     68          var sampledPos = gravity[i] + direction[i] * radius / unitscale;
     69          velocity[i] = velocity[i] * inertia + sampledPos - position[i];
    6170        }
    6271      }
     
    101110      var neighborBest = NeighborBestParameter.ActualValue;
    102111      var neighborBestAttraction = NeighborBestAttractionParameter.ActualValue.Value;
    103      
    104       UpdateVelocity(random, velocity, maxVelocity, position, inertia, personalBest, personalBestAttraction, neighborBest, neighborBestAttraction);
     112
     113      UpdateVelocity(random, velocity, position, personalBest, neighborBest, inertia, personalBestAttraction, neighborBestAttraction, maxVelocity);
    105114      UpdatePosition(bounds, velocity, position);
    106115
Note: See TracChangeset for help on using the changeset viewer.