Changeset 2915 for trunk/sources
- Timestamp:
- 03/02/10 19:05:10 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.RealVector/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.RealVector/3.3/HeuristicLab.Encodings.RealVector-3.3.csproj
r2914 r2915 96 96 </Compile> 97 97 <Compile Include="HeuristicLabEncodingsRealVectorPlugin.cs" /> 98 <Compile Include="Manipulators\MichalewiczNonUniformAllPositionsManipulator.cs"> 99 <SubType>Code</SubType> 100 </Compile> 101 <Compile Include="Manipulators\MichalewiczNonUniformOnePositionManipulator.cs" /> 98 102 <Compile Include="Manipulators\UniformOnePositionManipulator.cs" /> 99 103 <None Include="HeuristicLab.snk" /> -
trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Manipulators/MichalewiczNonUniformAllPositionsManipulator.cs
r2900 r2915 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Text;25 23 using HeuristicLab.Core; 26 24 using HeuristicLab.Data; 25 using HeuristicLab.Parameters; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 27 28 28 namespace HeuristicLab.Encodings.RealVector { 29 29 /// <summary> 30 /// Michalewicz, Z. (1992). Genetic Algorithms + Data Structures = Evolution Programs<br/>31 /// Non-uniformly distributed change of all positions of a real vector.30 /// The solution is manipulated with diminishing strength over time. In addition the mutated values are not sampled over the entire domain, but additive.<br/> 31 /// Initially, the space will be searched uniformly and very locally at later stages. This increases the probability of generating the new numbers closer to the current value. 32 32 /// </summary> 33 public class MichalewiczNonUniformAllPositionsManipulator : RealVectorManipulatorBase { 34 /// <inheritdoc select="summary"/> 35 public override string Description { 36 get { return 37 @"Non-uniformly distributed change of all positions of a real vector (Michalewicz 1992) 38 Initially, the space will be searched uniformly and very locally at later stages. This increases the probability of generating the new number closer to its successor instead of a random number. 39 40 Michalewicz, Z. (1992). Genetic Algorithms + Data Structures = Evolution Programs. Springer Verlag."; 41 } 33 /// <remarks> 34 /// It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg. 35 /// </remarks> 36 [Item("MichalewiczNonUniformOnePositionManipulator", "It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.")] 37 [EmptyStorableClass] 38 public class MichalewiczNonUniformAllPositionsManipulator : RealVectorManipulator { 39 public ValueLookupParameter<DoubleData> MinimumParameter { 40 get { return (ValueLookupParameter<DoubleData>)Parameters["Minimum"]; } 41 } 42 public ValueLookupParameter<DoubleData> MaximumParameter { 43 get { return (ValueLookupParameter<DoubleData>)Parameters["Maximum"]; } 44 } 45 public LookupParameter<IntData> GenerationParameter { 46 get { return (LookupParameter<IntData>)Parameters["Generation"]; } 47 } 48 public LookupParameter<IntData> MaximumGenerationsParameter { 49 get { return (LookupParameter<IntData>)Parameters["MaximumGenerations"]; } 50 } 51 public ValueLookupParameter<DoubleData> GenerationDependencyParameter { 52 get { return (ValueLookupParameter<DoubleData>)Parameters["GenerationDependency"]; } 42 53 } 43 54 44 55 /// <summary> 45 56 /// Initializes a new instance of <see cref="MichalewiczNonUniformAllPositionsManipulator"/> with 46 /// five variable infos (<c>Minimum</c>, <c>Maximum</c>, <c>CurrentGeneration</c>,47 /// <c>MaximumGenerations</c> and <c>Generation sDependency</c>).57 /// five parameters (<c>Minimum</c>, <c>Maximum</c>, <c>CurrentGeneration</c>, 58 /// <c>MaximumGenerations</c> and <c>GenerationDependency</c>). 48 59 /// </summary> 49 60 public MichalewiczNonUniformAllPositionsManipulator() 50 61 : base() { 51 AddVariableInfo(new VariableInfo("Minimum", "Minimum of the sampling range for the vector element (included)", typeof(DoubleData), VariableKind.In)); 52 AddVariableInfo(new VariableInfo("Maximum", "Maximum of the sampling range for the vector element (excluded)", typeof(DoubleData), VariableKind.In)); 53 AddVariableInfo(new VariableInfo("CurrentGeneration", "Current Generation of the algorithm", typeof(IntData), VariableKind.In)); 54 AddVariableInfo(new VariableInfo("MaximumGenerations", "Maximum number of Generations", typeof(IntData), VariableKind.In)); 55 VariableInfo genDepInfo = new VariableInfo("GenerationsDependency", "Specifies the degree of dependency on the number of generations", typeof(IntData), VariableKind.In); 56 genDepInfo.Local = true; 57 AddVariableInfo(genDepInfo); 58 AddVariable(new Variable("GenerationsDependency", new IntData(5))); 62 Parameters.Add(new ValueLookupParameter<DoubleData>("Minimum", "Minimum of the sampling range for the vector element (included)")); 63 Parameters.Add(new ValueLookupParameter<DoubleData>("Maximum", "Maximum of the sampling range for the vector element (excluded)")); 64 Parameters.Add(new LookupParameter<IntData>("Generation", "Current generation of the algorithm")); 65 Parameters.Add(new LookupParameter<IntData>("MaximumGenerations", "Maximum number of generations")); 66 Parameters.Add(new ValueLookupParameter<DoubleData>("GenerationDependency", "Specifies the degree of dependency on the number of generations", new DoubleData(5))); 59 67 } 60 68 61 69 /// <summary> 62 /// Performs a non uniformly distributed all position manipulation on the given 63 /// real <paramref name="vector"/> , published by Z. Michalewicz, 1992.70 /// Performs a non uniformly distributed all position manipulation on the given 71 /// real <paramref name="vector"/>. The probability of stronger mutations reduces the more <see cref="currentGeneration"/> approaches <see cref="maximumGenerations"/>. 64 72 /// </summary> 65 /// <remarks>Calls <see cref="Apply"/>.</remarks> 66 /// <param name="scope">The current scope.</param> 67 /// <param name="random">The random number generator.</param> 68 /// <param name="vector">The real vector to manipulate.</param> 69 /// <returns>The manipulated real vector.</returns> 70 protected override double[] Manipulate(IScope scope, IRandom random, double[] vector) { 71 double min = GetVariableValue<DoubleData>("Minimum", scope, true).Data; 72 double max = GetVariableValue<DoubleData>("Maximum", scope, true).Data; 73 int currentGeneration = GetVariableValue<IntData>("CurrentGeneration", scope, true).Data; 74 int maximumGenerations = GetVariableValue<IntData>("MaximumGenerations", scope, true).Data; 75 int generationsDependency = GetVariableValue<IntData>("GenerationsDependency", scope, true).Data; 76 return Apply(random, vector, min, max, currentGeneration, maximumGenerations, generationsDependency); 77 } 78 79 /// <summary> 80 /// Performs a non uniformly distributed all position manipulation on the given 81 /// real <paramref name="vector"/>, published by Z. Michalewicz, 1992. 82 /// </summary> 73 /// <exception cref="ArgumentException">Thrown when <paramref name="currentGeneration"/> is greater than <paramref name="maximumGenerations"/>.</exception> 83 74 /// <param name="random">The random number generator.</param> 84 75 /// <param name="vector">The real vector to manipulate.</param> … … 89 80 /// <param name="generationsDependency">Specifies the degree of dependency on the number of generations.</param> 90 81 /// <returns>The manipulated real vector.</returns> 91 public static double[] Apply(IRandom random, double[] vector, double min, double max, int currentGeneration, int maximumGenerations, int generationsDependency) { 82 public static void Apply(IRandom random, DoubleArrayData vector, DoubleData min, DoubleData max, IntData currentGeneration, IntData maximumGenerations, DoubleData generationsDependency) { 83 if (currentGeneration.Value > maximumGenerations.Value) throw new ArgumentException("MichalewiczNonUniformAllPositionManipulator: CurrentGeneration must be smaller or equal than MaximumGeneration", "currentGeneration"); 92 84 int length = vector.Length; 93 double[] result = new double[length]; 85 86 double prob = Math.Pow(1 - currentGeneration.Value / maximumGenerations.Value, generationsDependency.Value); 94 87 95 88 for (int i = 0; i < length; i++) { 96 89 if (random.NextDouble() < 0.5) { 97 vector[i] = vector[i] + Delta(random, currentGeneration, max - vector[i], maximumGenerations, generationsDependency);90 vector[i] = vector[i] + (max.Value - vector[i]) * (1 - Math.Pow(random.NextDouble(), prob)); 98 91 } else { 99 vector[i] = vector[i] - Delta(random, currentGeneration, vector[i] - min, maximumGenerations, generationsDependency);92 vector[i] = vector[i] - (vector[i] - min.Value) * (1 - Math.Pow(random.NextDouble(), prob)); 100 93 } 101 94 } 102 return vector;103 95 } 104 96 105 // returns a value between 0 and y (both included) 106 private static double Delta(IRandom random, int currentGeneration, double y, int maximumGenerations, int generationsDependency) { 107 return y * (1 - Math.Pow(random.NextDouble(), Math.Pow(1 - currentGeneration / maximumGenerations, generationsDependency))); 97 /// <summary> 98 /// Checks if all parameters are available and forwards the call to <see cref="Apply(IRandom, DoubleArrayData, DoubleData, DoubleData, IntData, IntData, DoubleData)"/>. 99 /// </summary> 100 /// <param name="random">The random number generator.</param> 101 /// <param name="realVector">The real vector that should be manipulated.</param> 102 protected override void Manipulate(IRandom random, DoubleArrayData realVector) { 103 if (MinimumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + MinimumParameter.ActualName + " could not be found."); 104 if (MaximumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + MaximumParameter.ActualName + " could not be found."); 105 if (GenerationParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + GenerationParameter.ActualName + " could not be found."); 106 if (MaximumGenerationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + MaximumGenerationsParameter.ActualName + " could not be found."); 107 if (GenerationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + GenerationDependencyParameter.ActualName + " could not be found."); 108 Apply(random, realVector, MinimumParameter.ActualValue, MaximumParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue); 108 109 } 109 110 } -
trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Manipulators/MichalewiczNonUniformOnePositionManipulator.cs
r2900 r2915 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.Text;25 23 using HeuristicLab.Core; 26 24 using HeuristicLab.Data; 25 using HeuristicLab.Parameters; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 27 28 28 namespace HeuristicLab.Encodings.RealVector { 29 29 /// <summary> 30 /// Michalewicz, Z. (1992). Genetic Algorithms + Data Structures = Evolution Programs<br/>31 /// Non-uniformly distributed change of one position of a real vector.30 /// The solution is manipulated with diminishing strength over time. In addition the mutated value is not sampled over the entire domain, but additive at the selected position.<br/> 31 /// Initially, the space will be searched uniformly and very locally at later stages. This increases the probability of generating the new number closer to the current value. 32 32 /// </summary> 33 public class MichalewiczNonUniformOnePositionManipulator : RealVectorManipulatorBase { 34 /// <inheritdoc select="summary"/> 35 public override string Description { 36 get { return 37 @"Non-uniformly distributed change of one position of a real vector (Michalewicz 1992) 38 Initially, the space will be searched uniformly and very locally at later stages. This increases the probability of generating the new number closer to its successor instead of a random number. 39 40 Michalewicz, Z. (1992). Genetic Algorithms + Data Structures = Evolution Programs. Springer Verlag."; 41 } 33 /// <remarks> 34 /// It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg. 35 /// </remarks> 36 [Item("MichalewiczNonUniformOnePositionManipulator", "It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.")] 37 [EmptyStorableClass] 38 public class MichalewiczNonUniformOnePositionManipulator : RealVectorManipulator { 39 public ValueLookupParameter<DoubleData> MinimumParameter { 40 get { return (ValueLookupParameter<DoubleData>)Parameters["Minimum"]; } 41 } 42 public ValueLookupParameter<DoubleData> MaximumParameter { 43 get { return (ValueLookupParameter<DoubleData>)Parameters["Maximum"]; } 44 } 45 public LookupParameter<IntData> GenerationParameter { 46 get { return (LookupParameter<IntData>)Parameters["Generation"]; } 47 } 48 public LookupParameter<IntData> MaximumGenerationsParameter { 49 get { return (LookupParameter<IntData>)Parameters["MaximumGenerations"]; } 50 } 51 public ValueLookupParameter<DoubleData> GenerationDependencyParameter { 52 get { return (ValueLookupParameter<DoubleData>)Parameters["GenerationDependency"]; } 42 53 } 43 54 44 55 /// <summary> 45 56 /// Initializes a new instance of <see cref="MichalewiczNonUniformOnePositionManipulator"/> with five 46 /// variable infos (<c>Minimum</c>, <c>Maximum</c>, <c>CurrentGeneration</c>, <c>MaximumGenerations</c>47 /// and <c>Generation sDependency</c>).57 /// parameters (<c>Minimum</c>, <c>Maximum</c>, <c>CurrentGeneration</c>, <c>MaximumGenerations</c> 58 /// and <c>GenerationDependency</c>). 48 59 /// </summary> 49 60 public MichalewiczNonUniformOnePositionManipulator() 50 61 : base() { 51 AddVariableInfo(new VariableInfo("Minimum", "Minimum of the sampling range for the vector element (included)", typeof(DoubleData), VariableKind.In)); 52 AddVariableInfo(new VariableInfo("Maximum", "Maximum of the sampling range for the vector element (excluded)", typeof(DoubleData), VariableKind.In)); 53 AddVariableInfo(new VariableInfo("CurrentGeneration", "Current Generation of the algorithm", typeof(IntData), VariableKind.In)); 54 AddVariableInfo(new VariableInfo("MaximumGenerations", "Maximum number of Generations", typeof(IntData), VariableKind.In)); 55 VariableInfo genDepInfo = new VariableInfo("GenerationsDependency", "Specifies the degree of dependency on the number of generations", typeof(IntData), VariableKind.In); 56 genDepInfo.Local = true; 57 AddVariableInfo(genDepInfo); 58 AddVariable(new Variable("GenerationsDependency", new IntData(5))); 62 Parameters.Add(new ValueLookupParameter<DoubleData>("Minimum", "Minimum of the sampling range for the vector element (included)")); 63 Parameters.Add(new ValueLookupParameter<DoubleData>("Maximum", "Maximum of the sampling range for the vector element (excluded)")); 64 Parameters.Add(new LookupParameter<IntData>("Generation", "Current generation of the algorithm")); 65 Parameters.Add(new LookupParameter<IntData>("MaximumGenerations", "Maximum number of generations")); 66 Parameters.Add(new ValueLookupParameter<DoubleData>("GenerationDependency", "Specifies the degree of dependency on the number of generations", new DoubleData(5))); 59 67 } 60 68 61 69 /// <summary> 62 70 /// Performs a non uniformly distributed one position manipulation on the given 63 /// real <paramref name="vector"/> , published by Z. Michalewicz, 1992.71 /// real <paramref name="vector"/>. The probability of stronger mutations reduces the more <see cref="currentGeneration"/> approaches <see cref="maximumGenerations"/>. 64 72 /// </summary> 65 /// <remarks>Calls <see cref="Apply"/>.</remarks> 66 /// <param name="scope">The current scope.</param> 67 /// <param name="random">The random number generator.</param> 68 /// <param name="vector">The real vector to manipulate.</param> 69 /// <returns>The manipulated real vector.</returns> 70 protected override double[] Manipulate(IScope scope, IRandom random, double[] vector) { 71 double min = GetVariableValue<DoubleData>("Minimum", scope, true).Data; 72 double max = GetVariableValue<DoubleData>("Maximum", scope, true).Data; 73 int currentGeneration = GetVariableValue<IntData>("CurrentGeneration", scope, true).Data; 74 int maximumGenerations = GetVariableValue<IntData>("MaximumGenerations", scope, true).Data; 75 int generationsDependency = GetVariableValue<IntData>("GenerationsDependency", scope, true).Data; 76 return Apply(random, vector, min, max, currentGeneration, maximumGenerations, generationsDependency); 77 } 78 79 /// <summary> 80 /// Performs a non uniformly distributed one position manipulation on the given 81 /// real <paramref name="vector"/>, published by Z. Michalewicz, 1992. 82 /// </summary> 73 /// <exception cref="ArgumentException">Thrown when <paramref name="currentGeneration"/> is greater than <paramref name="maximumGenerations"/>.</exception> 83 74 /// <param name="random">The random number generator.</param> 84 75 /// <param name="vector">The real vector to manipulate.</param> … … 89 80 /// <param name="generationsDependency">Specifies the degree of dependency on the number of generations.</param> 90 81 /// <returns>The manipulated real vector.</returns> 91 public static double[] Apply(IRandom random, double[] vector, double min, double max, int currentGeneration, int maximumGenerations, int generationsDependency) { 82 public static void Apply(IRandom random, DoubleArrayData vector, DoubleData min, DoubleData max, IntData currentGeneration, IntData maximumGenerations, DoubleData generationsDependency) { 83 if (currentGeneration.Value > maximumGenerations.Value) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: CurrentGeneration must be smaller or equal than MaximumGeneration", "currentGeneration"); 92 84 int length = vector.Length; 93 double[] result = new double[length]; 94 int pos = random.Next(length); 85 int index = random.Next(length); 86 87 double prob = (1 - Math.Pow(random.NextDouble(), Math.Pow(1 - currentGeneration.Value / maximumGenerations.Value, generationsDependency.Value))); 95 88 96 89 if (random.NextDouble() < 0.5) { 97 vector[ pos] = vector[pos] + Delta(random, currentGeneration, max - vector[pos], maximumGenerations, generationsDependency);90 vector[index] = vector[index] + (max.Value - vector[index]) * prob; 98 91 } else { 99 vector[ pos] = vector[pos] - Delta(random, currentGeneration, vector[pos] - min, maximumGenerations, generationsDependency);92 vector[index] = vector[index] - (vector[index] - min.Value) * prob; 100 93 } 101 return vector;102 94 } 103 95 104 // returns a value between 0 and y (both included) 105 private static double Delta(IRandom random, int currentGeneration, double y, int maximumGenerations, int generationsDependency) { 106 return y * (1 - Math.Pow(random.NextDouble(), Math.Pow(1 - currentGeneration / maximumGenerations, generationsDependency))); 96 /// <summary> 97 /// Checks if all parameters are available and forwards the call to <see cref="Apply(IRandom, DoubleArrayData, DoubleData, DoubleData, IntData, IntData, DoubleData)"/>. 98 /// </summary> 99 /// <param name="random">The random number generator.</param> 100 /// <param name="realVector">The real vector that should be manipulated.</param> 101 protected override void Manipulate(IRandom random, DoubleArrayData realVector) { 102 if (MinimumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MinimumParameter.ActualName + " could not be found."); 103 if (MaximumParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MaximumParameter.ActualName + " could not be found."); 104 if (GenerationParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + GenerationParameter.ActualName + " could not be found."); 105 if (MaximumGenerationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MaximumGenerationsParameter.ActualName + " could not be found."); 106 if (GenerationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + GenerationDependencyParameter.ActualName + " could not be found."); 107 Apply(random, realVector, MinimumParameter.ActualValue, MaximumParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue); 107 108 } 108 109 }
Note: See TracChangeset
for help on using the changeset viewer.