Changeset 16613


Ignore:
Timestamp:
02/17/19 22:56:09 (2 years ago)
Author:
swagner
Message:

#2989: Moving Peaks Benchmark

  • fixed updates of best known quality
  • added bounds for peak movement
Location:
branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3/Analyzers/BestMovingPeaksBenchmarkSolutionAnalyzer.cs

    r16611 r16613  
    102102      else i = qualities.Select((x, index) => new { index, x.Value }).OrderByDescending(x => x.Value).First().index;
    103103
    104       if (bestKnownQuality == null ||
    105           max && qualities[i].Value > bestKnownQuality.Value
    106           || !max && qualities[i].Value < bestKnownQuality.Value) {
    107         BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[i].Value);
    108         BestKnownSolutionParameter.ActualValue = (RealVector)realVectors[i].Clone();
    109       }
    110 
    111104      RealVector best = (RealVector)realVectors[i].Clone();
    112105      RealVector bestKnown = (RealVector)BestKnownSolutionParameter.ActualValue.Clone();
  • branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3/MovingPeaksBenchmarkProblem.cs

    r16609 r16613  
    7171      get { return (FixedValueParameter<IntValue>)Parameters["MovingPeaksRandomSeed"]; }
    7272    }
     73    public FixedValueParameter<DoubleValue> MinPeakWidthParameter {
     74      get { return (FixedValueParameter<DoubleValue>)Parameters["MinPeakWidth"]; }
     75    }
     76    public FixedValueParameter<DoubleValue> MaxPeakWidthParameter {
     77      get { return (FixedValueParameter<DoubleValue>)Parameters["MaxPeakWidth"]; }
     78    }
     79    public FixedValueParameter<DoubleValue> MinPeakHeightParameter {
     80      get { return (FixedValueParameter<DoubleValue>)Parameters["MinPeakHeight"]; }
     81    }
     82    public FixedValueParameter<DoubleValue> MaxPeakHeightParameter {
     83      get { return (FixedValueParameter<DoubleValue>)Parameters["MaxPeakHeight"]; }
     84    }
    7385    public FixedValueParameter<IntValue> PeakMovementIntervalParameter {
    7486      get { return (FixedValueParameter<IntValue>)Parameters["PeakMovementInterval"]; }
     
    109121    public IntValue MovingPeaksRandomSeed {
    110122      get { return MovingPeaksRandomSeedParameter.Value; }
     123    }
     124    public DoubleValue MinPeakWidth {
     125      get { return MinPeakWidthParameter.Value; }
     126    }
     127    public DoubleValue MaxPeakWidth {
     128      get { return MaxPeakWidthParameter.Value; }
     129    }
     130    public DoubleValue MinPeakHeight {
     131      get { return MinPeakHeightParameter.Value; }
     132    }
     133    public DoubleValue MaxPeakHeight {
     134      get { return MaxPeakHeightParameter.Value; }
    111135    }
    112136    public IntValue PeakMovementInterval {
     
    140164        { 09.0, 19.0, 27.0, 67.0, 24.0 },
    141165        { 66.0, 87.0, 65.0, 19.0, 43.0 },
    142         { 76.0, 32.0, 43.0, 54.0, 65.0 }
     166        { 76.0, 32.0, 43.0, 54.0, 65.0 },
     167        { 25.0, 51.0, 17.0, 25.0, 16.0 },
     168        { 19.0, 93.0, 06.0, 35.0, 15.0 },
     169        { 88.0, 44.0, 37.0, 77.0, 74.0 },
     170        { 37.0, 74.0, 55.0, 09.0, 53.0 },
     171        { 42.0, 22.0, 93.0, 84.0, 35.0 }
    143172      };
    144       var defaultWidths = new double[] { 0.1, 0.1, 0.1, 0.1, 0.1 };
    145       var defaultHeights = new double[] { 50.0, 50.0, 50.0, 50.0, 50.0 };
     173      var defaultWidths = new double[] { -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0 };
     174      var defaultHeights = new double[] { 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0, 50.0 };
    146175      var defaultBestKnown = new double[] { 08.0, 64.0, 67.0, 55.0, 04.0 };
    147176
    148177      Parameters.Add(new ValueParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension.", new DoubleMatrix(defaultBounds)));
    149178      Parameters.Add(new ValueParameter<IntValue>("ProblemSize", "The dimension of the problem.", new IntValue(5)));
    150       Parameters.Add(new ValueParameter<IntValue>("Peaks", "The number of peaks.", new IntValue(5)));
     179      Parameters.Add(new ValueParameter<IntValue>("Peaks", "The number of peaks.", new IntValue(10)));
    151180      Parameters.Add(new ValueParameter<DoubleMatrix>("InitialPeakLocations", "Initial coordinates of each peaks.", new DoubleMatrix(defaultPeaks)));
    152181      Parameters.Add(new ValueParameter<DoubleArray>("InitialPeakWidths", "Initial width of each peak.", new DoubleArray(defaultWidths)));
    153182      Parameters.Add(new ValueParameter<DoubleArray>("InitialPeakHeights", "Initial height of each peak.", new DoubleArray(defaultHeights)));
    154183      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)));
     184      Parameters.Add(new FixedValueParameter<DoubleValue>("MinPeakWidth", "The minimum width of each peak.", new DoubleValue(1.0)));
     185      Parameters.Add(new FixedValueParameter<DoubleValue>("MaxPeakWidth", "The maximum width of each peak.", new DoubleValue(12.0)));
     186      Parameters.Add(new FixedValueParameter<DoubleValue>("MinPeakHeight", "The minimum height of each peak.", new DoubleValue(30.0)));
     187      Parameters.Add(new FixedValueParameter<DoubleValue>("MaxPeakHeight", "The maximum height of each peak.", new DoubleValue(70.0)));
     188      Parameters.Add(new FixedValueParameter<IntValue>("PeakMovementInterval", "The interval in evaluated solutions in which peaks are moved.", new IntValue(5000)));
     189      Parameters.Add(new FixedValueParameter<DoubleValue>("PeakMovementStrength", "The length of the random vector used for changing peak locations.", new DoubleValue(1.5)));
    157190      Parameters.Add(new OptionalValueParameter<RealVector>("BestKnownSolution", "The location of the highest peak.", new RealVector(defaultBestKnown)));
    158191
  • branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3/MovingPeaksBenchmarkProblemEvaluator.cs

    r16611 r16613  
    4545    double offlineErrorSum;
    4646
     47    #region Parameters
     48    public ILookupParameter<DoubleMatrix> BoundsParameter {
     49      get { return (ILookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
     50    }
    4751    public IValueLookupParameter<DoubleMatrix> PeakLocationsParameter {
    4852      get { return (IValueLookupParameter<DoubleMatrix>)Parameters["PeakLocations"]; }
     
    5761      get { return (ILookupParameter<IntValue>)Parameters["MovingPeaksRandomSeed"]; }
    5862    }
     63    public ILookupParameter<DoubleValue> MinPeakWidthParameter {
     64      get { return (ILookupParameter<DoubleValue>)Parameters["MinPeakWidth"]; }
     65    }
     66    public ILookupParameter<DoubleValue> MaxPeakWidthParameter {
     67      get { return (ILookupParameter<DoubleValue>)Parameters["MaxPeakWidth"]; }
     68    }
     69    public ILookupParameter<DoubleValue> MinPeakHeightParameter {
     70      get { return (ILookupParameter<DoubleValue>)Parameters["MinPeakHeight"]; }
     71    }
     72    public ILookupParameter<DoubleValue> MaxPeakHeightParameter {
     73      get { return (ILookupParameter<DoubleValue>)Parameters["MaxPeakHeight"]; }
     74    }
    5975    public ILookupParameter<IntValue> PeakMovementIntervalParameter {
    6076      get { return (ILookupParameter<IntValue>)Parameters["PeakMovementInterval"]; }
     
    7894      get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; }
    7995    }
     96    #endregion
    8097
    8198    [StorableConstructor]
     
    83100    protected MovingPeaksBenchmarkProblemEvaluator(MovingPeaksBenchmarkProblemEvaluator original, Cloner cloner) : base(original, cloner) { }
    84101    public MovingPeaksBenchmarkProblemEvaluator() : base() {
     102      Parameters.Add(new LookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension."));
    85103      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("PeakLocations", "Current position of the peaks."));
    86104      PeakLocationsParameter.ActualName = "InitialPeakLocations";
     
    90108      PeakHeightsParameter.ActualName = "InitialPeakHeights";
    91109      Parameters.Add(new LookupParameter<IntValue>("MovingPeaksRandomSeed", "The random seed for initializing the PRNG for changing the peaks."));
     110      Parameters.Add(new LookupParameter<DoubleValue>("MinPeakWidth", "The minimum width of each peak."));
     111      Parameters.Add(new LookupParameter<DoubleValue>("MaxPeakWidth", "The maximum width of each peak."));
     112      Parameters.Add(new LookupParameter<DoubleValue>("MinPeakHeight", "The minimum height of each peak."));
     113      Parameters.Add(new LookupParameter<DoubleValue>("MaxPeakHeight", "The maximum height of each peak."));
    92114      Parameters.Add(new LookupParameter<IntValue>("PeakMovementInterval", "The interval in evaluated solutions in which peaks are moved."));
    93115      Parameters.Add(new LookupParameter<DoubleValue>("PeakMovementStrength", "The length of the random vector used for changing peak locations."));
     
    101123      PeakWidthsParameter.Hidden = true;
    102124      PeakHeightsParameter.Hidden = true;
     125      MovingPeaksRandomSeedParameter.Hidden = true;
     126      MinPeakWidthParameter.Hidden = true;
     127      MaxPeakWidthParameter.Hidden = true;
     128      MinPeakHeightParameter.Hidden = true;
     129      MaxPeakHeightParameter.Hidden = true;
     130      PeakMovementIntervalParameter.Hidden = true;
     131      PeakMovementStrengthParameter.Hidden = true;
    103132      BestKnownQualityParameter.Hidden = true;
    104133      BestKnownSolutionParameter.Hidden = true;
     
    111140
    112141    public override IOperation InstrumentedApply() {
     142      lock (this) {
     143        if (uniformRandom == null) {
     144          uniformRandom = new MersenneTwister();
     145          uniformRandom.Reset(MovingPeaksRandomSeedParameter.ActualValue.Value);
     146        }
     147      }
     148
    113149      DoubleMatrix peaks = PeakLocationsParameter.ActualValue;
    114150      DoubleArray widths = PeakWidthsParameter.ActualValue;
     
    127163        results.Add(new Result("Current Peak Widths", widths));
    128164        results.Add(new Result("Current Peak Heights", heights));
    129       }
    130       if (uniformRandom == null) {
    131         uniformRandom = new MersenneTwister();
    132         uniformRandom.Reset(MovingPeaksRandomSeedParameter.ActualValue.Value);
    133       }
    134 
    135       // move peaks if peaks movement interval is reached
     165
     166        for (int i = 0; i < widths.Length; i++) {
     167          if (widths[i] < 0) {
     168            widths[i] = MinPeakWidthParameter.ActualValue.Value + uniformRandom.NextDouble() * (MaxPeakWidthParameter.ActualValue.Value - MinPeakWidthParameter.ActualValue.Value);
     169          }
     170          if (heights[i] < 0) {
     171            heights[i] = MinPeakHeightParameter.ActualValue.Value + uniformRandom.NextDouble() * (MaxPeakHeightParameter.ActualValue.Value - MinPeakHeightParameter.ActualValue.Value);
     172          }
     173        }
     174      }
     175
    136176      lock (this) {
     177        // move peaks if peaks movement interval is reached
    137178        if ((executions % PeakMovementIntervalParameter.ActualValue.Value) == 0) {
    138           MovePeaks(uniformRandom, peaks, widths, heights, PeakMovementStrengthParameter.ActualValue.Value);
     179          MovePeaks(uniformRandom, peaks, widths, heights,
     180                    PeakMovementStrengthParameter.ActualValue.Value,
     181                    MinPeakWidthParameter.ActualValue.Value, MaxPeakWidthParameter.ActualValue.Value,
     182                    MinPeakHeightParameter.ActualValue.Value, MaxPeakHeightParameter.ActualValue.Value,
     183                    BoundsParameter.ActualValue[0, 0], BoundsParameter.ActualValue[0, 1]);
    139184
    140185          // update best known solution & quality according to highest peak
     
    202247    }
    203248
    204     private void MovePeaks(IRandom uniformRandom, DoubleMatrix peaks, DoubleArray widths, DoubleArray heights, double strength) {
     249    private void MovePeaks(IRandom uniformRandom, DoubleMatrix peaks, DoubleArray widths, DoubleArray heights, double strength,
     250                           double minWidth, double maxWidth, double minHeight, double maxHeight, double minLocation, double maxLocation) {
    205251      IRandom normalRandom = new NormalDistributedRandom(uniformRandom, 0, 1);
    206252      for (int i = 0; i < peaks.Rows; i++) {
     
    208254        for (int j = 0; j < v.Length; j++) {
    209255          peaks[i, j] += v[j];
    210         }
    211         widths[i] = widths[i] + 0.01 * normalRandom.NextDouble();
    212         heights[i] = heights[i] + 7 * normalRandom.NextDouble();
     256          if (peaks[i, j] < minLocation) peaks[i, j] = minLocation;
     257          if (peaks[i, j] > maxLocation) peaks[i, j] = maxLocation;
     258        }
     259
     260        widths[i] = NewRandomValue(normalRandom, widths[i], 1.0, minWidth, maxWidth);
     261        heights[i] = NewRandomValue(normalRandom, heights[i], 7, minHeight, maxHeight);
    213262      }
    214263    }
     
    226275      return vector;
    227276    }
     277
     278    private double NewRandomValue(IRandom normalRandom, double value, double factor, double min, double max) {
     279      double r, newValue;
     280      do {
     281        r = normalRandom.NextDouble();
     282        newValue = value + factor * r;
     283      } while ((newValue < min) || (newValue > max));
     284      return newValue;
     285    }
    228286  }
    229287}
Note: See TracChangeset for help on using the changeset viewer.