Changeset 15096
- Timestamp:
- 06/29/17 23:04:03 (7 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.ParticleSwarmOptimization/3.3/ParticleSwarmOptimization.cs
r15091 r15096 177 177 Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); 178 178 Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true))); 179 Parameters.Add(new ValueParameter<IntValue>("SwarmSize", "Size of the particle swarm.", new IntValue( 10)));179 Parameters.Add(new ValueParameter<IntValue>("SwarmSize", "Size of the particle swarm.", new IntValue(20))); 180 180 Parameters.Add(new ValueParameter<IntValue>("MaxIterations", "Maximal number of iterations.", new IntValue(1000))); 181 181 Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze each generation.", new MultiAnalyzer())); 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)));182 Parameters.Add(new ValueParameter<DoubleValue>("Inertia", "Inertia weight on a particle's movement (omega).", new DoubleValue(0.8))); 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))); 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.")); … … 189 189 Parameters.Add(new OptionalConstrainedValueParameter<IDiscreteDoubleValueModifier>("InertiaUpdater", "Updates the omega parameter.")); 190 190 Parameters.Add(new ConstrainedValueParameter<ISwarmUpdater>("SwarmUpdater", "Encoding-specific parameter which is provided by the problem. May provide additional encoding-specific parameters, such as velocity bounds for real valued problems")); 191 ParticleUpdaterParameter.Hidden = true;192 191 193 192 RandomCreator randomCreator = new RandomCreator(); -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/HeuristicLab.Encodings.RealVectorEncoding-3.3.csproj
r15091 r15096 116 116 <Compile Include="Creators\NormalDistributedRealVectorCreator.cs" /> 117 117 <Compile Include="Interfaces\IRealVectorMultiNeighborhoodShakingOperator.cs" /> 118 <Compile Include="ParticleOperators\SPSO2011ParticleUpdater.cs" /> 119 <Compile Include="ParticleOperators\SPSO2007ParticleUpdater.cs" /> 118 120 <Compile Include="ParticleOperators\RealVectorParticleCreator.cs" /> 119 121 <Compile Include="Crossovers\BlendAlphaBetaCrossover.cs" /> -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorNeighborhoodParticleUpdater.cs
r15091 r15096 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.PluginInfrastructure; 25 27 26 28 namespace HeuristicLab.Encodings.RealVectorEncoding { 27 29 [Item("Neighborhood Particle Updater", "Updates the particle's position using (among other things) the best neighbor's position. Point = Point + Velocity*Inertia + (PersonalBestPoint-Point)*Phi_P*r_p + (BestNeighborPoint-Point)*Phi_G*r_g.")] 28 30 [StorableClass] 29 public sealed class RealVectorNeighborhoodParticleUpdater : RealVectorParticleUpdater { 31 [NonDiscoverableType] 32 [Obsolete("Replaced by SPSO2007ParticleUpdater")] 33 internal sealed class RealVectorNeighborhoodParticleUpdater : RealVectorParticleUpdater { 30 34 31 35 #region Construction & Cloning … … 39 43 #endregion 40 44 45 private void UpdateVelocity() { 46 var velocity = VelocityParameter.ActualValue; 47 var position = RealVectorParameter.ActualValue; 48 var inertia = CurrentInertiaParameter.ActualValue.Value; 49 var personalBest = PersonalBestParameter.ActualValue; 50 var personalBestAttraction = PersonalBestAttractionParameter.ActualValue.Value; 51 var neighborBest = NeighborBestParameter.ActualValue; 52 var neighborBestAttraction = NeighborBestAttractionParameter.ActualValue.Value; 53 54 var random = RandomParameter.ActualValue; 55 56 for (int i = 0; i < velocity.Length; i++) { 57 double r_p = random.NextDouble(); 58 double r_g = random.NextDouble(); 59 velocity[i] = 60 velocity[i] * inertia + 61 (personalBest[i] - position[i]) * personalBestAttraction * r_p + 62 (neighborBest[i] - position[i]) * neighborBestAttraction * r_g; 63 } 64 65 var maxVelocity = CurrentMaxVelocityParameter.ActualValue.Value; 66 var speed = Math.Sqrt(velocity.DotProduct(velocity)); 67 if (speed > maxVelocity) { 68 for (var i = 0; i < velocity.Length; i++) { 69 velocity[i] *= maxVelocity / speed; 70 } 71 } 72 } 73 74 private void UpdatePosition() { 75 var velocity = VelocityParameter.ActualValue; 76 var position = RealVectorParameter.ActualValue; 77 78 for (int i = 0; i < velocity.Length; i++) { 79 position[i] += velocity[i]; 80 } 81 82 var bounds = BoundsParameter.ActualValue; 83 for (int i = 0; i < position.Length; i++) { 84 double min = bounds[i % bounds.Rows, 0]; 85 double max = bounds[i % bounds.Rows, 1]; 86 if (position[i] < min) { 87 position[i] = min; 88 velocity[i] = -0.5 * velocity[i]; // SPSO 2011 89 } 90 if (position[i] > max) { 91 position[i] = max; 92 velocity[i] = -0.5 * velocity[i]; // SPSO 2011 93 } 94 } 95 } 96 41 97 public override IOperation Apply() { 42 98 UpdateVelocity(); -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorParticleUpdater.cs
r15091 r15096 19 19 */ 20 20 #endregion 21 22 using System; 21 23 22 using HeuristicLab.Common; 24 23 using HeuristicLab.Core; 25 24 using HeuristicLab.Data; 26 25 using HeuristicLab.Operators; 26 using HeuristicLab.Optimization; 27 27 using HeuristicLab.Parameters; 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 60 60 get { return (ILookupParameter<DoubleValue>)Parameters["CurrentMaxVelocity"]; } 61 61 } 62 public ILookupParameter<DoubleValue> InertiaParameter {62 public ILookupParameter<DoubleValue> CurrentInertiaParameter { 63 63 get { return (ILookupParameter<DoubleValue>)Parameters["CurrentInertia"]; } 64 64 } 65 ILookupParameter<DoubleValue> IParticleUpdater.InertiaParameter { get { return CurrentInertiaParameter; } } 66 65 67 public ILookupParameter<DoubleValue> PersonalBestAttractionParameter { 66 68 get { return (ILookupParameter<DoubleValue>)Parameters["PersonalBestAttraction"]; } … … 89 91 } 90 92 #endregion 91 92 protected void UpdateVelocity() {93 var velocity = VelocityParameter.ActualValue;94 var position = RealVectorParameter.ActualValue;95 var inertia = InertiaParameter.ActualValue.Value;96 var personalBest = PersonalBestParameter.ActualValue;97 var personalBestAttraction = PersonalBestAttractionParameter.ActualValue.Value;98 var neighborBest = NeighborBestParameter.ActualValue;99 var neighborBestAttraction = NeighborBestAttractionParameter.ActualValue.Value;100 101 var random = RandomParameter.ActualValue;102 103 for (int i = 0; i < velocity.Length; i++) {104 double r_p = random.NextDouble();105 double r_g = random.NextDouble();106 velocity[i] =107 velocity[i] * inertia +108 (personalBest[i] - position[i]) * personalBestAttraction * r_p +109 (neighborBest[i] - position[i]) * neighborBestAttraction * r_g;110 }111 112 var maxVelocity = CurrentMaxVelocityParameter.ActualValue.Value;113 var speed = Math.Sqrt(velocity.DotProduct(velocity));114 if (speed > maxVelocity) {115 for (var i = 0; i < velocity.Length; i++) {116 velocity[i] *= maxVelocity / speed;117 }118 }119 }120 121 protected void UpdatePosition() {122 var velocity = VelocityParameter.ActualValue;123 var position = RealVectorParameter.ActualValue;124 125 for (int i = 0; i < velocity.Length; i++) {126 position[i] += velocity[i];127 }128 129 var bounds = BoundsParameter.ActualValue;130 for (int i = 0; i < position.Length; i++) {131 double min = bounds[i % bounds.Rows, 0];132 double max = bounds[i % bounds.Rows, 1];133 if (position[i] < min) {134 position[i] = min;135 velocity[i] = -0.5 * velocity[i]; // SPSO 2011136 }137 if (position[i] > max) {138 position[i] = max;139 velocity[i] = -0.5 * velocity[i]; // SPSO 2011140 }141 }142 }143 93 } 144 94 } -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorSwarmUpdater.cs
r15091 r15096 126 126 Parameters.Add(new ScopeTreeLookupParameter<IntArray>("Neighbors", "The list of neighbors for each particle.")); 127 127 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(1 )));128 Parameters.Add(new ValueLookupParameter<DoubleValue>("MaxVelocity", "Speed limit for each particle.", new DoubleValue(1000000))); 129 129 Parameters.Add(new LookupParameter<DoubleValue>("CurrentMaxVelocity", "Current value of the speed limit.")); 130 130 Parameters.Add(new LookupParameter<ResultCollection>("Results", "Results")); -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/ParticleOperators/RealVectorTotallyConnectedParticleUpdater.cs
r15091 r15096 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Optimization;26 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 26 using HeuristicLab.PluginInfrastructure; … … 31 30 [StorableClass] 32 31 [NonDiscoverableType] 33 [Obsolete(" Same as the RealVectorNeighborhoodParticleUpdate")]32 [Obsolete("Replaced by SPSO2007ParticleUpdater")] 34 33 internal sealed class RealVectorTotallyConnectedParticleUpdater : RealVectorParticleUpdater { 35 34 … … 44 43 #endregion 45 44 45 private void UpdateVelocity() { 46 var velocity = VelocityParameter.ActualValue; 47 var position = RealVectorParameter.ActualValue; 48 var inertia = CurrentInertiaParameter.ActualValue.Value; 49 var personalBest = PersonalBestParameter.ActualValue; 50 var personalBestAttraction = PersonalBestAttractionParameter.ActualValue.Value; 51 var neighborBest = NeighborBestParameter.ActualValue; 52 var neighborBestAttraction = NeighborBestAttractionParameter.ActualValue.Value; 53 54 var random = RandomParameter.ActualValue; 55 56 for (int i = 0; i < velocity.Length; i++) { 57 double r_p = random.NextDouble(); 58 double r_g = random.NextDouble(); 59 velocity[i] = 60 velocity[i] * inertia + 61 (personalBest[i] - position[i]) * personalBestAttraction * r_p + 62 (neighborBest[i] - position[i]) * neighborBestAttraction * r_g; 63 } 64 65 var maxVelocity = CurrentMaxVelocityParameter.ActualValue.Value; 66 var speed = Math.Sqrt(velocity.DotProduct(velocity)); 67 if (speed > maxVelocity) { 68 for (var i = 0; i < velocity.Length; i++) { 69 velocity[i] *= maxVelocity / speed; 70 } 71 } 72 } 73 74 private void UpdatePosition() { 75 var velocity = VelocityParameter.ActualValue; 76 var position = RealVectorParameter.ActualValue; 77 78 for (int i = 0; i < velocity.Length; i++) { 79 position[i] += velocity[i]; 80 } 81 82 var bounds = BoundsParameter.ActualValue; 83 for (int i = 0; i < position.Length; i++) { 84 double min = bounds[i % bounds.Rows, 0]; 85 double max = bounds[i % bounds.Rows, 1]; 86 if (position[i] < min) { 87 position[i] = min; 88 velocity[i] = -0.5 * velocity[i]; // SPSO 2011 89 } 90 if (position[i] > max) { 91 position[i] = max; 92 velocity[i] = -0.5 * velocity[i]; // SPSO 2011 93 } 94 } 95 } 96 46 97 public override IOperation Apply() { 47 98 UpdateVelocity(); -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVector.cs
r15091 r15096 78 78 } 79 79 80 public void Add(RealVector other) { 81 if (other.Length != Length) throw new ArgumentException("Vectors are of unequal length."); 82 for (var i = 0; i < Length; i++) 83 this[i] += other[i]; 84 } 85 86 public void Subtract(RealVector other) { 87 if (other.Length != Length) throw new ArgumentException("Vectors are of unequal length."); 88 for (var i = 0; i < Length; i++) 89 this[i] -= other[i]; 90 } 91 80 92 public double DotProduct(RealVector other) { 81 93 if (other.Length != Length) throw new ArgumentException("Vectors are of unequal length."); -
trunk/sources/HeuristicLab.Tests/HeuristicLab-3.3/Samples/PsoSchwefelSampleTest.cs
r15092 r15096 52 52 SamplesUtils.RunAlgorithm(pso); 53 53 if (Environment.Is64BitProcess) { 54 Assert.AreEqual( 118.43833503632464, SamplesUtils.GetDoubleResult(pso, "BestQuality"));55 Assert.AreEqual(1 18.43935663125784, SamplesUtils.GetDoubleResult(pso, "CurrentAverageQuality"));56 Assert.AreEqual( 118.44721627137812, SamplesUtils.GetDoubleResult(pso, "CurrentWorstQuality"));57 Assert.AreEqual( 1000, SamplesUtils.GetIntResult(pso, "Iterations"));54 Assert.AreEqual(2.8334909529803554E-08, SamplesUtils.GetDoubleResult(pso, "BestQuality")); 55 Assert.AreEqual(128.08680460446624, SamplesUtils.GetDoubleResult(pso, "CurrentAverageQuality")); 56 Assert.AreEqual(713.67728101375587, SamplesUtils.GetDoubleResult(pso, "CurrentWorstQuality")); 57 Assert.AreEqual(200, SamplesUtils.GetIntResult(pso, "Iterations")); 58 58 } else { 59 Assert.AreEqual( 118.4383350363247, SamplesUtils.GetDoubleResult(pso, "BestQuality"));60 Assert.AreEqual(1 18.43935663125787, SamplesUtils.GetDoubleResult(pso, "CurrentAverageQuality"));61 Assert.AreEqual( 118.44721627137824, SamplesUtils.GetDoubleResult(pso, "CurrentWorstQuality"));62 Assert.AreEqual( 1000, SamplesUtils.GetIntResult(pso, "Iterations"));59 Assert.AreEqual(2.8334909529803554E-08, SamplesUtils.GetDoubleResult(pso, "BestQuality")); 60 Assert.AreEqual(128.08680460446624, SamplesUtils.GetDoubleResult(pso, "CurrentAverageQuality")); 61 Assert.AreEqual(713.67728101375587, SamplesUtils.GetDoubleResult(pso, "CurrentWorstQuality")); 62 Assert.AreEqual(200, SamplesUtils.GetIntResult(pso, "Iterations")); 63 63 } 64 64 } … … 80 80 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 81 pso.Problem = problem; 82 pso.Inertia.Value = 1 0;83 pso.MaxIterations.Value = 1000;84 pso.NeighborBestAttraction.Value = 0.5;85 pso.PersonalBestAttraction.Value = -0.01;86 pso.SwarmSize.Value = 50;82 pso.Inertia.Value = 1.1; 83 pso.MaxIterations.Value = 200; 84 pso.NeighborBestAttraction.Value = 1; 85 pso.PersonalBestAttraction.Value = 1; 86 pso.SwarmSize.Value = 40; 87 87 88 88 var inertiaUpdater = pso.InertiaUpdaterParameter.ValidValues 89 89 .OfType<ExponentialDiscreteDoubleValueModifier>() 90 90 .Single(); 91 inertiaUpdater.StartValueParameter.Value = new DoubleValue(10); 92 inertiaUpdater.EndValueParameter.Value = new DoubleValue(0.8); 91 inertiaUpdater.EndValueParameter.Value = new DoubleValue(0.721); 93 92 pso.InertiaUpdater = inertiaUpdater; 94 95 pso.ParticleCreator = pso.ParticleCreatorParameter.ValidValues 96 .OfType<RealVectorParticleCreator>() 97 .Single(); 98 var swarmUpdater = pso.SwarmUpdaterParameter.ValidValues 99 .OfType<RealVectorSwarmUpdater>() 100 .Single(); 101 swarmUpdater.MaxVelocityParameter.Value = new DoubleValue(20.0); 102 swarmUpdater.FinalMaxVelocityParameter.Value = new DoubleValue(1.0); 103 swarmUpdater.MaxVelocityScalingOperatorParameter.Value = swarmUpdater.MaxVelocityScalingOperatorParameter.ValidValues 104 .OfType<ExponentialDiscreteDoubleValueModifier>() 105 .Single(); 106 93 107 94 pso.TopologyInitializer = null; 108 95 pso.TopologyUpdater = null; 109 pso.SwarmUpdater = swarmUpdater;110 96 pso.Seed.Value = 0; 111 97 pso.SetSeedRandomly.Value = true;
Note: See TracChangeset
for help on using the changeset viewer.