Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/RuggednessAnalyzer.cs @ 14871

Last change on this file since 14871 was 13583, checked in by abeham, 9 years ago

#2457:

  • Added stripped-down version of FLA branch
  • Added appropriate calculators
  • Fixed detecting maximization in RLD view
File size: 4.0 KB
RevLine 
[7128]1#region License Information
2/* HeuristicLab
[13583]3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[7128]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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Operators;
[13583]26using HeuristicLab.Optimization;
[7128]27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[13583]29using System.Linq;
[7128]30
[13583]31namespace HeuristicLab.Analysis.FitnessLandscape {
32  [Item("Ruggedness Analyzer", "Analyzes autocorrelation for one mutation step and correlation length.")]
[7128]33  [StorableClass]
[13583]34  public class RuggednessAnalyzer : SingleSuccessorOperator, IQualityTrailAnalyzer {
[7176]35    public bool EnabledByDefault {
36      get { return false; }
37    }
[7128]38
39    #region Parameters
40    public LookupParameter<DataTable> QualityTrailParameter {
41      get { return (LookupParameter<DataTable>)Parameters["Quality Trail"]; }
42    }
[13583]43    public LookupParameter<ResultCollection> ResultsParameter {
44      get { return (LookupParameter<ResultCollection>)Parameters["Results"]; }
[7128]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    #endregion
53
54    [StorableConstructor]
55    protected RuggednessAnalyzer(bool deserializing) : base(deserializing) { }
56    protected RuggednessAnalyzer(RuggednessAnalyzer original, Cloner cloner) : base(original, cloner) { }
57    public RuggednessAnalyzer() {
58      Parameters.Add(new LookupParameter<DataTable>("Quality Trail", "The quality of the solution"));
[13583]59      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection of all results of this algorithm"));
[7128]60      Parameters.Add(new LookupParameter<DoubleValue>("AutoCorrelation1", "Autocorrelation for one mutation step."));
61      Parameters.Add(new LookupParameter<IntValue>("CorrelationLength", "The correlation length."));
62    }
63
64    public override IDeepCloneable Clone(Cloner cloner) {
65      return new RuggednessAnalyzer(this, cloner);
66    }
67
68    public override IOperation Apply() {
[13583]69      var qualityTrail = QualityTrailParameter.ActualValue;
70      if (qualityTrail == null || qualityTrail.Rows.Count <= 0) return base.Apply();
71      var results = ResultsParameter.ActualValue;
72      double[] autocorrelationValues;
73      var correlationLength = RuggednessCalculator.CalculateCorrelationLength(qualityTrail.Rows.First().Values.ToArray(), out autocorrelationValues);
74      var cl = new IntValue(correlationLength);
75      CorrelationLengthParameter.ActualValue = cl;
76      AddOrUpdateResult(results, CorrelationLengthParameter.Name, cl);
77      var ac1 = new DoubleValue(autocorrelationValues.Length > 1 ? autocorrelationValues[1] : 0.0);
78      AutoCorrelation1Parameter.ActualValue = ac1;
79      AddOrUpdateResult(results, AutoCorrelation1Parameter.Name, ac1);
[7128]80      return base.Apply();
81    }
82
[13583]83    private static void AddOrUpdateResult(ResultCollection results, string name, IItem item, bool clone = false) {
84      IResult r;
85      if (!results.TryGetValue(name, out r)) {
86        results.Add(new Result(name, clone ? (IItem)item.Clone() : item));
87      } else r.Value = clone ? (IItem)item.Clone() : item;
[7128]88    }
89  }
90}
Note: See TracBrowser for help on using the repository browser.