Changeset 16609


Ignore:
Timestamp:
02/16/19 05:27:50 (8 months ago)
Author:
swagner
Message:

#2989: Worked on Moving Peaks Benchmark

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  
    4848  </ItemGroup>
    4949  <ItemGroup>
     50    <Compile Include="Analyzers\BestMovingPeaksBenchmarkSolutionAnalyzer.cs" />
     51    <Compile Include="Interfaces\IBestMovingPeaksBenchmarkSolutionAnalyzer.cs" />
    5052    <Compile Include="Interfaces\IMovingPeaksBenchmarkProblemEvaluator.cs" />
    5153    <Compile Include="MovingPeaksBenchmarkProblem.cs" />
     
    6062  </ItemGroup>
    6163  <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>
    6268    <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj">
    6369      <Project>{958b43bc-cc5c-4fa2-8628-2b3b01d890b6}</Project>
     
    100106      <Name>HeuristicLab.PluginInfrastructure-3.3</Name>
    101107    </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>
    102112  </ItemGroup>
    103113  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3/Interfaces/IMovingPeaksBenchmarkProblemEvaluator.cs

    r16607 r16609  
    3030  /// </summary>
    3131  public interface IMovingPeaksBenchmarkProblemEvaluator : ISingleObjectiveEvaluator {
    32     ILookupParameter<DoubleMatrix> PeakLocationsParameter { get; }
    33     ILookupParameter<DoubleArray> PeakWidthsParameter { get; }
    34     ILookupParameter<DoubleArray> PeakHeightsParameter { get; }
     32    IValueLookupParameter<DoubleMatrix> PeakLocationsParameter { get; }
     33    IValueLookupParameter<DoubleArray> PeakWidthsParameter { get; }
     34    IValueLookupParameter<DoubleArray> PeakHeightsParameter { get; }
    3535    ILookupParameter<RealVector> PointParameter { get; }
    3636  }
  • branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3/MovingPeaksBenchmarkProblem.cs

    r16608 r16609  
    6262      get { return (ValueParameter<DoubleMatrix>)Parameters["InitialPeakLocations"]; }
    6363    }
    64     public ValueParameter<DoubleMatrix> PeakLocationsParameter {
    65       get { return (ValueParameter<DoubleMatrix>)Parameters["PeakLocations"]; }
    66     }
    6764    public ValueParameter<DoubleArray> InitialPeakWidthsParameter {
    6865      get { return (ValueParameter<DoubleArray>)Parameters["InitialPeakWidths"]; }
    6966    }
    70     public ValueParameter<DoubleArray> PeakWidthsParameter {
    71       get { return (ValueParameter<DoubleArray>)Parameters["PeakWidths"]; }
    72     }
    7367    public ValueParameter<DoubleArray> InitialPeakHeightsParameter {
    7468      get { return (ValueParameter<DoubleArray>)Parameters["InitialPeakHeights"]; }
    7569    }
    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"]; }
    7878    }
    7979    public OptionalValueParameter<RealVector> BestKnownSolutionParameter {
     
    9999      set { InitialPeakLocationsParameter.Value = value; }
    100100    }
    101     public DoubleMatrix PeakLocations {
    102       get { return PeakLocationsParameter.Value; }
    103       set { PeakLocationsParameter.Value = value; }
    104     }
    105101    public DoubleArray InitialPeakWidths {
    106102      get { return InitialPeakWidthsParameter.Value; }
    107103      set { InitialPeakWidthsParameter.Value = value; }
    108104    }
    109     public DoubleArray PeakWidths {
    110       get { return PeakWidthsParameter.Value; }
    111       set { PeakWidthsParameter.Value = value; }
    112     }
    113105    public DoubleArray InitialPeakHeights {
    114106      get { return InitialPeakHeightsParameter.Value; }
    115107      set { InitialPeakHeightsParameter.Value = value; }
    116108    }
    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    }
    124121    #endregion
    125122
     
    147144      var defaultWidths = new double[] { 0.1, 0.1, 0.1, 0.1, 0.1 };
    148145      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 };
    149147
    150148      Parameters.Add(new ValueParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension.", new DoubleMatrix(defaultBounds)));
     
    152150      Parameters.Add(new ValueParameter<IntValue>("Peaks", "The number of peaks.", new IntValue(5)));
    153151      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)));
    155152      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)));
    157153      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)));
    161158
    162159      Maximization.Value = true;
    163       //BestKnownQuality = new DoubleValue(Evaluator.BestKnownQuality);
     160      BestKnownQuality = new DoubleValue(defaultHeights.Max());
    164161
    165162      //strategyVectorCreator = new StdDevStrategyVectorCreator();
     
    181178    public override IDeepCloneable Clone(Cloner cloner) {
    182179      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;
    190180    }
    191181
     
    297287    }
    298288    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      }
    309297    }
    310298    private void InitializeOperators() {
     
    316304      //Operators.Add(new QualitySimilarityCalculator());
    317305
    318       //Operators.Add(new BestSingleObjectiveTestFunctionSolutionAnalyzer());
     306      Operators.Add(new BestMovingPeaksBenchmarkSolutionAnalyzer());
    319307      //Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
    320308      ParameterizeAnalyzers();
  • branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3/MovingPeaksBenchmarkProblemEvaluator.cs

    r16608 r16609  
    2020#endregion
    2121
     22using System;
     23using System.Linq;
    2224using HeuristicLab.Common;
    2325using HeuristicLab.Core;
     
    2527using HeuristicLab.Encodings.RealVectorEncoding;
    2628using HeuristicLab.Operators;
     29using HeuristicLab.Optimization;
    2730using HeuristicLab.Parameters;
    2831using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     32using HeuristicLab.Random;
    2933
    3034namespace HeuristicLab.Problems.MovingPeaksBenchmark {
     
    3236  [StorableClass]
    3337  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"]; }
    4260    }
    4361    public ILookupParameter<RealVector> PointParameter {
     
    4664    public ILookupParameter<DoubleValue> QualityParameter {
    4765      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"]; }
    4875    }
    4976
     
    5279    protected MovingPeaksBenchmarkProblemEvaluator(MovingPeaksBenchmarkProblemEvaluator original, Cloner cloner) : base(original, cloner) { }
    5380    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."));
    5790      Parameters.Add(new LookupParameter<RealVector>("Point", "The point which should be evaluated."));
    5891      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;
    59102    }
    60103
     
    67110      DoubleArray widths = PeakWidthsParameter.ActualValue;
    68111      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
    69149      RealVector point = PointParameter.ActualValue;
    70150      double quality = Apply(peaks, widths, heights, point);
     
    73153    }
    74154
     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
    75168    public double Apply(DoubleMatrix peaks, DoubleArray widths, DoubleArray heights, RealVector point) {
    76       heights[0] *= 1.01;
    77 
    78169      double max = 0;
    79170      double val = 0;
     
    89180      return max;
    90181    }
     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    }
    91207  }
    92208}
  • branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3/Plugin.cs.frame

    r16607 r16609  
    2828  [PluginFile("HeuristicLab.Problems.MovingPeaksBenchmark-3.3.dll", PluginFileType.Assembly)]
    2929  [Plugin("HeuristicLab.Problems.MovingPeaksBenchmark", "3.3.15.$WCREV$")]
    30 //  [PluginDependency("HeuristicLab.Analysis", "3.3")]
     30  [PluginDependency("HeuristicLab.Analysis", "3.3")]
    3131  [PluginDependency("HeuristicLab.Collections", "3.3")]
    3232  [PluginDependency("HeuristicLab.Common", "3.3")]
     
    4141  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    4242  [PluginDependency("HeuristicLab.Persistence", "3.3")]
     43  [PluginDependency("HeuristicLab.Random", "3.3")]
    4344  public class HeuristicLabProblemsMovingPeaksBenchmarkPlugin : PluginBase {
    4445  }
Note: See TracChangeset for help on using the changeset viewer.