Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15214 for trunk


Ignore:
Timestamp:
07/12/17 16:49:16 (7 years ago)
Author:
abeham
Message:

#2797:

  • Fixed adaptive random topology updater
  • Adapted default values of the best attraction parameters
  • Changed code of the new topology initializer
  • Fixed the parameters of the SPSO particle updaters (c parameter is actually (personal|neighbor)bestattraction), reordered the method signature and provided defaults
  • Removed the max beyond parameter again
  • Updated the sample and updated the unit test
    • In the sample no inertia updating is used, but the topology initializers / updaters of SPSO are used
Location:
trunk/sources
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/AdaptiveRandomTopologyUpdater.cs

    r15181 r15214  
    8686      var successor = new OperationCollection(new[] { base.Apply() });
    8787      var max = MaximizationParameter.ActualValue.Value;
    88       if (max && swarmBest.Value >= previousBest.Value
    89         || !max && swarmBest.Value <= previousBest.Value)
     88      if (max && swarmBest.Value <= previousBest.Value
     89        || !max && swarmBest.Value >= previousBest.Value)
    9090        successor.Insert(0, ExecutionContext.CreateOperation(TopologyInitializerParameter.ActualValue));
    9191
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimization.cs

    r15181 r15214  
    181181      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
    182182      Parameters.Add(new ValueParameter<DoubleValue>("Inertia", "Inertia weight on a particle's movement (omega).", new DoubleValue(0.721)));
    183       Parameters.Add(new ValueParameter<DoubleValue>("PersonalBestAttraction", "Weight for particle's pull towards its personal best soution (phi_p).", new DoubleValue(1)));
    184       Parameters.Add(new ValueParameter<DoubleValue>("NeighborBestAttraction", "Weight for pull towards the neighborhood best solution or global best solution in case of a totally connected topology (phi_g).", new DoubleValue(1)));
     183      Parameters.Add(new ValueParameter<DoubleValue>("PersonalBestAttraction", "Weight for particle's pull towards its personal best soution (phi_p).", new DoubleValue(1.193)));
     184      Parameters.Add(new ValueParameter<DoubleValue>("NeighborBestAttraction", "Weight for pull towards the neighborhood best solution or global best solution in case of a totally connected topology (phi_g).", new DoubleValue(1.193)));
    185185      Parameters.Add(new ConstrainedValueParameter<IParticleCreator>("ParticleCreator", "Operator that creates a new particle."));
    186186      Parameters.Add(new ConstrainedValueParameter<IParticleUpdater>("ParticleUpdater", "Operator that updates a particle."));
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/RandomTopologyInitializer.cs

    r15181 r15214  
    3030
    3131namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
    32   [Item("Random Topology Initializer", "Each particle is informed by exactly k+1 distinct other particles (including itself).")]
     32  [Item("Random Distinct Topology Initializer", "Each particle is informed by exactly k+1 distinct other particles (including itself).")]
    3333  [StorableClass]
    3434  public sealed class RandomTopologyInitializer : TopologyInitializer, IStochasticOperator {
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/SPSORandomTopologyInitializer.cs

    r15181 r15214  
    6262
    6363      // SPSO: Each particle informs at most K+1 particles (at least itself and K others)
    64       var particlesInform = Enumerable.Repeat(k + 1, swarmSize)
    65         .Select((v, i) => new HashSet<int>(Enumerable.Range(0, v).Select(x => x == 0 ? i : random.Next(swarmSize)))).ToList();
     64      //       it is by design that we draw from the particles with repetition
     65      var particlesInform = new List<HashSet<int>>(swarmSize);
     66      for (var i = 0; i < swarmSize; i++) {
     67        var informs = new HashSet<int>() { i };
     68        for (var j = 0; j < k; j++) {
     69          informs.Add(random.Next(swarmSize));
     70        }
     71        particlesInform.Add(informs);
     72      }
    6673
    6774      var neighbors = new ItemArray<IntArray>(swarmSize);
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/SPSO2007ParticleUpdater.cs

    r15102 r15214  
    4242    #endregion
    4343   
    44     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) {
     44    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) {
    4545      for (int i = 0; i < velocity.Length; i++) {
    46         double r_p = random.NextDouble() * c;
    47         double r_g = random.NextDouble() * c;
     46        double r_p = random.NextDouble();
     47        double r_g = random.NextDouble();
    4848        velocity[i] =
    4949          velocity[i] * inertia +
     
    9191      var neighborBest = NeighborBestParameter.ActualValue;
    9292      var neighborBestAttraction = NeighborBestAttractionParameter.ActualValue.Value;
    93       var maxBeyond = MaxBeyondBestParameter.ActualValue.Value;
    9493
    95       UpdateVelocity(random, velocity, maxVelocity, position, inertia, personalBest, personalBestAttraction, neighborBest, neighborBestAttraction, maxBeyond);
     94      UpdateVelocity(random, velocity, position, personalBest, neighborBest, inertia, personalBestAttraction, neighborBestAttraction, maxVelocity);
    9695      UpdatePosition(bounds, velocity, position);
    9796
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/SPSO2011ParticleUpdater.cs

    r15181 r15214  
    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, double c = 1.193) {
     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];
    4545      var direction = new RealVector(velocity.Length);
     
    4949
    5050      for (int i = 0; i < velocity.Length; i++) {
    51         var g_id = c * ((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;
    5254        // center of the hyper-sphere
    5355        gravity[i] = g_id + position[i];
     
    108110      var neighborBest = NeighborBestParameter.ActualValue;
    109111      var neighborBestAttraction = NeighborBestAttractionParameter.ActualValue.Value;
    110       var maxBeyond = MaxBeyondBestParameter.ActualValue.Value;
    111112
    112       UpdateVelocity(random, velocity, maxVelocity, position, inertia, personalBest, personalBestAttraction, neighborBest, neighborBestAttraction, maxBeyond);
     113      UpdateVelocity(random, velocity, position, personalBest, neighborBest, inertia, personalBestAttraction, neighborBestAttraction, maxVelocity);
    113114      UpdatePosition(bounds, velocity, position);
    114115
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/SPSOParticleUpdater.cs

    r15102 r15214  
    7171      get { return (ILookupParameter<DoubleValue>)Parameters["NeighborBestAttraction"]; }
    7272    }
    73 
    74     public IValueLookupParameter<DoubleValue> MaxBeyondBestParameter {
    75       get { return (IValueLookupParameter<DoubleValue>)Parameters["MaxBeyondBest"]; }
    76     }
    7773    #endregion
    7874
     
    9389      Parameters.Add(new LookupParameter<DoubleValue>("PersonalBestAttraction", "The weight for the particle's personal best position."));
    9490      Parameters.Add(new LookupParameter<DoubleValue>("NeighborBestAttraction", "The weight for the global best position."));
    95       Parameters.Add(new ValueLookupParameter<DoubleValue>("MaxBeyondBest", "A factor of how much the velocity update may maximally aim beyond the personal and neighbor best.", new DoubleValue(1.193)));
    9691    }
    9792    #endregion
  • trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/PsoSchwefelSampleTest.cs

    r15181 r15214  
    2626using HeuristicLab.Data;
    2727using HeuristicLab.Encodings.RealVectorEncoding;
    28 using HeuristicLab.Optimization.Operators;
    2928using HeuristicLab.Persistence.Default.Xml;
    3029using HeuristicLab.Problems.TestFunctions;
     
    5251      SamplesUtils.RunAlgorithm(pso);
    5352      if (Environment.Is64BitProcess) {
    54         Assert.AreEqual(2.6641411068339949E-05, SamplesUtils.GetDoubleResult(pso, "BestQuality"));
    55         Assert.AreEqual(94.28800902426002, SamplesUtils.GetDoubleResult(pso, "CurrentAverageQuality"));
    56         Assert.AreEqual(992.93251114761892, SamplesUtils.GetDoubleResult(pso, "CurrentWorstQuality"));
     53        Assert.AreEqual(-1.4779288903810084E-12, SamplesUtils.GetDoubleResult(pso, "BestQuality"));
     54        Assert.AreEqual(189.28837949705971, SamplesUtils.GetDoubleResult(pso, "CurrentAverageQuality"));
     55        Assert.AreEqual(1195.4166822158872, SamplesUtils.GetDoubleResult(pso, "CurrentWorstQuality"));
    5756        Assert.AreEqual(200, SamplesUtils.GetIntResult(pso, "Iterations"));
    5857      } else {
    59         Assert.AreEqual(2.6641411068339949E-05, SamplesUtils.GetDoubleResult(pso, "BestQuality"));
    60         Assert.AreEqual(94.28800902426002, SamplesUtils.GetDoubleResult(pso, "CurrentAverageQuality"));
    61         Assert.AreEqual(992.93251114761892, SamplesUtils.GetDoubleResult(pso, "CurrentWorstQuality"));
     58        Assert.AreEqual(-1.4779288903810084E-12, SamplesUtils.GetDoubleResult(pso, "BestQuality"));
     59        Assert.AreEqual(189.28837949705971, SamplesUtils.GetDoubleResult(pso, "CurrentAverageQuality"));
     60        Assert.AreEqual(1195.4166822158873, SamplesUtils.GetDoubleResult(pso, "CurrentWorstQuality"));
    6261        Assert.AreEqual(200, SamplesUtils.GetIntResult(pso, "Iterations"));
    6362      }
     
    8079      pso.Description = "A particle swarm optimization algorithm which solves the 2-dimensional Schwefel test function (based on the description in Pedersen, M.E.H. (2010). PhD thesis. University of Southampton)";
    8180      pso.Problem = problem;
    82       pso.Inertia.Value = 1.1;
     81      pso.Inertia.Value = 0.721;
    8382      pso.MaxIterations.Value = 200;
    84       pso.NeighborBestAttraction.Value = 1;
    85       pso.PersonalBestAttraction.Value = 1;
     83      pso.NeighborBestAttraction.Value = 1.193;
     84      pso.PersonalBestAttraction.Value = 1.193;
    8685      pso.SwarmSize.Value = 40;
    87 
    88       var inertiaUpdater = pso.InertiaUpdaterParameter.ValidValues
    89         .OfType<ExponentialDiscreteDoubleValueModifier>()
    90         .Single();
    91       inertiaUpdater.EndValueParameter.Value = new DoubleValue(0.721);
    92       pso.InertiaUpdater = inertiaUpdater;
    93      
    94       pso.TopologyInitializer = null;
    95       pso.TopologyUpdater = null;
     86           
     87      pso.TopologyInitializer = pso.TopologyInitializerParameter.ValidValues.OfType<SPSORandomTopologyInitializer>().First();
     88      pso.TopologyUpdater = pso.TopologyUpdaterParameter.ValidValues.OfType<SPSOAdaptiveRandomTopologyUpdater>().First();
    9689      pso.Seed.Value = 0;
    9790      pso.SetSeedRandomly.Value = true;
Note: See TracChangeset for help on using the changeset viewer.