Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3781


Ignore:
Timestamp:
05/11/10 19:18:32 (15 years ago)
Author:
abeham
Message:

#934

  • added BestKnownSolution to test functions
  • added unit tests
Location:
trunk/sources
Files:
17 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab 3.3.sln

    r3777 r3781  
    244244EndProject
    245245Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.DataAnalysis.Tests-3.3", "HeuristicLab.Problems.DataAnalysis\3.3\Tests\HeuristicLab.Problems.DataAnalysis.Tests-3.3.csproj", "{5A4679EF-A8F3-4647-B722-441A36B3BA6B}"
     246EndProject
     247Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HeuristicLab.Problems.TestFunctions-3.3.Tests", "HeuristicLab.Problems.TestFunctions\3.3\Tests\HeuristicLab.Problems.TestFunctions-3.3.Tests.csproj", "{71D904D9-233B-44B2-ABB2-1525691228C5}"
    246248EndProject
    247249Global
     
    13561358    {5A4679EF-A8F3-4647-B722-441A36B3BA6B}.Services|x64.ActiveCfg = Release|Any CPU
    13571359    {5A4679EF-A8F3-4647-B722-441A36B3BA6B}.Services|x86.ActiveCfg = Release|Any CPU
     1360    {71D904D9-233B-44B2-ABB2-1525691228C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
     1361    {71D904D9-233B-44B2-ABB2-1525691228C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
     1362    {71D904D9-233B-44B2-ABB2-1525691228C5}.Debug|x64.ActiveCfg = Debug|Any CPU
     1363    {71D904D9-233B-44B2-ABB2-1525691228C5}.Debug|x86.ActiveCfg = Debug|Any CPU
     1364    {71D904D9-233B-44B2-ABB2-1525691228C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
     1365    {71D904D9-233B-44B2-ABB2-1525691228C5}.Release|Any CPU.Build.0 = Release|Any CPU
     1366    {71D904D9-233B-44B2-ABB2-1525691228C5}.Release|x64.ActiveCfg = Release|Any CPU
     1367    {71D904D9-233B-44B2-ABB2-1525691228C5}.Release|x86.ActiveCfg = Release|Any CPU
     1368    {71D904D9-233B-44B2-ABB2-1525691228C5}.Services|Any CPU.ActiveCfg = Release|Any CPU
     1369    {71D904D9-233B-44B2-ABB2-1525691228C5}.Services|Any CPU.Build.0 = Release|Any CPU
     1370    {71D904D9-233B-44B2-ABB2-1525691228C5}.Services|x64.ActiveCfg = Release|Any CPU
     1371    {71D904D9-233B-44B2-ABB2-1525691228C5}.Services|x86.ActiveCfg = Release|Any CPU
    13581372  EndGlobalSection
    13591373  GlobalSection(SolutionProperties) = preSolution
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Analyzers/BestSingleObjectiveTestFunctionSolutionAnalyzer.cs

    r3661 r3781  
    5555      get { return (ILookupParameter<SingleObjectiveTestFunctionSolution>)Parameters["BestSolution"]; }
    5656    }
     57    public ILookupParameter<RealVector> BestKnownSolutionParameter {
     58      get { return (ILookupParameter<RealVector>)Parameters["BestKnownSolution"]; }
     59    }
     60    public ILookupParameter<DoubleValue> BestKnownQualityParameter {
     61      get { return (ILookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
     62    }
    5763    public IValueLookupParameter<ResultCollection> ResultsParameter {
    5864      get { return (IValueLookupParameter<ResultCollection>)Parameters["Results"]; }
     
    6773      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The qualities of the SingleObjectiveTestFunction solutions which should be visualized."));
    6874      Parameters.Add(new LookupParameter<SingleObjectiveTestFunctionSolution>("BestSolution", "The best SingleObjectiveTestFunction solution."));
     75      Parameters.Add(new LookupParameter<RealVector>("BestKnownSolution", "The best known solution."));
     76      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution."));
    6977      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "The result collection where the SingleObjectiveTestFunction solution should be stored."));
    7078      Parameters.Add(new ValueLookupParameter<ISingleObjectiveTestFunctionProblemEvaluator>("Evaluator", "The evaluator with which the solution is evaluated."));
     
    7684      ResultCollection results = ResultsParameter.ActualValue;
    7785      ISingleObjectiveTestFunctionProblemEvaluator evaluator = EvaluatorParameter.ActualValue;
     86      bool max = evaluator.Maximization;
    7887
    7988      int i = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     
    8291        solution = new SingleObjectiveTestFunctionSolution(realVectors[i], qualities[i], evaluator);
    8392        solution.Population = realVectors;
     93        double bestknownQuality = BestKnownQualityParameter.ActualValue.Value;
     94        if (max && qualities[i].Value >= bestknownQuality
     95          || !max && qualities[i].Value <= bestknownQuality) {
     96          BestKnownSolutionParameter.ActualValue = (RealVector)realVectors[i].Clone();
     97        }
     98        solution.BestKnownRealVector = BestKnownSolutionParameter.ActualValue;
    8499        BestSolutionParameter.ActualValue = solution;
    85 
    86100        results.Add(new Result("Best SingleObjectiveTestFunction Solution", solution));
    87101      } else {
    88         if (evaluator.Maximization && qualities[i].Value > solution.BestQuality.Value
    89           || !evaluator.Maximization && qualities[i].Value < solution.BestQuality.Value) {
     102        double bestknownQuality = BestKnownQualityParameter.ActualValue.Value;
     103        if (max && qualities[i].Value >= bestknownQuality
     104          || !max && qualities[i].Value <= bestknownQuality) {
     105          BestKnownSolutionParameter.ActualValue = (RealVector)realVectors[i].Clone();
     106        }
     107        if (max && qualities[i].Value > solution.BestQuality.Value
     108          || !max && qualities[i].Value < solution.BestQuality.Value) {
    90109          solution.BestRealVector = realVectors[i];
    91110          solution.BestQuality = qualities[i];
    92111        }
    93112        solution.Population = realVectors;
    94 
    95113        //results["Best SingleObjectiveTestFunction Solution"].Value = solution;
    96114      }
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Evaluators/AckleyEvaluator.cs

    r3450 r3781  
    6666    }
    6767
     68    public override RealVector GetBestKnownSolution(int dimension) {
     69      return new RealVector(dimension);
     70    }
     71
    6872    /// <summary>
    6973    /// Evaluates the Ackley function for a specific <paramref name="point"/>.
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Evaluators/BealeEvaluator.cs

    r3376 r3781  
    6666    }
    6767
     68    public override RealVector GetBestKnownSolution(int dimension) {
     69      if (dimension != 2) throw new ArgumentException(Name + ": This function is only defined for 2 dimensions.", "dimension");
     70      return new RealVector(new double[] { 3, 0.5 });
     71    }
    6872    /// <summary>
    6973    /// Evaluates the test function for a specific <paramref name="point"/>.
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Evaluators/BoothEvaluator.cs

    r3376 r3781  
    6565    }
    6666
     67    public override RealVector GetBestKnownSolution(int dimension) {
     68      if (dimension != 2) throw new ArgumentException(Name + ": This function is only defined for 2 dimensions.", "dimension");
     69      return new RealVector(new double[] { 1, 3 });
     70    }
    6771    /// <summary>
    6872    /// Evaluates the test function for a specific <paramref name="point"/>.
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Evaluators/GriewankEvaluator.cs

    r3376 r3781  
    6767    }
    6868
     69    public override RealVector GetBestKnownSolution(int dimension) {
     70      return new RealVector(dimension);
     71    }
    6972    /// <summary>
    7073    /// If dimension of the problem is less or equal than 100 the values of Math.Sqrt(i + 1) are precomputed.
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Evaluators/LevyEvaluator.cs

    r3376 r3781  
    6565    }
    6666
     67    public override RealVector GetBestKnownSolution(int dimension) {
     68      if (dimension < 2) throw new ArgumentException(Name + ": This function is not defined for 1 dimension.");
     69      RealVector result = new RealVector(dimension);
     70      for (int i = 0; i < dimension; i++) result[i] = 1;
     71      return result;
     72    }
    6773    /// <summary>
    6874    /// Evaluates the test function for a specific <paramref name="point"/>.
     
    8086
    8187      s = Math.Sin(Math.PI * z[0]);
     88      if (Math.Abs(s) < 1e-15) s = 0; // Math.Sin(Math.PI) == 0.00000000000000012246063538223773
    8289      s *= s;
    8390
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Evaluators/MatyasEvaluator.cs

    r3376 r3781  
    6565    }
    6666
     67    public override RealVector GetBestKnownSolution(int dimension) {
     68      if (dimension != 2) throw new ArgumentException(Name + ": This function is only defined for 2 dimensions.", "dimension");
     69      return new RealVector(dimension);
     70    }
    6771    /// <summary>
    6872    /// Evaluates the test function for a specific <paramref name="point"/>.
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Evaluators/RastriginEvaluator.cs

    r3376 r3781  
    8080    }
    8181
     82    public override RealVector GetBestKnownSolution(int dimension) {
     83      return new RealVector(dimension);
     84    }
     85
    8286    /// <summary>
    8387    /// Initializes a new instance of the RastriginEvaluator with one parameter (<c>A</c>).
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Evaluators/RosenbrockEvaluator.cs

    r3376 r3781  
    6969    }
    7070
     71    public override RealVector GetBestKnownSolution(int dimension) {
     72      if (dimension < 2) throw new ArgumentException(Name + ": This function is not defined for 1 dimension.");
     73      RealVector result = new RealVector(dimension);
     74      for (int i = 0; i < dimension; i++) result[i] = 1;
     75      return result;
     76    }
     77
    7178    /// <summary>
    7279    /// Evaluates the test function for a specific <paramref name="point"/>.
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Evaluators/SchwefelEvaluator.cs

    r3376 r3781  
    3131  /// The Schwefel function (sine root) is implemented as described in Affenzeller, M. and Wagner, S. 2005. Offspring Selection: A New Self-Adaptive Selection Scheme for Genetic Algorithms.  Ribeiro, B., Albrecht, R. F., Dobnikar, A., Pearson, D. W., and Steele, N. C. (eds.). Adaptive and Natural Computing Algorithms, pp. 218-221, Springer.
    3232  /// </summary>
    33   [Item("SchwefelEvaluator", "Evaluates the Schwefel function (sine root) on a given point. The optimum of this function is 0 at (420.968746453712,420.968746453712,...,420.968746453712). It is implemented as described in Affenzeller, M. and Wagner, S. 2005. Offspring Selection: A New Self-Adaptive Selection Scheme for Genetic Algorithms.  Ribeiro, B., Albrecht, R. F., Dobnikar, A., Pearson, D. W., and Steele, N. C. (eds.). Adaptive and Natural Computing Algorithms, pp. 218-221, Springer.")]
     33  [Item("SchwefelEvaluator", "Evaluates the Schwefel function (sine root) on a given point. In the given bounds [-500;500] the optimum of this function is close to 0 at (420.968746453712,420.968746453712,...,420.968746453712). It is implemented as described in Affenzeller, M. and Wagner, S. 2005. Offspring Selection: A New Self-Adaptive Selection Scheme for Genetic Algorithms.  Ribeiro, B., Albrecht, R. F., Dobnikar, A., Pearson, D. W., and Steele, N. C. (eds.). Adaptive and Natural Computing Algorithms, pp. 218-221, Springer.")]
    3434  [StorableClass]
    3535  public class SchwefelEvaluator : SingleObjectiveTestFunctionProblemEvaluator {
     
    6565    }
    6666
     67    public override RealVector GetBestKnownSolution(int dimension) {
     68      return null;
     69    }
     70
    6771    /// <summary>
    6872    /// Evaluates the test function for a specific <paramref name="point"/>.
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Evaluators/SingleObjectiveTestFunctionProblemEvaluator.cs

    r3665 r3781  
    8787      return EvaluateFunction(new RealVector(new double[] { x, y }));
    8888    }
     89    /// <summary>
     90    /// Gets the best known solution for this function.
     91    /// </summary>
     92    public abstract RealVector GetBestKnownSolution(int dimension);
    8993
    9094    /// <summary>
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Evaluators/SphereEvaluator.cs

    r3376 r3781  
    6666      get { return int.MaxValue; }
    6767    }
     68
     69    public override RealVector GetBestKnownSolution(int dimension) {
     70      return new RealVector(dimension);
     71    }
     72
    6873    /// <summary>
    6974    /// The parameter C modifies the steepness of the objective function y = C * ||X||^Alpha. Default is C = 1.
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Evaluators/SumSquaresEvaluator.cs

    r3376 r3781  
    6565    }
    6666
     67    public override RealVector GetBestKnownSolution(int dimension) {
     68      return new RealVector(dimension);
     69    }
     70
    6771    /// <summary>
    6872    /// Evaluates the test function for a specific <paramref name="point"/>.
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Evaluators/ZakharovEvaluator.cs

    r3376 r3781  
    6565    }
    6666
     67    public override RealVector GetBestKnownSolution(int dimension) {
     68      return new RealVector(dimension);
     69    }
     70
    6771    /// <summary>
    6872    /// Evaluates the test function for a specific <paramref name="point"/>.
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Interfaces/ISingleObjectiveTestFunctionProblemEvaluator.cs

    r3665 r3781  
    4040
    4141    double Evaluate2D(double x, double y);
     42    RealVector GetBestKnownSolution(int dimension);
    4243  }
    4344}
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r3751 r3781  
    8383      get { return BestKnownQualityParameter; }
    8484    }
     85    public OptionalValueParameter<RealVector> BestKnownSolutionParameter {
     86      get { return (OptionalValueParameter<RealVector>)Parameters["BestKnownSolution"]; }
     87    }
    8588    #endregion
    8689
     
    141144      Parameters.Add(new ValueParameter<ISingleObjectiveTestFunctionProblemEvaluator>("Evaluator", "The operator which should be used to evaluate test function solutions.", evaluator));
    142145      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this test function.", new DoubleValue(evaluator.BestKnownQuality)));
     146      Parameters.Add(new OptionalValueParameter<RealVector>("BestKnownSolution", "The best known solution for this test function instance."));
    143147
    144148      strategyVectorCreator = new StdDevStrategyVectorCreator();
     
    194198      if (ProblemSize.Value < 1) ProblemSize.Value = 1;
    195199      ParameterizeSolutionCreator();
     200      ParameterizeEvaluator();
    196201      strategyVectorManipulator.GeneralLearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * ProblemSize.Value));
    197202      strategyVectorManipulator.LearningRateParameter.Value = new DoubleValue(1.0 / Math.Sqrt(2 * Math.Sqrt(ProblemSize.Value)));
     203      OnReset();
    198204    }
    199205    private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
     
    219225      BestKnownQuality = new DoubleValue(Evaluator.BestKnownQuality);
    220226      Evaluator_QualityParameter_ActualNameChanged(null, EventArgs.Empty);
     227      OnReset();
    221228    }
    222229    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
     
    230237      if (Bounds.Columns != 2 || Bounds.Rows < 1)
    231238        Bounds = new DoubleMatrix(1, 2);
    232       ParameterizeOperators();
     239      ParameterizeOperators();
     240      UpdateStrategyVectorBounds();
    233241    }
    234242    private void Bounds_ItemChanged(object sender, EventArgs<int, int> e) {
     
    237245      if (e.Value2 == 1 && Bounds[e.Value, 0] >= Bounds[e.Value, 1])
    238246        Bounds[e.Value, 0] = Bounds[e.Value, 1] - 0.1;
    239       ParameterizeOperators();
     247      ParameterizeOperators();
     248      UpdateStrategyVectorBounds();
    240249    }
    241250    private void MoveGenerator_AdditiveMoveParameter_ActualNameChanged(object sender, EventArgs e) {
     
    263272    }
    264273    private void strategyVectorCreator_BoundsParameter_ValueChanged(object sender, EventArgs e) {
    265       strategyVectorManipulator.BoundsParameter.Value = strategyVectorCreator.BoundsParameter.Value;
     274      strategyVectorManipulator.BoundsParameter.Value = (DoubleMatrix)strategyVectorCreator.BoundsParameter.Value.Clone();
    266275    }
    267276    private void strategyVectorCreator_StrategyParameterParameter_ActualNameChanged(object sender, EventArgs e) {
     
    344353    private void ParameterizeEvaluator() {
    345354      Evaluator.PointParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
     355      BestKnownSolutionParameter.Value = Evaluator.GetBestKnownSolution(ProblemSize.Value);
    346356    }
    347357    private void ParameterizeOperators() {
     
    371381      }
    372382    }
     383    private void UpdateStrategyVectorBounds() {
     384      DoubleMatrix strategyBounds = (DoubleMatrix)Bounds.Clone();
     385      for (int i = 0; i < strategyBounds.Rows; i++)
     386        if (strategyBounds[i, 0] < 0) strategyBounds[i, 0] = 0;
     387      strategyVectorCreator.BoundsParameter.Value = strategyBounds;
     388    }
    373389    #endregion
    374390  }
Note: See TracChangeset for help on using the changeset viewer.