Changeset 16608


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

#2989: Worked on Moving Peaks Benchmark

Location:
branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3
Files:
2 edited

Legend:

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

    r16607 r16608  
    5959      get { return (ValueParameter<IntValue>)Parameters["Peaks"]; }
    6060    }
     61    public ValueParameter<DoubleMatrix> InitialPeakLocationsParameter {
     62      get { return (ValueParameter<DoubleMatrix>)Parameters["InitialPeakLocations"]; }
     63    }
    6164    public ValueParameter<DoubleMatrix> PeakLocationsParameter {
    6265      get { return (ValueParameter<DoubleMatrix>)Parameters["PeakLocations"]; }
    6366    }
     67    public ValueParameter<DoubleArray> InitialPeakWidthsParameter {
     68      get { return (ValueParameter<DoubleArray>)Parameters["InitialPeakWidths"]; }
     69    }
    6470    public ValueParameter<DoubleArray> PeakWidthsParameter {
    6571      get { return (ValueParameter<DoubleArray>)Parameters["PeakWidths"]; }
     72    }
     73    public ValueParameter<DoubleArray> InitialPeakHeightsParameter {
     74      get { return (ValueParameter<DoubleArray>)Parameters["InitialPeakHeights"]; }
    6675    }
    6776    public ValueParameter<DoubleArray> PeakHeightsParameter {
     
    8695      set { PeaksParameter.Value = value; }
    8796    }
     97    public DoubleMatrix InitialPeakLocations {
     98      get { return InitialPeakLocationsParameter.Value; }
     99      set { InitialPeakLocationsParameter.Value = value; }
     100    }
    88101    public DoubleMatrix PeakLocations {
    89102      get { return PeakLocationsParameter.Value; }
    90103      set { PeakLocationsParameter.Value = value; }
    91104    }
     105    public DoubleArray InitialPeakWidths {
     106      get { return InitialPeakWidthsParameter.Value; }
     107      set { InitialPeakWidthsParameter.Value = value; }
     108    }
    92109    public DoubleArray PeakWidths {
    93110      get { return PeakWidthsParameter.Value; }
    94111      set { PeakWidthsParameter.Value = value; }
     112    }
     113    public DoubleArray InitialPeakHeights {
     114      get { return InitialPeakHeightsParameter.Value; }
     115      set { InitialPeakHeightsParameter.Value = value; }
    95116    }
    96117    public DoubleArray PeakHeights {
     
    114135    public MovingPeaksBenchmarkProblem()
    115136      : base(new MovingPeaksBenchmarkProblemEvaluator(), new UniformRandomRealVectorCreator()) {
    116       Parameters.Add(new ValueParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension.", null));
     137      var defaultBounds = new double[,] {
     138        { 0.0, 100.0 }
     139      };
     140      var defaultPeaks = new double[,] {
     141        { 08.0, 64.0, 67.0, 55.0, 04.0 },
     142        { 50.0, 13.0, 76.0, 15.0, 07.0 },
     143        { 09.0, 19.0, 27.0, 67.0, 24.0 },
     144        { 66.0, 87.0, 65.0, 19.0, 43.0 },
     145        { 76.0, 32.0, 43.0, 54.0, 65.0 }
     146      };
     147      var defaultWidths = new double[] { 0.1, 0.1, 0.1, 0.1, 0.1 };
     148      var defaultHeights = new double[] { 50.0, 50.0, 50.0, 50.0, 50.0 };
     149
     150      Parameters.Add(new ValueParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension.", new DoubleMatrix(defaultBounds)));
    117151      Parameters.Add(new ValueParameter<IntValue>("ProblemSize", "The dimension of the problem.", new IntValue(5)));
    118152      Parameters.Add(new ValueParameter<IntValue>("Peaks", "The number of peaks.", new IntValue(5)));
    119       Parameters.Add(new ValueParameter<DoubleMatrix>("PeakLocations", "", null ));
    120       Parameters.Add(new ValueParameter<DoubleArray>("PeakWidths", "", new DoubleArray(new double[] { 0, 0, 0, 0, 0 })));
    121       Parameters.Add(new ValueParameter<DoubleArray>("PeakHeights", "", new DoubleArray(new double[] { 0, 0, 0, 0, 0 })));
    122 
    123       Parameters.Add(new OptionalValueParameter<RealVector>("BestKnownSolution", "The best known solution for this test function instance."));
     153      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      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      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."));
    124161
    125162      Maximization.Value = true;
     
    144181    public override IDeepCloneable Clone(Cloner cloner) {
    145182      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;
    146190    }
    147191
     
    156200    protected override void OnEvaluatorChanged() {
    157201      base.OnEvaluatorChanged();
    158       bool problemSizeChange = ProblemSize.Value < Evaluator.MinimumProblemSize
    159         || ProblemSize.Value > Evaluator.MaximumProblemSize;
    160       if (problemSizeChange) {
    161         ProblemSize.Value = Math.Max(Evaluator.MinimumProblemSize, Math.Min(ProblemSize.Value, Evaluator.MaximumProblemSize));
    162       } else {
    163         ParameterizeEvaluator();
    164       }
     202      ParameterizeEvaluator();
    165203      UpdateMoveEvaluators();
    166204      ParameterizeAnalyzers();
    167       Maximization.Value = Evaluator.Maximization;
    168       BoundsParameter.Value = Evaluator.Bounds;
    169       BestKnownQuality = new DoubleValue(Evaluator.BestKnownQuality);
    170205      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    171206      Evaluator_QualityParameter_ActualNameChanged(null, EventArgs.Empty);
     
    180215      ParameterizeSolutionCreator();
    181216      ParameterizeEvaluator();
    182       strategyVectorManipulator.GeneralLearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * ProblemSize.Value));
    183       strategyVectorManipulator.LearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * Math.Sqrt(ProblemSize.Value)));
     217      //strategyVectorManipulator.GeneralLearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * ProblemSize.Value));
     218      //strategyVectorManipulator.LearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * Math.Sqrt(ProblemSize.Value)));
    184219      OnReset();
    185220    }
     
    233268    //  }
    234269    //}
    235     private void strategyVectorCreator_BoundsParameter_ValueChanged(object sender, EventArgs e) {
    236       strategyVectorManipulator.BoundsParameter.Value = (DoubleMatrix)strategyVectorCreator.BoundsParameter.Value.Clone();
    237     }
    238     private void strategyVectorCreator_StrategyParameterParameter_ActualNameChanged(object sender, EventArgs e) {
    239       string name = strategyVectorCreator.StrategyParameterParameter.ActualName;
    240       strategyVectorCrossover.ParentsParameter.ActualName = name;
    241       strategyVectorCrossover.StrategyParameterParameter.ActualName = name;
    242       strategyVectorManipulator.StrategyParameterParameter.ActualName = name;
    243     }
     270    //private void strategyVectorCreator_BoundsParameter_ValueChanged(object sender, EventArgs e) {
     271    //  strategyVectorManipulator.BoundsParameter.Value = (DoubleMatrix)strategyVectorCreator.BoundsParameter.Value.Clone();
     272    //}
     273    //private void strategyVectorCreator_StrategyParameterParameter_ActualNameChanged(object sender, EventArgs e) {
     274    //  string name = strategyVectorCreator.StrategyParameterParameter.ActualName;
     275    //  strategyVectorCrossover.ParentsParameter.ActualName = name;
     276    //  strategyVectorCrossover.StrategyParameterParameter.ActualName = name;
     277    //  strategyVectorManipulator.StrategyParameterParameter.ActualName = name;
     278    //}
    244279    #endregion
    245280
     
    247282    [StorableHook(HookType.AfterDeserialization)]
    248283    private void AfterDeserialization() {
    249       // BackwardsCompatibility3.3
    250       #region Backwards compatible code (remove with 3.4)
    251       if (Operators.Count == 0) InitializeOperators();
    252       #endregion
    253284      RegisterEventHandlers();
    254285    }
     
    262293      SolutionCreator.RealVectorParameter.ActualNameChanged += new EventHandler(SolutionCreator_RealVectorParameter_ActualNameChanged);
    263294      Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    264       strategyVectorCreator.BoundsParameter.ValueChanged += new EventHandler(strategyVectorCreator_BoundsParameter_ValueChanged);
    265       strategyVectorCreator.StrategyParameterParameter.ActualNameChanged += new EventHandler(strategyVectorCreator_StrategyParameterParameter_ActualNameChanged);
     295      //strategyVectorCreator.BoundsParameter.ValueChanged += new EventHandler(strategyVectorCreator_BoundsParameter_ValueChanged);
     296      //strategyVectorCreator.StrategyParameterParameter.ActualNameChanged += new EventHandler(strategyVectorCreator_StrategyParameterParameter_ActualNameChanged);
    266297    }
    267298    private void ParameterizeAnalyzers() {
     
    287318      //Operators.Add(new BestSingleObjectiveTestFunctionSolutionAnalyzer());
    288319      //Operators.Add(new PopulationSimilarityAnalyzer(Operators.OfType<ISolutionSimilarityCalculator>()));
    289       //ParameterizeAnalyzers();
    290       //Operators.AddRange(ApplicationManager.Manager.GetInstances<IRealVectorOperator>().Cast<IOperator>());
     320      ParameterizeAnalyzers();
     321      Operators.AddRange(ApplicationManager.Manager.GetInstances<IRealVectorOperator>().Cast<IOperator>());
    291322      //Operators.Add(strategyVectorCreator);
    292323      //Operators.Add(strategyVectorCrossover);
    293324      //Operators.Add(strategyVectorManipulator);
    294       //UpdateMoveEvaluators();
    295       //ParameterizeOperators();
    296       //InitializeMoveGenerators();
     325      UpdateMoveEvaluators();
     326      ParameterizeOperators();
     327      InitializeMoveGenerators();
    297328    }
    298329    private void InitializeMoveGenerators() {
     
    325356      //    #endregion
    326357      //  }
    327       //ParameterizeOperators();
    328       //OnOperatorsChanged();
     358      ParameterizeOperators();
     359      OnOperatorsChanged();
    329360    }
    330361    private void ParameterizeSolutionCreator() {
     
    337368      Evaluator.PointParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
    338369      Evaluator.PointParameter.Hidden = true;
    339       try {
    340         BestKnownSolutionParameter.Value = Evaluator.GetBestKnownSolution(ProblemSize.Value);
    341       }
    342       catch (ArgumentException e) {
    343         ErrorHandling.ShowErrorDialog(e);
    344         ProblemSize.Value = Evaluator.MinimumProblemSize;
    345       }
     370      //try {
     371      //  BestKnownSolutionParameter.Value = Evaluator.GetBestKnownSolution(ProblemSize.Value);
     372      //}
     373      //catch (ArgumentException e) {
     374      //  ErrorHandling.ShowErrorDialog(e);
     375      //  ProblemSize.Value = Evaluator.MinimumProblemSize;
     376      //}
    346377    }
    347378    private void ParameterizeOperators() {
     
    412443    }
    413444    private void UpdateStrategyVectorBounds() {
    414       var strategyBounds = (DoubleMatrix)Bounds.Clone();
    415       for (int i = 0; i < strategyBounds.Rows; i++) {
    416         if (strategyBounds[i, 0] < 0) strategyBounds[i, 0] = 0;
    417         strategyBounds[i, 1] = 0.1 * (Bounds[i, 1] - Bounds[i, 0]);
    418       }
    419       strategyVectorCreator.BoundsParameter.Value = strategyBounds;
     445      //var strategyBounds = (DoubleMatrix)Bounds.Clone();
     446      //for (int i = 0; i < strategyBounds.Rows; i++) {
     447      //  if (strategyBounds[i, 0] < 0) strategyBounds[i, 0] = 0;
     448      //  strategyBounds[i, 1] = 0.1 * (Bounds[i, 1] - Bounds[i, 0]);
     449      //}
     450      //strategyVectorCreator.BoundsParameter.Value = strategyBounds;
    420451    }
    421452    #endregion
  • branches/2989_MovingPeaksBenchmark/HeuristicLab.Problems.MovingPeaksBenchmark/3.3/MovingPeaksBenchmarkProblemEvaluator.cs

    r16607 r16608  
    7474
    7575    public double Apply(DoubleMatrix peaks, DoubleArray widths, DoubleArray heights, RealVector point) {
    76       return 0;
     76      heights[0] *= 1.01;
     77
     78      double max = 0;
     79      double val = 0;
     80
     81      for (int i = 0; i < widths.Length; i++) {
     82        val = 0;
     83        for (int j = 0; j < point.Length; j++) {
     84          val += (point[j] - peaks[i, j]) * (point[j] - peaks[i, j]);
     85        }
     86        val = heights[i] / (1 + widths[i] * val);
     87        if (val > max) max = val;
     88      }
     89      return max;
    7790    }
    7891  }
Note: See TracChangeset for help on using the changeset viewer.