Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/29/17 15:26:16 (7 years ago)
Author:
abeham
Message:

#2797:

  • Updated PSO to make it more compatible with SPSO 2011
  • Removed truncation of velocity vector and instead rescaled it given the maximum velocity
  • Added non-zero initial velocity according to SPSO 2011
  • Removed complicated bouncing code due to box constraints and instead implemented as described in SPSO 2011
  • Calculating neighbor best has been changed to use personal best
  • Avoiding local and global particle update and instead relying on neighborbest
  • More randomization during velocity update by using a separate random numbers per dimension
  • Reusing problem specific solution creator in RealVectorParticleCreator instead of always using UniformRandomRealVectorCreator
Location:
trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3
Files:
5 edited

Legend:

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

    r14185 r15091  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
    2425using HeuristicLab.Analysis;
     
    179180      Parameters.Add(new ValueParameter<IntValue>("MaxIterations", "Maximal number of iterations.", new IntValue(1000)));
    180181      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer()));
    181       Parameters.Add(new ValueParameter<DoubleValue>("Inertia", "Inertia weight on a particle's movement (omega).", new DoubleValue(1)));
    182       Parameters.Add(new ValueParameter<DoubleValue>("PersonalBestAttraction", "Weight for particle's pull towards its personal best soution (phi_p).", new DoubleValue(-0.01)));
    183       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(3.7)));
     182      Parameters.Add(new ValueParameter<DoubleValue>("Inertia", "Inertia weight on a particle's movement (omega).", new DoubleValue(0.9)));
     183      Parameters.Add(new ValueParameter<DoubleValue>("PersonalBestAttraction", "Weight for particle's pull towards its personal best soution (phi_p).", new DoubleValue(0.05)));
     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(0.5)));
    184185      Parameters.Add(new ConstrainedValueParameter<IParticleCreator>("ParticleCreator", "Operator that creates a new particle."));
    185186      Parameters.Add(new ConstrainedValueParameter<IParticleUpdater>("ParticleUpdater", "Operator that updates a particle."));
     
    262263      UpdateAnalyzers();
    263264      ParameterizeAnalyzers();
     265      UpdateParticleUpdaterParameter();
    264266      UpdateTopologyParameters();
    265267      InitializeParticleCreator();
     
    280282
    281283    private void InitializeParticleCreator() {
     284      ParticleCreatorParameter.ValidValues.Clear();
    282285      if (Problem != null) {
    283286        IParticleCreator oldParticleCreator = ParticleCreator;
    284287        IParticleCreator defaultParticleCreator = Problem.Operators.OfType<IParticleCreator>().FirstOrDefault();
    285         ParticleCreatorParameter.ValidValues.Clear();
    286         foreach (IParticleCreator Creator in Problem.Operators.OfType<IParticleCreator>().OrderBy(x => x.Name)) {
    287           ParticleCreatorParameter.ValidValues.Add(Creator);
     288        foreach (var creator in Problem.Operators.OfType<IParticleCreator>().OrderBy(x => x.Name)) {
     289          ParticleCreatorParameter.ValidValues.Add(creator);
    288290        }
    289291        if (oldParticleCreator != null) {
    290           IParticleCreator creator = ParticleCreatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleCreator.GetType());
     292          var creator = ParticleCreatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleCreator.GetType());
    291293          if (creator != null) ParticleCreator = creator;
    292294          else oldParticleCreator = null;
     
    328330        updater.IndexParameter.ActualName = "Iterations";
    329331        updater.ValueParameter.ActualName = "CurrentInertia";
    330         updater.StartValueParameter.Value = new DoubleValue(1);
    331         updater.EndValueParameter.Value = new DoubleValue(1E-10);
     332        updater.StartValueParameter.ActualName = InertiaParameter.Name;
     333        updater.EndValueParameter.Value = new DoubleValue(0.70);
    332334      }
    333335    }
     
    346348
    347349    private void UpdateTopologyInitializer() {
    348       ITopologyInitializer oldTopologyInitializer = TopologyInitializer;
     350      var oldTopologyInitializer = TopologyInitializer;
    349351      TopologyInitializerParameter.ValidValues.Clear();
    350352      foreach (ITopologyInitializer topologyInitializer in ApplicationManager.Manager.GetInstances<ITopologyInitializer>().OrderBy(x => x.Name)) {
    351353        TopologyInitializerParameter.ValidValues.Add(topologyInitializer);
    352354      }
     355
    353356      if (oldTopologyInitializer != null && TopologyInitializerParameter.ValidValues.Any(x => x.GetType() == oldTopologyInitializer.GetType()))
    354357        TopologyInitializer = TopologyInitializerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTopologyInitializer.GetType());
     
    357360
    358361    private void ParameterizeTopologyUpdaters() {
    359       foreach (var updater in TopologyUpdaterParameter.ValidValues) {
    360         var multiPsoUpdater = updater as MultiPSOTopologyUpdater;
    361         if (multiPsoUpdater != null) {
    362           multiPsoUpdater.CurrentIterationParameter.ActualName = "Iterations";
    363         }
    364       }
    365     }
    366 
    367     private void UpdateTopologyParameters() {
    368       ITopologyUpdater oldTopologyUpdater = TopologyUpdater;
    369       IParticleUpdater oldParticleUpdater = ParticleUpdater;
    370       ClearTopologyParameters();
    371       if (Problem != null) {
    372         IParticleUpdater defaultParticleUpdater = null;
    373         if (TopologyInitializer != null) {
    374           foreach (ITopologyUpdater topologyUpdater in ApplicationManager.Manager.GetInstances<ITopologyUpdater>())
    375             TopologyUpdaterParameter.ValidValues.Add(topologyUpdater);
    376           defaultParticleUpdater = Problem.Operators.OfType<ILocalParticleUpdater>().FirstOrDefault();
    377           foreach (IParticleUpdater particleUpdater in Problem.Operators.OfType<ILocalParticleUpdater>().OrderBy(x => x.Name))
    378             ParticleUpdaterParameter.ValidValues.Add(particleUpdater);
    379         } else {
    380           defaultParticleUpdater = Problem.Operators.OfType<IGlobalParticleUpdater>().FirstOrDefault();
    381           foreach (IParticleUpdater particleUpdater in Problem.Operators.OfType<IGlobalParticleUpdater>().OrderBy(x => x.Name))
    382             ParticleUpdaterParameter.ValidValues.Add(particleUpdater);
    383         }
    384         if (oldTopologyUpdater != null) {
    385           ITopologyUpdater newTopologyUpdater = TopologyUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType());
    386           if (newTopologyUpdater != null) TopologyUpdater = newTopologyUpdater;
    387         }
     362      foreach (var updater in TopologyUpdaterParameter.ValidValues.OfType<MultiPSOTopologyUpdater>()) {
     363        updater.CurrentIterationParameter.ActualName = "Iterations";
     364      }
     365    }
     366
     367    private void UpdateParticleUpdaterParameter() {
     368      var oldParticleUpdater = ParticleUpdater;
     369      ParticleUpdaterParameter.ValidValues.Clear();
     370      if (Problem != null) {
     371        var defaultParticleUpdater = Problem.Operators.OfType<IParticleUpdater>().FirstOrDefault();
     372
     373        foreach (var particleUpdater in Problem.Operators.OfType<IParticleUpdater>().OrderBy(x => x.Name))
     374          ParticleUpdaterParameter.ValidValues.Add(particleUpdater);
     375
    388376        if (oldParticleUpdater != null) {
    389           IParticleUpdater newParticleUpdater = ParticleUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType());
     377          var newParticleUpdater = ParticleUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldParticleUpdater.GetType());
    390378          if (newParticleUpdater != null) ParticleUpdater = newParticleUpdater;
    391379          else oldParticleUpdater = null;
     
    393381        if (oldParticleUpdater == null && defaultParticleUpdater != null)
    394382          ParticleUpdater = defaultParticleUpdater;
    395 
    396         ParameterizeTopologyUpdaters();
    397       }
    398     }
    399 
    400     private void ClearTopologyParameters() {
     383      }
     384    }
     385
     386    private void UpdateTopologyParameters() {
     387      ITopologyUpdater oldTopologyUpdater = TopologyUpdater;
    401388      TopologyUpdaterParameter.ValidValues.Clear();
    402       ParticleUpdaterParameter.ValidValues.Clear();
     389      if (Problem != null) {
     390        if (TopologyInitializerParameter.Value != null) {
     391          foreach (ITopologyUpdater topologyUpdater in ApplicationManager.Manager.GetInstances<ITopologyUpdater>())
     392            TopologyUpdaterParameter.ValidValues.Add(topologyUpdater);
     393
     394          if (oldTopologyUpdater != null) {
     395            ITopologyUpdater newTopologyUpdater = TopologyUpdaterParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldTopologyUpdater.GetType());
     396            if (newTopologyUpdater != null) TopologyUpdater = newTopologyUpdater;
     397          }
     398          ParameterizeTopologyUpdaters();
     399        }
     400      }
    403401    }
    404402
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/RandomTopologyInitializer.cs

    r14185 r15091  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
     27using HeuristicLab.Optimization;
    2728using HeuristicLab.Parameters;
    2829using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3132  [Item("Random Topology Initializer", "Randomly connectes every particle with k other particles.")]
    3233  [StorableClass]
    33   public sealed class RandomTopologyInitializer : TopologyInitializer {
     34  public sealed class RandomTopologyInitializer : TopologyInitializer, IStochasticOperator {
    3435    #region Parameters
    3536    public ILookupParameter<IRandom> RandomParameter {
     
    4041    }
    4142    #endregion
    42 
    43     #region Parameter Values
    44     private IRandom Random {
    45       get { return RandomParameter.ActualValue; }
    46     }
    47     private int NrOfConnections {
    48       get { return NrOfConnectionsParameter.ActualValue.Value; }
    49     }
    50     #endregion
    51 
     43   
    5244    #region Construction & Cloning
    5345    [StorableConstructor]
     
    6557
    6658    public override IOperation Apply() {
    67       ItemArray<IntArray> neighbors = new ItemArray<IntArray>(SwarmSize);
    68       for (int i = 0; i < SwarmSize; i++) {
    69         var numbers = Enumerable.Range(0, SwarmSize).ToList();
     59      var random = RandomParameter.ActualValue;
     60      var swarmSize = SwarmSizeParameter.ActualValue.Value;
     61      var nrOfConnections = NrOfConnectionsParameter.ActualValue.Value;
     62
     63      ItemArray<IntArray> neighbors = new ItemArray<IntArray>(swarmSize);
     64      for (int i = 0; i < swarmSize; i++) {
     65        var numbers = Enumerable.Range(0, swarmSize).ToList();
    7066        numbers.RemoveAt(i);
    71         var selectedNumbers = new List<int>(NrOfConnections);
    72         for (int j = 0; j < NrOfConnections && numbers.Count > 0; j++) {
    73           int index = Random.Next(numbers.Count);
     67        var selectedNumbers = new List<int>(nrOfConnections);
     68        for (int j = 0; j < nrOfConnections && numbers.Count > 0; j++) {
     69          int index = random.Next(numbers.Count);
    7470          selectedNumbers.Add(numbers[index]);
    7571          numbers.RemoveAt(index);
     
    7773        neighbors[i] = new IntArray(selectedNumbers.ToArray());
    7874      }
    79       Neighbors = neighbors;
     75      NeighborsParameter.ActualValue = neighbors;
    8076      return base.Apply();
    8177    }
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/RingTopologyInitializer.cs

    r14185 r15091  
    4343
    4444    public override IOperation Apply() {
    45       ItemArray<IntArray> neighbors = new ItemArray<IntArray>(SwarmSize);
    46       for (int i = 0; i < SwarmSize; i++) {
    47         neighbors[i] = new IntArray(new[] { (SwarmSize + i - 1) % SwarmSize, (i + 1) % SwarmSize });
     45      var swarmSize = SwarmSizeParameter.ActualValue.Value;
     46
     47      ItemArray<IntArray> neighbors = new ItemArray<IntArray>(swarmSize);
     48      for (int i = 0; i < swarmSize; i++) {
     49        neighbors[i] = new IntArray(new[] { (swarmSize + i - 1) % swarmSize, (i + 1) % swarmSize });
    4850      }
    49       Neighbors = neighbors;
     51      NeighborsParameter.ActualValue = neighbors;
    5052      return base.Apply();
    5153    }
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/TopologyInitializer.cs

    r14185 r15091  
    4040      get { return (IScopeTreeLookupParameter<IntArray>)Parameters["Neighbors"]; }
    4141    }
    42 
    4342    public ILookupParameter<IntValue> SwarmSizeParameter {
    4443      get { return (ILookupParameter<IntValue>)Parameters["SwarmSize"]; }
    45     }
    46 
    47     #endregion
    48 
    49     #region Parameter Values
    50     protected ItemArray<IntArray> Neighbors {
    51       get { return NeighborsParameter.ActualValue; }
    52       set { NeighborsParameter.ActualValue = value; }
    53     }
    54     protected int SwarmSize {
    55       get { return SwarmSizeParameter.ActualValue.Value; }
    5644    }
    5745    #endregion
  • trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/VonNeumannTopologyInitializer.cs

    r14185 r15091  
    4444
    4545    public override IOperation Apply() {
    46       ItemArray<IntArray> neighbors = new ItemArray<IntArray>(SwarmSize);
    47       for (int i = 0; i < SwarmSize; i++) {
     46      var swarmSize = SwarmSizeParameter.ActualValue.Value;
     47
     48      ItemArray<IntArray> neighbors = new ItemArray<IntArray>(swarmSize);
     49      for (int i = 0; i < swarmSize; i++) {
    4850        neighbors[i] = new IntArray(new[] {
    49           (SwarmSize + i-2) % SwarmSize,
    50           (SwarmSize + i-1) % SwarmSize,
    51           (i+1) % SwarmSize,
    52           (i+2) % SwarmSize
     51          (swarmSize + i-2) % swarmSize,
     52          (swarmSize + i-1) % swarmSize,
     53          (i+1) % swarmSize,
     54          (i+2) % swarmSize
    5355        });
    5456      }
    55       Neighbors = neighbors;
     57      NeighborsParameter.ActualValue = neighbors;
    5658      return base.Apply();
    5759    }
Note: See TracChangeset for help on using the changeset viewer.