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 copied

Legend:

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

    r15167 r15181  
    3131
    3232namespace HeuristicLab.Algorithms.ParticleSwarmOptimization {
    33   [Item("Multi PSO Topology Updater", "Splits swarm into NrOfSwarms non-overlapping sub-swarms. Swarms are re-grouped every regroupingPeriod iteration. The operator is implemented as described in Liang, J.J. and Suganthan, P.N 2005. Dynamic multi-swarm particle swarm optimizer. IEEE Swarm Intelligence Symposium, pp. 124-129.")]
     33  [Item("SPSO Adaptive Random Topology Updater", "Each unsuccessful iteration the topology initializer is applied again.")]
    3434  [StorableClass]
    35   public sealed class MultiPSOTopologyUpdater : SingleSuccessorOperator, ITopologyUpdater {
     35  public sealed class SPSOAdaptiveRandomTopologyUpdater : SingleSuccessorOperator, ITopologyUpdater, ISingleObjectiveOperator {
    3636
    3737    public override bool CanChangeName {
     
    4040
    4141    #region Parameters
    42     public ILookupParameter<IRandom> RandomParameter {
    43       get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
     42    public ILookupParameter<BoolValue> MaximizationParameter {
     43      get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
    4444    }
    45     public IValueLookupParameter<IntValue> NrOfSwarmsParameter {
    46       get { return (IValueLookupParameter<IntValue>)Parameters["NrOfSwarms"]; }
     45    public ILookupParameter<DoubleValue> SwarmBestQualityParameter {
     46      get { return (ILookupParameter<DoubleValue>)Parameters["SwarmBestQuality"]; }
    4747    }
    48     public ILookupParameter<IntValue> SwarmSizeParameter {
    49       get { return (ILookupParameter<IntValue>)Parameters["SwarmSize"]; }
     48    public ILookupParameter<DoubleValue> PreviousBestQualityParameter {
     49      get { return (ILookupParameter<DoubleValue>)Parameters["PreviousBestQuality"]; }
     50    }
     51    public ILookupParameter<ITopologyInitializer> TopologyInitializerParameter {
     52      get { return (ILookupParameter<ITopologyInitializer>)Parameters["TopologyInitializer"]; }
    5053    }
    5154    public IScopeTreeLookupParameter<IntArray> NeighborsParameter {
    5255      get { return (IScopeTreeLookupParameter<IntArray>)Parameters["Neighbors"]; }
    53     }
    54     public ILookupParameter<IntValue> CurrentIterationParameter {
    55       get { return (ILookupParameter<IntValue>)Parameters["CurrentIteration"]; }
    56     }
    57     public IValueLookupParameter<IntValue> RegroupingPeriodParameter {
    58       get { return (IValueLookupParameter<IntValue>)Parameters["RegroupingPeriod"]; }
    59     }
    60     #endregion
    61 
    62     #region Parameter Values
    63     private IRandom Random {
    64       get { return RandomParameter.ActualValue; }
    65     }
    66     private int NrOfSwarms {
    67       get { return NrOfSwarmsParameter.ActualValue.Value; }
    68     }
    69     private int SwarmSize {
    70       get { return SwarmSizeParameter.ActualValue.Value; }
    71     }
    72     private ItemArray<IntArray> Neighbors {
    73       get { return NeighborsParameter.ActualValue; }
    74       set { NeighborsParameter.ActualValue = value; }
    75     }
    76     private int CurrentIteration {
    77       get { return CurrentIterationParameter.ActualValue.Value; }
    78     }
    79     private int RegroupingPeriod {
    80       get { return RegroupingPeriodParameter.ActualValue.Value; }
    8156    }
    8257    #endregion
     
    8459    #region Construction & Cloning
    8560    [StorableConstructor]
    86     private MultiPSOTopologyUpdater(bool deserializing) : base(deserializing) { }
    87     private MultiPSOTopologyUpdater(MultiPSOTopologyUpdater original, Cloner cloner) : base(original, cloner) { }
    88     public MultiPSOTopologyUpdater()
     61    private SPSOAdaptiveRandomTopologyUpdater(bool deserializing) : base(deserializing) { }
     62    private SPSOAdaptiveRandomTopologyUpdater(SPSOAdaptiveRandomTopologyUpdater original, Cloner cloner) : base(original, cloner) { }
     63    public SPSOAdaptiveRandomTopologyUpdater()
    8964      : base() {
    90       Parameters.Add(new LookupParameter<IRandom>("Random", "A random number generator."));
    91       Parameters.Add(new ValueLookupParameter<IntValue>("NrOfSwarms", "Nr of connected sub-swarms.", new IntValue(3)));
    92       Parameters.Add(new LookupParameter<IntValue>("SwarmSize", "Number of particles in the swarm."));
     65      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "Whether the problem is to be maximized or not."));
     66      Parameters.Add(new LookupParameter<DoubleValue>("SwarmBestQuality", "The swarm's best quality."));
     67      Parameters.Add(new LookupParameter<DoubleValue>("PreviousBestQuality", "The best quality of the previous iteration."));
     68      Parameters.Add(new LookupParameter<ITopologyInitializer>("TopologyInitializer", "The topology initializer is called again in case no improvement is made."));
    9369      Parameters.Add(new ScopeTreeLookupParameter<IntArray>("Neighbors", "The list of neighbors for each particle."));
    94       Parameters.Add(new LookupParameter<IntValue>("CurrentIteration", "The current iteration of the algorithm."));
    95       Parameters.Add(new ValueLookupParameter<IntValue>("RegroupingPeriod", "Update interval (=iterations) for regrouping of neighborhoods.", new IntValue(5)));
    9670    }
    9771    public override IDeepCloneable Clone(Cloner cloner) {
    98       return new MultiPSOTopologyUpdater(this, cloner);
     72      return new SPSOAdaptiveRandomTopologyUpdater(this, cloner);
    9973    }
    10074    #endregion
    10175
    10276    public override IOperation Apply() {
    103       if (CurrentIteration > 0 && CurrentIteration % RegroupingPeriod == 0) {
    104         ItemArray<IntArray> neighbors = new ItemArray<IntArray>(SwarmSize);
     77      var swarmBest = SwarmBestQualityParameter.ActualValue;
     78      if (swarmBest == null) return base.Apply();
    10579
    106         var particles = Enumerable.Range(0, SwarmSize).ToList();
    107         for (int i = SwarmSize-1; i>0; i--) {
    108           int j = Random.Next(i+1);
    109           int t = particles[j];
    110           particles[j] = particles[i];
    111           particles[i] = t;
    112         }
     80      var previousBest = PreviousBestQualityParameter.ActualValue;
     81      if (previousBest == null) {
     82        PreviousBestQualityParameter.ActualValue = new DoubleValue(swarmBest.Value);
     83        return base.Apply();
     84      };
    11385
    114         for (int partitionNr = 0; partitionNr<NrOfSwarms; partitionNr++) {
    115           int start = partitionNr*SwarmSize/NrOfSwarms;
    116           int end = (partitionNr+1)*SwarmSize/NrOfSwarms;
    117           for (int i = start; i<end; i++)
    118             neighbors[particles[i]] = GetSegment(particles, start, end, i);
    119         }
     86      var successor = new OperationCollection(new[] { base.Apply() });
     87      var max = MaximizationParameter.ActualValue.Value;
     88      if (max && swarmBest.Value >= previousBest.Value
     89        || !max && swarmBest.Value <= previousBest.Value)
     90        successor.Insert(0, ExecutionContext.CreateOperation(TopologyInitializerParameter.ActualValue));
    12091
    121         Neighbors = neighbors;
    122       }
    123       return base.Apply();
    124     }
    125 
    126     public static IntArray GetSegment(IEnumerable<int> list, int start, int end, int excludedIndex) {
    127       return new IntArray(list
    128         .Skip(start)
    129         .Take(end-start)
    130         .Where((p, j) => start+j != excludedIndex)
    131         .ToArray());
     92      previousBest.Value = swarmBest.Value;
     93      return successor;
    13294    }
    13395  }
Note: See TracChangeset for help on using the changeset viewer.