- Timestamp:
- 02/16/19 05:27:50 (6 years ago)
- Location:
- branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3/HeuristicLab.Problems.MovingPeaksBenchmark-3.3.csproj
r16607 r16609 48 48 </ItemGroup> 49 49 <ItemGroup> 50 <Compile Include="Analyzers\BestMovingPeaksBenchmarkSolutionAnalyzer.cs" /> 51 <Compile Include="Interfaces\IBestMovingPeaksBenchmarkSolutionAnalyzer.cs" /> 50 52 <Compile Include="Interfaces\IMovingPeaksBenchmarkProblemEvaluator.cs" /> 51 53 <Compile Include="MovingPeaksBenchmarkProblem.cs" /> … … 60 62 </ItemGroup> 61 63 <ItemGroup> 64 <ProjectReference Include="..\..\HeuristicLab.Analysis\3.3\HeuristicLab.Analysis-3.3.csproj"> 65 <Project>{887425b4-4348-49ed-a457-b7d2c26ddbf9}</Project> 66 <Name>HeuristicLab.Analysis-3.3</Name> 67 </ProjectReference> 62 68 <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj"> 63 69 <Project>{958b43bc-cc5c-4fa2-8628-2b3b01d890b6}</Project> … … 100 106 <Name>HeuristicLab.PluginInfrastructure-3.3</Name> 101 107 </ProjectReference> 108 <ProjectReference Include="..\..\HeuristicLab.Random\3.3\HeuristicLab.Random-3.3.csproj"> 109 <Project>{f4539fb6-4708-40c9-be64-0a1390aea197}</Project> 110 <Name>HeuristicLab.Random-3.3</Name> 111 </ProjectReference> 102 112 </ItemGroup> 103 113 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3/Interfaces/IMovingPeaksBenchmarkProblemEvaluator.cs
r16607 r16609 30 30 /// </summary> 31 31 public interface IMovingPeaksBenchmarkProblemEvaluator : ISingleObjectiveEvaluator { 32 I LookupParameter<DoubleMatrix> PeakLocationsParameter { get; }33 I LookupParameter<DoubleArray> PeakWidthsParameter { get; }34 I LookupParameter<DoubleArray> PeakHeightsParameter { get; }32 IValueLookupParameter<DoubleMatrix> PeakLocationsParameter { get; } 33 IValueLookupParameter<DoubleArray> PeakWidthsParameter { get; } 34 IValueLookupParameter<DoubleArray> PeakHeightsParameter { get; } 35 35 ILookupParameter<RealVector> PointParameter { get; } 36 36 } -
branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3/MovingPeaksBenchmarkProblem.cs
r16608 r16609 62 62 get { return (ValueParameter<DoubleMatrix>)Parameters["InitialPeakLocations"]; } 63 63 } 64 public ValueParameter<DoubleMatrix> PeakLocationsParameter {65 get { return (ValueParameter<DoubleMatrix>)Parameters["PeakLocations"]; }66 }67 64 public ValueParameter<DoubleArray> InitialPeakWidthsParameter { 68 65 get { return (ValueParameter<DoubleArray>)Parameters["InitialPeakWidths"]; } 69 66 } 70 public ValueParameter<DoubleArray> PeakWidthsParameter {71 get { return (ValueParameter<DoubleArray>)Parameters["PeakWidths"]; }72 }73 67 public ValueParameter<DoubleArray> InitialPeakHeightsParameter { 74 68 get { return (ValueParameter<DoubleArray>)Parameters["InitialPeakHeights"]; } 75 69 } 76 public ValueParameter<DoubleArray> PeakHeightsParameter { 77 get { return (ValueParameter<DoubleArray>)Parameters["PeakHeights"]; } 70 public FixedValueParameter<IntValue> MovingPeaksRandomSeedParameter { 71 get { return (FixedValueParameter<IntValue>)Parameters["MovingPeaksRandomSeed"]; } 72 } 73 public FixedValueParameter<IntValue> PeakMovementIntervalParameter { 74 get { return (FixedValueParameter<IntValue>)Parameters["PeakMovementInterval"]; } 75 } 76 public FixedValueParameter<DoubleValue> PeakMovementStrengthParameter { 77 get { return (FixedValueParameter<DoubleValue>)Parameters["PeakMovementStrength"]; } 78 78 } 79 79 public OptionalValueParameter<RealVector> BestKnownSolutionParameter { … … 99 99 set { InitialPeakLocationsParameter.Value = value; } 100 100 } 101 public DoubleMatrix PeakLocations {102 get { return PeakLocationsParameter.Value; }103 set { PeakLocationsParameter.Value = value; }104 }105 101 public DoubleArray InitialPeakWidths { 106 102 get { return InitialPeakWidthsParameter.Value; } 107 103 set { InitialPeakWidthsParameter.Value = value; } 108 104 } 109 public DoubleArray PeakWidths {110 get { return PeakWidthsParameter.Value; }111 set { PeakWidthsParameter.Value = value; }112 }113 105 public DoubleArray InitialPeakHeights { 114 106 get { return InitialPeakHeightsParameter.Value; } 115 107 set { InitialPeakHeightsParameter.Value = value; } 116 108 } 117 public DoubleArray PeakHeights { 118 get { return PeakHeightsParameter.Value; } 119 set { PeakHeightsParameter.Value = value; } 120 } 121 // private BestSingleObjectiveTestFunctionSolutionAnalyzer BestSingleObjectiveTestFunctionSolutionAnalyzer { 122 // get { return Operators.OfType<BestSingleObjectiveTestFunctionSolutionAnalyzer>().FirstOrDefault(); } 123 // } 109 public IntValue MovingPeaksRandomSeed { 110 get { return MovingPeaksRandomSeedParameter.Value; } 111 } 112 public IntValue PeakMovementInterval { 113 get { return PeakMovementIntervalParameter.Value; } 114 } 115 public DoubleValue PeakMovementStrength { 116 get { return PeakMovementStrengthParameter.Value; } 117 } 118 private BestMovingPeaksBenchmarkSolutionAnalyzer BestMovingPeaksBenchmarkSolutionAnalyzer { 119 get { return Operators.OfType<BestMovingPeaksBenchmarkSolutionAnalyzer>().FirstOrDefault(); } 120 } 124 121 #endregion 125 122 … … 147 144 var defaultWidths = new double[] { 0.1, 0.1, 0.1, 0.1, 0.1 }; 148 145 var defaultHeights = new double[] { 50.0, 50.0, 50.0, 50.0, 50.0 }; 146 var defaultBestKnown = new double[] { 08.0, 64.0, 67.0, 55.0, 04.0 }; 149 147 150 148 Parameters.Add(new ValueParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension.", new DoubleMatrix(defaultBounds))); … … 152 150 Parameters.Add(new ValueParameter<IntValue>("Peaks", "The number of peaks.", new IntValue(5))); 153 151 Parameters.Add(new ValueParameter<DoubleMatrix>("InitialPeakLocations", "Initial coordinates of each peaks.", new DoubleMatrix(defaultPeaks))); 154 Parameters.Add(new ValueParameter<DoubleMatrix>("PeakLocations", "Current coordinates of each peaks.", new DoubleMatrix(defaultPeaks)));155 152 Parameters.Add(new ValueParameter<DoubleArray>("InitialPeakWidths", "Initial width of each peak.", new DoubleArray(defaultWidths))); 156 Parameters.Add(new ValueParameter<DoubleArray>("PeakWidths", "Current width of each peak.", new DoubleArray(defaultWidths)));157 153 Parameters.Add(new ValueParameter<DoubleArray>("InitialPeakHeights", "Initial height of each peak.", new DoubleArray(defaultHeights))); 158 Parameters.Add(new ValueParameter<DoubleArray>("PeakHeights", "Current height of each peak.", new DoubleArray(defaultHeights))); 159 160 //Parameters.Add(new OptionalValueParameter<RealVector>("BestKnownSolution", "The best known solution for this test function instance.")); 154 Parameters.Add(new FixedValueParameter<IntValue>("MovingPeaksRandomSeed", "The random seed for initializing the PRNG for changing the peaks.", new IntValue(666))); 155 Parameters.Add(new FixedValueParameter<IntValue>("PeakMovementInterval", "The interval in evaluated solutions in which peaks are moved.", new IntValue(1000))); 156 Parameters.Add(new FixedValueParameter<DoubleValue>("PeakMovementStrength", "The length of the random vector used for changing peak locations.", new DoubleValue(1.0))); 157 Parameters.Add(new OptionalValueParameter<RealVector>("BestKnownSolution", "The location of the highest peak.", new RealVector(defaultBestKnown))); 161 158 162 159 Maximization.Value = true; 163 //BestKnownQuality = new DoubleValue(Evaluator.BestKnownQuality);160 BestKnownQuality = new DoubleValue(defaultHeights.Max()); 164 161 165 162 //strategyVectorCreator = new StdDevStrategyVectorCreator(); … … 181 178 public override IDeepCloneable Clone(Cloner cloner) { 182 179 return new MovingPeaksBenchmarkProblem(this, cloner); 183 }184 185 protected override void OnReset() {186 base.OnReset();187 PeakLocations = InitialPeakLocations.Clone() as DoubleMatrix;188 PeakWidths = InitialPeakWidths.Clone() as DoubleArray;189 PeakHeights = InitialPeakHeights.Clone() as DoubleArray;190 180 } 191 181 … … 297 287 } 298 288 private void ParameterizeAnalyzers() { 299 //if (BestSingleObjectiveTestFunctionSolutionAnalyzer != null) { 300 // BestSingleObjectiveTestFunctionSolutionAnalyzer.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName; 301 // BestSingleObjectiveTestFunctionSolutionAnalyzer.ResultsParameter.ActualName = "Results"; 302 // BestSingleObjectiveTestFunctionSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 303 // BestSingleObjectiveTestFunctionSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name; 304 // BestSingleObjectiveTestFunctionSolutionAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name; 305 // BestSingleObjectiveTestFunctionSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name; 306 // BestSingleObjectiveTestFunctionSolutionAnalyzer.EvaluatorParameter.ActualName = EvaluatorParameter.Name; 307 // BestSingleObjectiveTestFunctionSolutionAnalyzer.BoundsParameter.ActualName = BoundsParameter.Name; 308 //} 289 if (BestMovingPeaksBenchmarkSolutionAnalyzer != null) { 290 BestMovingPeaksBenchmarkSolutionAnalyzer.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName; 291 BestMovingPeaksBenchmarkSolutionAnalyzer.ResultsParameter.ActualName = "Results"; 292 BestMovingPeaksBenchmarkSolutionAnalyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName; 293 BestMovingPeaksBenchmarkSolutionAnalyzer.BestKnownQualityParameter.ActualName = BestKnownQualityParameter.Name; 294 BestMovingPeaksBenchmarkSolutionAnalyzer.BestKnownSolutionParameter.ActualName = BestKnownSolutionParameter.Name; 295 BestMovingPeaksBenchmarkSolutionAnalyzer.MaximizationParameter.ActualName = MaximizationParameter.Name; 296 } 309 297 } 310 298 private void InitializeOperators() { … … 316 304 //Operators.Add(new QualitySimilarityCalculator()); 317 305 318 //Operators.Add(new BestSingleObjectiveTestFunctionSolutionAnalyzer());306 Operators.Add(new BestMovingPeaksBenchmarkSolutionAnalyzer()); 319 307 //Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>())); 320 308 ParameterizeAnalyzers(); -
branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3/MovingPeaksBenchmarkProblemEvaluator.cs
r16608 r16609 20 20 #endregion 21 21 22 using System; 23 using System.Linq; 22 24 using HeuristicLab.Common; 23 25 using HeuristicLab.Core; … … 25 27 using HeuristicLab.Encodings.RealVectorEncoding; 26 28 using HeuristicLab.Operators; 29 using HeuristicLab.Optimization; 27 30 using HeuristicLab.Parameters; 28 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 using HeuristicLab.Random; 29 33 30 34 namespace HeuristicLab.Problems.MovingPeaksBenchmark { … … 32 36 [StorableClass] 33 37 public class MovingPeaksBenchmarkProblemEvaluator : InstrumentedOperator, IMovingPeaksBenchmarkProblemEvaluator { 34 public ILookupParameter<DoubleMatrix> PeakLocationsParameter { 35 get { return (ILookupParameter<DoubleMatrix>)Parameters["PeakLocations"]; } 36 } 37 public ILookupParameter<DoubleArray> PeakWidthsParameter { 38 get { return (ILookupParameter<DoubleArray>)Parameters["PeakWidths"]; } 39 } 40 public ILookupParameter<DoubleArray> PeakHeightsParameter { 41 get { return (ILookupParameter<DoubleArray>)Parameters["PeakHeights"]; } 38 [Storable] 39 IRandom uniformRandom; 40 [Storable] 41 long executions; 42 43 public IValueLookupParameter<DoubleMatrix> PeakLocationsParameter { 44 get { return (IValueLookupParameter<DoubleMatrix>)Parameters["PeakLocations"]; } 45 } 46 public IValueLookupParameter<DoubleArray> PeakWidthsParameter { 47 get { return (IValueLookupParameter<DoubleArray>)Parameters["PeakWidths"]; } 48 } 49 public IValueLookupParameter<DoubleArray> PeakHeightsParameter { 50 get { return (IValueLookupParameter<DoubleArray>)Parameters["PeakHeights"]; } 51 } 52 public ILookupParameter<IntValue> MovingPeaksRandomSeedParameter { 53 get { return (ILookupParameter<IntValue>)Parameters["MovingPeaksRandomSeed"]; } 54 } 55 public ILookupParameter<IntValue> PeakMovementIntervalParameter { 56 get { return (ILookupParameter<IntValue>)Parameters["PeakMovementInterval"]; } 57 } 58 public ILookupParameter<DoubleValue> PeakMovementStrengthParameter { 59 get { return (ILookupParameter<DoubleValue>)Parameters["PeakMovementStrength"]; } 42 60 } 43 61 public ILookupParameter<RealVector> PointParameter { … … 46 64 public ILookupParameter<DoubleValue> QualityParameter { 47 65 get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; } 66 } 67 public ILookupParameter<DoubleValue> BestKnownQualityParameter { 68 get { return (ILookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 69 } 70 public ILookupParameter<RealVector> BestKnownSolutionParameter { 71 get { return (ILookupParameter<RealVector>)Parameters["BestKnownSolution"]; } 72 } 73 public IValueLookupParameter<ResultCollection> ResultsParameter { 74 get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; } 48 75 } 49 76 … … 52 79 protected MovingPeaksBenchmarkProblemEvaluator(MovingPeaksBenchmarkProblemEvaluator original, Cloner cloner) : base(original, cloner) { } 53 80 public MovingPeaksBenchmarkProblemEvaluator() : base() { 54 Parameters.Add(new LookupParameter<DoubleMatrix>("PeakLocations", "Current position of the peaks.")); 55 Parameters.Add(new LookupParameter<DoubleArray>("PeakWidths", "Current width of the peaks.")); 56 Parameters.Add(new LookupParameter<DoubleArray>("PeakHeights", "Current height of the peaks.")); 81 Parameters.Add(new ValueLookupParameter<DoubleMatrix>("PeakLocations", "Current position of the peaks.")); 82 PeakLocationsParameter.ActualName = "InitialPeakLocations"; 83 Parameters.Add(new ValueLookupParameter<DoubleArray>("PeakWidths", "Current width of the peaks.")); 84 PeakWidthsParameter.ActualName = "InitialPeakWidths"; 85 Parameters.Add(new ValueLookupParameter<DoubleArray>("PeakHeights", "Current height of the peaks.")); 86 PeakHeightsParameter.ActualName = "InitialPeakHeights"; 87 Parameters.Add(new LookupParameter<IntValue>("MovingPeaksRandomSeed", "The random seed for initializing the PRNG for changing the peaks.")); 88 Parameters.Add(new LookupParameter<IntValue>("PeakMovementInterval", "The interval in evaluated solutions in which peaks are moved.")); 89 Parameters.Add(new LookupParameter<DoubleValue>("PeakMovementStrength", "The length of the random vector used for changing peak locations.")); 57 90 Parameters.Add(new LookupParameter<RealVector>("Point", "The point which should be evaluated.")); 58 91 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "Quality value of the evaluated point.")); 92 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "Quality value of the highest peak.")); 93 Parameters.Add(new LookupParameter<RealVector>("BestKnownSolution", "The location of the highest peak.")); 94 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection for storing result values.")); 95 96 PeakLocationsParameter.Hidden = true; 97 PeakWidthsParameter.Hidden = true; 98 PeakHeightsParameter.Hidden = true; 99 BestKnownQualityParameter.Hidden = true; 100 BestKnownSolutionParameter.Hidden = true; 101 ResultsParameter.Hidden = true; 59 102 } 60 103 … … 67 110 DoubleArray widths = PeakWidthsParameter.ActualValue; 68 111 DoubleArray heights = PeakHeightsParameter.ActualValue; 112 113 if (PeakLocationsParameter.Value == null) { 114 peaks = peaks.Clone() as DoubleMatrix; 115 widths = widths.Clone() as DoubleArray; 116 heights = heights.Clone() as DoubleArray; 117 PeakLocationsParameter.Value = peaks; 118 PeakWidthsParameter.Value = widths; 119 PeakHeightsParameter.Value = heights; 120 121 ResultCollection results = ResultsParameter.ActualValue; 122 results.Add(new Result("Current Peak Locations", peaks)); 123 results.Add(new Result("Current Peak Widths", widths)); 124 results.Add(new Result("Current Peak Heights", heights)); 125 } 126 if (uniformRandom == null) { 127 uniformRandom = new MersenneTwister(); 128 uniformRandom.Reset(MovingPeaksRandomSeedParameter.ActualValue.Value); 129 } 130 131 // move peaks if peaks movement interval is reached 132 lock (this) { 133 if ((executions % PeakMovementIntervalParameter.ActualValue.Value) == 0) { 134 MovePeaks(uniformRandom, peaks, widths, heights, PeakMovementStrengthParameter.ActualValue.Value); 135 136 // update best known solution & quality according to highest peak 137 double maxHeight = heights.Max(); 138 int peakIndex = Array.IndexOf(heights.CloneAsArray(), maxHeight); 139 double[] peak = new double[peaks.Columns]; 140 for (int i = 0; i < peak.Length; i++) { 141 peak[i] = peaks[peakIndex, i]; 142 } 143 BestKnownSolutionParameter.ActualValue = new RealVector(peak); 144 BestKnownQualityParameter.ActualValue.Value = heights.Max(); 145 } 146 executions++; 147 } 148 69 149 RealVector point = PointParameter.ActualValue; 70 150 double quality = Apply(peaks, widths, heights, point); … … 73 153 } 74 154 155 public override void InitializeState() { 156 base.InitializeState(); 157 executions = 0; 158 } 159 160 public override void ClearState() { 161 base.ClearState(); 162 uniformRandom = null; 163 PeakLocationsParameter.Value = null; 164 PeakWidthsParameter.Value = null; 165 PeakHeightsParameter.Value = null; 166 } 167 75 168 public double Apply(DoubleMatrix peaks, DoubleArray widths, DoubleArray heights, RealVector point) { 76 heights[0] *= 1.01;77 78 169 double max = 0; 79 170 double val = 0; … … 89 180 return max; 90 181 } 182 183 private void MovePeaks(IRandom uniformRandom, DoubleMatrix peaks, DoubleArray widths, DoubleArray heights, double strength) { 184 IRandom normalRandom = new NormalDistributedRandom(uniformRandom, 0, 1); 185 for (int i = 0; i < peaks.Rows; i++) { 186 double[] v = RandomVector(uniformRandom, peaks.Columns, strength); 187 for (int j = 0; j < v.Length; j++) { 188 peaks[i, j] += v[j]; 189 } 190 widths[i] = widths[i] + 0.01 * normalRandom.NextDouble(); 191 heights[i] = heights[i] + 7 * normalRandom.NextDouble(); 192 } 193 } 194 195 private double[] RandomVector(IRandom uniformRandom, int dimensions, double length) { 196 double[] vector = new double[dimensions]; 197 198 for (int i = 0; i < vector.Length; i++) { 199 vector[i] = uniformRandom.NextDouble() - 0.5; 200 } 201 double factor = length / Math.Sqrt(vector.Select(x => x * x).Sum()); 202 for (int i = 0; i < vector.Length; i++) { 203 vector[i] *= factor; 204 } 205 return vector; 206 } 91 207 } 92 208 } -
branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3/Plugin.cs.frame
r16607 r16609 28 28 [PluginFile("HeuristicLab.Problems.MovingPeaksBenchmark-3.3.dll", PluginFileType.Assembly)] 29 29 [Plugin("HeuristicLab.Problems.MovingPeaksBenchmark", "3.3.15.$WCREV$")] 30 //[PluginDependency("HeuristicLab.Analysis", "3.3")]30 [PluginDependency("HeuristicLab.Analysis", "3.3")] 31 31 [PluginDependency("HeuristicLab.Collections", "3.3")] 32 32 [PluginDependency("HeuristicLab.Common", "3.3")] … … 41 41 [PluginDependency("HeuristicLab.Parameters", "3.3")] 42 42 [PluginDependency("HeuristicLab.Persistence", "3.3")] 43 [PluginDependency("HeuristicLab.Random", "3.3")] 43 44 public class HeuristicLabProblemsMovingPeaksBenchmarkPlugin : PluginBase { 44 45 }
Note: See TracChangeset
for help on using the changeset viewer.