Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2457_ExpertSystem/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/RuggednessAnalyzer.cs @ 16096

Last change on this file since 16096 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: 4.3 KB
Line 
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.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Analysis.FitnessLandscape {
32  [Item("Ruggedness Analyzer", "Analyzes autocorrelation for one mutation step and correlation length. Correlation length is calculated according to the statistical correlation length defined by Hordijk, W., 1996. A measure of landscapes. Evolutionary computation, 4(4), pp.335-360.")]
33  [StorableClass]
34  public class RuggednessAnalyzer : SingleSuccessorOperator, IQualityTrailAnalyzer {
35    public bool EnabledByDefault {
36      get { return false; }
37    }
38
39    #region Parameters
40    public LookupParameter<DataTable> QualityTrailParameter {
41      get { return (LookupParameter<DataTable>)Parameters["Quality Trail"]; }
42    }
43    public LookupParameter<ResultCollection> ResultsParameter {
44      get { return (LookupParameter<ResultCollection>)Parameters["Results"]; }
45    }
46    public LookupParameter<DoubleValue> AutoCorrelation1Parameter {
47      get { return (LookupParameter<DoubleValue>)Parameters["AutoCorrelation1"]; }
48    }
49    public LookupParameter<IntValue> CorrelationLengthParameter {
50      get { return (LookupParameter<IntValue>)Parameters["CorrelationLength"]; }
51    }
52    public ValueLookupParameter<DoubleValue> LimitParameter {
53      get { return (ValueLookupParameter<DoubleValue>)Parameters["Limit"]; }
54    }
55    #endregion
56
57    [StorableConstructor]
58    protected RuggednessAnalyzer(bool deserializing) : base(deserializing) { }
59    protected RuggednessAnalyzer(RuggednessAnalyzer original, Cloner cloner) : base(original, cloner) { }
60    public RuggednessAnalyzer() {
61      Parameters.Add(new LookupParameter<DataTable>("Quality Trail", "The quality of the solution"));
62      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection of all results of this algorithm"));
63      Parameters.Add(new LookupParameter<DoubleValue>("AutoCorrelation1", "Autocorrelation for one mutation step."));
64      Parameters.Add(new LookupParameter<IntValue>("CorrelationLength", "The correlation length."));
65      Parameters.Add(new ValueLookupParameter<DoubleValue>("Limit", "The limit for the statistical correlation length, if left empty 2 / sqrt(n), where n = length of walk will be used, as defined by Hordijk 1996."));
66    }
67
68    public override IDeepCloneable Clone(Cloner cloner) {
69      return new RuggednessAnalyzer(this, cloner);
70    }
71
72    public override IOperation Apply() {
73      var qualityTrail = QualityTrailParameter.ActualValue;
74      if (qualityTrail == null || qualityTrail.Rows.Count <= 0) return base.Apply();
75      var results = ResultsParameter.ActualValue;
76      var limit = LimitParameter.ActualValue?.Value;
77      double[] autocorrelationValues;
78      var correlationLength = RuggednessCalculator.CalculateCorrelationLength(qualityTrail.Rows.First().Values.ToArray(), out autocorrelationValues, limit);
79      var cl = new IntValue(correlationLength);
80      CorrelationLengthParameter.ActualValue = cl;
81      results.AddOrUpdateResult(CorrelationLengthParameter.Name, cl);
82      var ac1 = new DoubleValue(autocorrelationValues.Length > 1 ? autocorrelationValues[1] : 0.0);
83      AutoCorrelation1Parameter.ActualValue = ac1;
84      results.AddOrUpdateResult(AutoCorrelation1Parameter.Name, ac1);
85      return base.Apply();
86    }
87  }
88}
Note: See TracBrowser for help on using the repository browser.