Ignore:
Timestamp:
07/10/17 17:26:43 (3 years ago)
Author:
abeham
Message:

#2797:

  • Added IStochasticOperator interface to MultiPSOTopologyUpdater
  • Changed parameter defaults to those described in the paper
  • Added analyzer placeholder for the last iteration (has not been previously analyzed)
  • Changed random topology initializer to include itself (to be able to use it with SPSOSwarmUpdater -> this should not change the old RealVectorSwarmUpdater)
  • Changed ring topology initializer to include itself (same as above)
  • Changed von neumann topology initializer to include itself (same as above)
  • Added SPSO compatible random topology initializer (as described in the paper by Clerc)
  • Changed sampling of the random directional vector to be uniformly random on the surface of a hypersphere to avoid a slight bias in diagonal direction
  • Updating SwarmBestQuality and BestRealVector parameters in SPSOSwarmUpdater (an oversight)
  • Added a faster method to create a copy of a RealVector (based on Array.Copy)
  • Updated the sample
  • Updated the sample's test results (due to changed sampling in SPSO2011ParticleUpdater)
File:
1 edited

Legend:

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

    r15102 r15181  
    2525using HeuristicLab.Data;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using HeuristicLab.Random;
    2728
    2829namespace HeuristicLab.Encodings.RealVectorEncoding {
     
    4243    public static void UpdateVelocity(IRandom random, RealVector velocity, double maxVelocity, RealVector position, double inertia, RealVector personalBest, double personalBestAttraction, RealVector neighborBest, double neighborBestAttraction, double c = 1.193) {
    4344      var gravity = new double[velocity.Length];
    44       var direct = new RealVector(velocity.Length);
     45      var direction = new RealVector(velocity.Length);
    4546      var radius = 0.0;
     47
     48      var nd = new NormalDistributedRandom(random, 0, 1);
    4649
    4750      for (int i = 0; i < velocity.Length; i++) {
    4851        var g_id = c * ((personalBest[i] + neighborBest[i] - 2 * position[i]) / 3.0);
     52        // center of the hyper-sphere
    4953        gravity[i] = g_id + position[i];
    50         direct[i] = (random.NextDouble() - 0.5) * 2;
     54        // a random direction vector uniform over the surface of hyper-sphere, see http://mathworld.wolfram.com/HyperspherePointPicking.html
     55        direction[i] = nd.NextDouble();
    5156        radius += g_id * g_id;
    5257      }
    5358
     59      // randomly choose a radius within the hyper-sphere
    5460      radius = random.NextDouble() * Math.Sqrt(radius);
    5561
    56       var unitscale = Math.Sqrt(direct.DotProduct(direct));
     62      // unitscale is used to rescale the random direction vector to unit length, resp. length of the radius
     63      var unitscale = Math.Sqrt(direction.DotProduct(direction));
    5764      if (unitscale > 0) {
    5865        for (var i = 0; i < velocity.Length; i++) {
    59           velocity[i] = velocity[i] * inertia + gravity[i] + direct[i] * radius / unitscale - position[i];
     66          var sampledPos = gravity[i] + direction[i] * radius / unitscale;
     67          velocity[i] = velocity[i] * inertia + sampledPos - position[i];
    6068        }
    6169      }
Note: See TracChangeset for help on using the changeset viewer.