Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Evaluators/SphereEvaluator.cs @ 3315

Last change on this file since 3315 was 3315, checked in by abeham, 14 years ago

Documented some of the test functions with literature references.
Renamed Griewangk function as it is actually called Griewank function.
Schwefel is hard to find, used self-citation as Potter and DeJong's description from 1994 seems wrong
Levy is almost impossible to find and defined only for 2 variables, the implementation looks fishy (there was also a bug)
Booth, and Matyas are also just from a single website
Still missing is Zakharov and SumSquares
#934

File size: 5.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Encodings.RealVectorEncoding;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HeuristicLab.Parameters;
28
29namespace HeuristicLab.Problems.TestFunctions {
30  /// <summary>
31  /// The sphere function is a unimodal function that has its optimum at the origin.
32  /// It is implemented as described in Beyer, H.-G. and Schwefel, H.-P. 2002. Evolution Strategies - A Comprehensive Introduction Natural Computing, 1, pp. 3-52.
33  /// </summary>
34  [Item("SphereEvaluator", "Evaluates the Sphere function y = C * ||X||^Alpha on a given point. The optimum of this function is 0 at the origin. It is implemented as described in Beyer, H.-G. and Schwefel, H.-P. 2002. Evolution Strategies - A Comprehensive Introduction Natural Computing, 1, pp. 3-52.")]
35  [StorableClass]
36  public class SphereEvaluator : SingleObjectiveTestFunctionProblemEvaluator {
37    /// <summary>
38    /// Returns false as the Sphere function is a minimization problem.
39    /// </summary>
40    public override bool Maximization {
41      get { return false; }
42    }
43    /// <summary>
44    /// Gets the optimum function value (0).
45    /// </summary>
46    public override double BestKnownQuality {
47      get { return 0; }
48    }
49    /// <summary>
50    /// Gets the lower and upper bound of the function.
51    /// </summary>
52    public override DoubleMatrix Bounds {
53      get { return new DoubleMatrix(new double[,] { { -5.12, 5.12 } }); }
54    }
55    /// <summary>
56    /// Gets the minimum problem size (1).
57    /// </summary>
58    public override int MinimumProblemSize {
59      get { return 1; }
60    }
61    /// <summary>
62    /// Gets the (theoretical) maximum problem size (2^31 - 1).
63    /// </summary>
64    public override int MaximumProblemSize {
65      get { return int.MaxValue; }
66    }
67    /// <summary>
68    /// The parameter C modifies the steepness of the objective function y = C * ||X||^Alpha. Default is C = 1.
69    /// </summary>
70    public ValueParameter<DoubleValue> CParameter {
71      get { return (ValueParameter<DoubleValue>)Parameters["C"]; }
72    }
73    /// <summary>
74    /// The parameter Alpha modifies the steepness of the objective function y = C * ||X||^Alpha. Default is Alpha = 2.
75    /// </summary>
76    public ValueParameter<DoubleValue> AlphaParameter {
77      get { return (ValueParameter<DoubleValue>)Parameters["Alpha"]; }
78    }
79    /// <summary>
80    /// The parameter C modifies the steepness of the objective function y = C * ||X||^Alpha. Default is C = 1.
81    /// </summary>
82    public DoubleValue C {
83      get { return CParameter.Value; }
84      set { if (value != null) CParameter.Value = value; }
85    }
86    /// <summary>
87    /// The parameter Alpha modifies the steepness of the objective function y = C * ||X||^Alpha. Default is Alpha = 2.
88    /// </summary>
89    public DoubleValue Alpha {
90      get { return AlphaParameter.Value; }
91      set { if (value != null) AlphaParameter.Value = value; }
92    }
93
94    /// <summary>
95    /// Initializes a new instance of the SphereEvaluator with two parameters (<c>C</c> and <c>Alpha</c>).
96    /// </summary>
97    public SphereEvaluator()
98      : base() {
99      Parameters.Add(new ValueParameter<DoubleValue>("C", "The parameter C modifies the steepness of the objective function y = C * ||X||^Alpha. Default is C = 1.", new DoubleValue(1)));
100      Parameters.Add(new ValueParameter<DoubleValue>("Alpha", "The parameter Alpha modifies the steepness of the objective function y = C * ||X||^Alpha. Default is Alpha = 2.", new DoubleValue(2)));
101    }
102    /// <summary>
103    /// Evaluates the test function for a specific <paramref name="point"/>.
104    /// </summary>
105    /// <param name="point">N-dimensional point for which the test function should be evaluated.</param>
106    /// <returns>The result value of the Sphere function at the given point.</returns>
107    public static double Apply(RealVector point, double c, double alpha) {
108      double result = 0;
109      for (int i = 0; i < point.Length; i++)
110        result += point[i] * point[i];
111      if (alpha != 2) result = Math.Pow(Math.Sqrt(result), alpha);
112      return c * result;
113    }
114
115    /// <summary>
116    /// Evaluates the test function for a specific <paramref name="point"/>.
117    /// </summary>
118    /// <remarks>Calls <see cref="Apply"/>.</remarks>
119    /// <param name="point">N-dimensional point for which the test function should be evaluated.</param>
120    /// <returns>The result value of the Sphere function at the given point.</returns>
121    protected override double EvaluateFunction(RealVector point) {
122      return Apply(point, C.Value, Alpha.Value);
123    }
124  }
125}
Note: See TracBrowser for help on using the repository browser.