Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2457_ExpertSystem/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/RuggednessCalculator.cs @ 18242

Last change on this file since 18242 was 16096, checked in by abeham, 6 years ago

#2457:

  • Changed calculation of correlation length (using limit introduced Hordijk 1996)
  • Changed RuggednessCalculator (no more a HL item)
  • Added additional, information-analysis-based features for directed walks
  • Added generic DirectedWalk algorithm (as described in thesis)
  • Made OneSizeInstanceProvider parametrizable
  • Adapted program for analyzing problem instance reidentification
File size: 2.8 KB
RevLine 
[13583]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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;
[7128]23using System.Collections.Generic;
24
[13583]25namespace HeuristicLab.Analysis.FitnessLandscape {
[16096]26  public static class RuggednessCalculator {
27    /// <summary>
28    /// Calculates statistical correlation length as defined by Hordijk, W., 1996. A measure of landscapes. Evolutionary computation, 4(4), pp.335-360.
29    /// </summary>
30    /// <param name="qualities">The quality trail observed.</param>
31    /// <param name="acf">The autocorrelation values for each step s, including 0 => acf[0] = 1.</param>
32    /// <param name="limit">The statistical limit, correlation length will be the last step before acf falls within this limit. If omitted it is calculated as 2 / sqrt(qualities.Length).</param>
33    /// <returns>The statistical correlation length</returns>
34    public static int CalculateCorrelationLength(double[] qualities, out double[] acf, double? limit = null) {
35      if (!limit.HasValue) limit = 2.0 / Math.Sqrt(qualities.Length);
[7128]36      double[] correlations = new double[qualities.Length];
37      alglib.corr.corrr1dcircular(qualities, qualities.Length, qualities, qualities.Length, ref correlations);
38      double mean = 0;
39      double variance = 0;
40      double skewness = 0;
41      double kurtosis = 0;
42      alglib.basestat.samplemoments(qualities, qualities.Length, ref mean, ref variance, ref skewness, ref kurtosis);
43      List<double> autocorrelation = new List<double>() { 1.0 };
[13583]44      int correlationLength = -1, counter = 1;
45      for (; counter < qualities.Length / 2; counter++) {
46        double value = correlations[counter] / qualities.Length - mean * mean;
[7128]47        if (variance > 0)
[13583]48          value = Math.Max(Math.Min(value / variance, 1.0), -1.0);
[7128]49        else
50          value = 1;
51        autocorrelation.Add(value);
[16096]52        if (Math.Abs(value) < limit && correlationLength < 0) correlationLength = counter;
[7128]53      }
54      acf = autocorrelation.ToArray();
[13583]55      return correlationLength - 1;
[7128]56    }
57  }
58}
Note: See TracBrowser for help on using the repository browser.