Changeset 15214 for trunk/sources
- Timestamp:
- 07/12/17 16:49:16 (7 years ago)
- Location:
- trunk/sources
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/AdaptiveRandomTopologyUpdater.cs
r15181 r15214 86 86 var successor = new OperationCollection(new[] { base.Apply() }); 87 87 var max = MaximizationParameter.ActualValue.Value; 88 if (max && swarmBest.Value >= previousBest.Value89 || !max && swarmBest.Value <= previousBest.Value)88 if (max && swarmBest.Value <= previousBest.Value 89 || !max && swarmBest.Value >= previousBest.Value) 90 90 successor.Insert(0, ExecutionContext.CreateOperation(TopologyInitializerParameter.ActualValue)); 91 91 -
trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimization.cs
r15181 r15214 181 181 Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer())); 182 182 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))); 185 185 Parameters.Add(new ConstrainedValueParameter<IParticleCreator>("ParticleCreator", "Operator that creates a new particle.")); 186 186 Parameters.Add(new ConstrainedValueParameter<IParticleUpdater>("ParticleUpdater", "Operator that updates a particle.")); -
trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/RandomTopologyInitializer.cs
r15181 r15214 30 30 31 31 namespace 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).")] 33 33 [StorableClass] 34 34 public sealed class RandomTopologyInitializer : TopologyInitializer, IStochasticOperator { -
trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/SPSORandomTopologyInitializer.cs
r15181 r15214 62 62 63 63 // 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 } 66 73 67 74 var neighbors = new ItemArray<IntArray>(swarmSize); -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/SPSO2007ParticleUpdater.cs
r15102 r15214 42 42 #endregion 43 43 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) { 45 45 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(); 48 48 velocity[i] = 49 49 velocity[i] * inertia + … … 91 91 var neighborBest = NeighborBestParameter.ActualValue; 92 92 var neighborBestAttraction = NeighborBestAttractionParameter.ActualValue.Value; 93 var maxBeyond = MaxBeyondBestParameter.ActualValue.Value;94 93 95 UpdateVelocity(random, velocity, maxVelocity, position, inertia, personalBest, personalBestAttraction, neighborBest, neighborBestAttraction, maxBeyond);94 UpdateVelocity(random, velocity, position, personalBest, neighborBest, inertia, personalBestAttraction, neighborBestAttraction, maxVelocity); 96 95 UpdatePosition(bounds, velocity, position); 97 96 -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/SPSO2011ParticleUpdater.cs
r15181 r15214 41 41 #endregion 42 42 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) { 44 44 var gravity = new double[velocity.Length]; 45 45 var direction = new RealVector(velocity.Length); … … 49 49 50 50 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; 52 54 // center of the hyper-sphere 53 55 gravity[i] = g_id + position[i]; … … 108 110 var neighborBest = NeighborBestParameter.ActualValue; 109 111 var neighborBestAttraction = NeighborBestAttractionParameter.ActualValue.Value; 110 var maxBeyond = MaxBeyondBestParameter.ActualValue.Value;111 112 112 UpdateVelocity(random, velocity, maxVelocity, position, inertia, personalBest, personalBestAttraction, neighborBest, neighborBestAttraction, maxBeyond);113 UpdateVelocity(random, velocity, position, personalBest, neighborBest, inertia, personalBestAttraction, neighborBestAttraction, maxVelocity); 113 114 UpdatePosition(bounds, velocity, position); 114 115 -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/SPSOParticleUpdater.cs
r15102 r15214 71 71 get { return (ILookupParameter<DoubleValue>)Parameters["NeighborBestAttraction"]; } 72 72 } 73 74 public IValueLookupParameter<DoubleValue> MaxBeyondBestParameter {75 get { return (IValueLookupParameter<DoubleValue>)Parameters["MaxBeyondBest"]; }76 }77 73 #endregion 78 74 … … 93 89 Parameters.Add(new LookupParameter<DoubleValue>("PersonalBestAttraction", "The weight for the particle's personal best position.")); 94 90 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)));96 91 } 97 92 #endregion -
trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/PsoSchwefelSampleTest.cs
r15181 r15214 26 26 using HeuristicLab.Data; 27 27 using HeuristicLab.Encodings.RealVectorEncoding; 28 using HeuristicLab.Optimization.Operators;29 28 using HeuristicLab.Persistence.Default.Xml; 30 29 using HeuristicLab.Problems.TestFunctions; … … 52 51 SamplesUtils.RunAlgorithm(pso); 53 52 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")); 57 56 Assert.AreEqual(200, SamplesUtils.GetIntResult(pso, "Iterations")); 58 57 } 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")); 62 61 Assert.AreEqual(200, SamplesUtils.GetIntResult(pso, "Iterations")); 63 62 } … … 80 79 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)"; 81 80 pso.Problem = problem; 82 pso.Inertia.Value = 1.1;81 pso.Inertia.Value = 0.721; 83 82 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; 86 85 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(); 96 89 pso.Seed.Value = 0; 97 90 pso.SetSeedRandomly.Value = true;
Note: See TracChangeset
for help on using the changeset viewer.