Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/10/17 17:26:43 (7 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/SPSOSwarmUpdater.cs

    r15102 r15181  
    3434
    3535namespace HeuristicLab.Encodings.RealVectorEncoding {
    36   [Item("Swarm Updater (SPSO)", "Updates personal best point and quality as well as global best point and quality.")]
     36  [Item("Swarm Updater (SPSO)", "Updates personal best point and quality as well as neighbor best point and quality.")]
    3737  [StorableClass]
    3838  public sealed class SPSOSwarmUpdater : SingleSuccessorOperator, IRealVectorSwarmUpdater, ISingleObjectiveOperator {
     
    126126      Parameters.Add(new ScopeTreeLookupParameter<IntArray>("Neighbors", "The list of neighbors for each particle."));
    127127      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
    128       Parameters.Add(new ValueLookupParameter<DoubleValue>("MaxVelocity", "Speed limit for each particle.", new DoubleValue(1000000)));
     128      Parameters.Add(new ValueLookupParameter<DoubleValue>("MaxVelocity", "The maximum velocity for each particle and initial velocity if scaling is used.", new DoubleValue(double.MaxValue)));
    129129      Parameters.Add(new LookupParameter<DoubleValue>("CurrentMaxVelocity", "Current value of the speed limit."));
    130130      Parameters.Add(new LookupParameter<ResultCollection>("Results", "Results"));
     
    132132      #region Max Velocity Updating
    133133      Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("MaxVelocityScalingOperator", "Modifies the value"));
    134       Parameters.Add(new ValueLookupParameter<DoubleValue>("FinalMaxVelocity", "The value of maximum velocity if PSO has reached maximum iterations.", new DoubleValue(1E-10)));
     134      Parameters.Add(new ValueLookupParameter<DoubleValue>("FinalMaxVelocity", "The value of maximum velocity if scaling is used and PSO has reached maximum iterations.", new DoubleValue(1E-10)));
    135135      Parameters.Add(new LookupParameter<IntValue>("MaxVelocityIndex", "The current index.", "Iterations"));
    136136      Parameters.Add(new ValueLookupParameter<IntValue>("MaxVelocityStartIndex", "The start index at which to start modifying 'Value'.", new IntValue(0)));
     
    195195        var neighborBest = new ItemArray<RealVector>(neighbors.Length);
    196196        var neighborBestQuality = new ItemArray<DoubleValue>(neighbors.Length);
     197        double overallBest = double.NaN;
     198        RealVector overallBestVector = null;
    197199        for (int n = 0; n < neighbors.Length; n++) {
    198           var pairs = particles.Where(x => x.Item1 == n || neighbors[n].Contains(x.Item1));
    199           var bestNeighbor = (maximization ? pairs.MaxItems(p => p.Item3)
    200                                            : pairs.MinItems(p => p.Item3)).First();
     200          var neighborhood = particles.Where(x => neighbors[n].Contains(x.Item1));
     201          var bestNeighbor = (maximization ? neighborhood.MaxItems(p => p.Item3)
     202                                           : neighborhood.MinItems(p => p.Item3)).First();
    201203          neighborBest[n] = bestNeighbor.Item2;
    202204          neighborBestQuality[n] = new DoubleValue(bestNeighbor.Item3);
     205          if (double.IsNaN(overallBest) || maximization && bestNeighbor.Item3 > overallBest
     206            || !maximization && bestNeighbor.Item3 < overallBest) {
     207            overallBest = bestNeighbor.Item3;
     208            overallBestVector = bestNeighbor.Item2;
     209          }
    203210        }
    204211        NeighborBestParameter.ActualValue = neighborBest;
    205212        NeighborBestQualityParameter.ActualValue = neighborBestQuality;
     213        SwarmBestQualityParameter.ActualValue = new DoubleValue(overallBest);
     214        BestRealVectorParameter.ActualValue = overallBestVector;
    206215      } else {
    207216        // Neighbor best = Global best
    208217        var best = maximization ? particles.MaxItems(x => x.Item3).First() : particles.MinItems(x => x.Item3).First();
    209         NeighborBestParameter.ActualValue = new ItemArray<RealVector>(particles.Select(x => best.Item2));
    210         NeighborBestQualityParameter.ActualValue = new ItemArray<DoubleValue>(particles.Select(x => new DoubleValue(best.Item3)));
     218        NeighborBestParameter.ActualValue = new ItemArray<RealVector>(Enumerable.Repeat(best.Item2, particles.Count));
     219        NeighborBestQualityParameter.ActualValue = new ItemArray<DoubleValue>(Enumerable.Repeat(new DoubleValue(best.Item3), particles.Count));
     220        SwarmBestQualityParameter.ActualValue = new DoubleValue(best.Item3);
     221        BestRealVectorParameter.ActualValue = best.Item2;
    211222      }
    212223    }
     
    224235          !maximization && p.Item3 < personalBestQuality[p.Item1].Value) {
    225236          personalBestQuality[p.Item1].Value = p.Item3;
    226           personalBest[p.Item1] = (RealVector)p.Item2.Clone();
     237          personalBest[p.Item1] = new RealVector(p.Item2);
    227238        }
    228239      }
Note: See TracChangeset for help on using the changeset viewer.