Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2457_ExpertSystem/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/InformationAnalyzer.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: 9.2 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.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
33  [StorableClass]
34  public class InformationAnalyzer : 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 ValueLookupParameter<IntValue> NQuantilesParameter {
47      get { return (ValueLookupParameter<IntValue>)Parameters["NQuantiles"]; }
48    }
49    public ValueLookupParameter<IntValue> ShapeSizeParameter {
50      get { return (ValueLookupParameter<IntValue>)Parameters["ShapeSize"]; }
51    }
52    public LookupParameter<DoubleValue> InformationContentParameter {
53      get { return (LookupParameter<DoubleValue>)Parameters["InformationContent"]; }
54    }
55    public LookupParameter<DoubleValue> PartialInformationContentParameter {
56      get { return (LookupParameter<DoubleValue>)Parameters["PartialInformationContent"]; }
57    }
58    public LookupParameter<DoubleValue> DensityBasinInformationParameter {
59      get { return (LookupParameter<DoubleValue>)Parameters["DensityBasinInformation"]; }
60    }
61    public LookupParameter<DoubleValue> TotalEntropyParameter {
62      get { return (LookupParameter<DoubleValue>)Parameters["TotalEntropy"]; }
63    }
64    public LookupParameter<DoubleValue> InformationStabilityParameter {
65      get { return (LookupParameter<DoubleValue>)Parameters["InformationStability"]; }
66    }
67    public LookupParameter<DoubleValue> RegularityParameter {
68      get { return (LookupParameter<DoubleValue>)Parameters["Regularity"]; }
69    }
70    public LookupParameter<DoubleValue> DiversityParameter {
71      get { return (LookupParameter<DoubleValue>)Parameters["Diversity"]; }
72    }
73    public LookupParameter<DoubleValue> PeakInformationContentParameter {
74      get { return (LookupParameter<DoubleValue>)Parameters["PeakInformationContent"]; }
75    }
76    public LookupParameter<DoubleValue> PeakDensityBasinInformationParameter {
77      get { return (LookupParameter<DoubleValue>)Parameters["PeakDensityBasinInformation"]; }
78    }
79    public ILookupParameter<DataTable> InformationAnalysisParameter {
80      get { return (ILookupParameter<DataTable>)Parameters["InformationAnalysis"]; }
81    }
82    #endregion
83
84    [StorableConstructor]
85    protected InformationAnalyzer(bool deserializing) : base(deserializing) { }
86    protected InformationAnalyzer(InformationAnalyzer original, Cloner cloner) : base(original, cloner) { }
87
88    public InformationAnalyzer() {
89      Parameters.Add(new LookupParameter<DataTable>("Quality Trail", "The qualities of the solutions"));
90      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection of all results of this algorithm"));
91
92      Parameters.Add(new ValueLookupParameter<IntValue>("NQuantiles", "The number of delta quantiles to display", new IntValue(20)));
93      Parameters.Add(new ValueLookupParameter<IntValue>("ShapeSize", "The number of slopes to consider as shapes.", new IntValue(2)));
94
95      Parameters.Add(new LookupParameter<DoubleValue>("InformationContent", "The information content H(0) at eps = 0"));
96      Parameters.Add(new LookupParameter<DoubleValue>("PartialInformationContent", "Partial information content M(0) at eps = 0"));
97      Parameters.Add(new LookupParameter<DoubleValue>("DensityBasinInformation", "Density Basin Information h(0) at eps = 0"));
98      Parameters.Add(new LookupParameter<DoubleValue>("TotalEntropy", "The overall disorder in the trajectory"));
99      Parameters.Add(new LookupParameter<DoubleValue>("InformationStability", "Information Stability Value"));
100      Parameters.Add(new LookupParameter<DoubleValue>("Regularity", "The number of different quality differences"));
101      Parameters.Add(new LookupParameter<DoubleValue>("Diversity", "The number of different quality values"));
102      Parameters.Add(new LookupParameter<DoubleValue>("PeakInformationContent", "Maximum information content at any quality delta."));
103      Parameters.Add(new LookupParameter<DoubleValue>("PeakDensityBasinInformation", "Maximum density basin information at any quality delta."));
104
105      Parameters.Add(new LookupParameter<DataTable>("InformationAnalysis", "Graphical analysis of information theoretic features."));
106    }
107
108    public override IDeepCloneable Clone(Cloner cloner) {
109      return new InformationAnalyzer(this, cloner);
110    }
111
112    public override IOperation Apply() {
113      var qualityTrail = QualityTrailParameter.ActualValue;
114      if (qualityTrail == null || qualityTrail.Rows.Count == 0) return base.Apply();
115
116      var qualities = QualityTrailParameter.ActualValue.Rows.First().Values.ToList();
117      if (qualities.Count <= 2) return base.Apply();
118
119      var nQuantiles = NQuantilesParameter.ActualValue.Value;
120      var shapeSize = ShapeSizeParameter.ActualValue.Value;
121      var results = ResultsParameter.ActualValue;
122
123      var analysis = new InformationAnalysis(qualities, nQuantiles, shapeSize);
124      var ic = new DoubleValue(analysis.InformationContent.FirstOrDefault());
125      InformationContentParameter.ActualValue = ic;
126      results.AddOrUpdateResult(InformationContentParameter.Name, ic);
127      var pic = new DoubleValue(analysis.PartialInformationContent.FirstOrDefault());
128      PartialInformationContentParameter.ActualValue = pic;
129      results.AddOrUpdateResult(PartialInformationContentParameter.Name, pic);
130      var dbi = new DoubleValue(analysis.DensityBasinInformation.FirstOrDefault());
131      DensityBasinInformationParameter.ActualValue = dbi;
132      results.AddOrUpdateResult(DensityBasinInformationParameter.Name, dbi);
133      var @is = new DoubleValue(analysis.InformationStability);
134      InformationStabilityParameter.ActualValue = @is;
135      results.AddOrUpdateResult(InformationStabilityParameter.Name, @is);
136      var regularity = new DoubleValue(1.0 * analysis.Regularity / qualities.Count);
137      RegularityParameter.ActualValue = regularity;
138      results.AddOrUpdateResult(RegularityParameter.Name, regularity);
139      var diversity = new DoubleValue(1.0 * analysis.Diversity / qualities.Count);
140      DiversityParameter.ActualValue = diversity;
141      results.AddOrUpdateResult(DiversityParameter.Name, diversity);
142      var totalEntropy = new DoubleValue(analysis.TotalEntropy.FirstOrDefault());
143      TotalEntropyParameter.ActualValue = totalEntropy;
144      results.AddOrUpdateResult(TotalEntropyParameter.Name, totalEntropy);
145      var peakIc = new DoubleValue(analysis.PeakInformationContent.Value);
146      PeakInformationContentParameter.ActualValue = peakIc;
147      results.AddOrUpdateResult(PeakInformationContentParameter.Name, peakIc);
148      var peakDbi = new DoubleValue(analysis.PeakDensityBasinInformation.Value);
149      PeakDensityBasinInformationParameter.ActualValue = peakDbi;
150      results.AddOrUpdateResult(PeakDensityBasinInformationParameter.Name, peakDbi);
151
152      var itable = GetInformationTable(analysis);
153      results.AddOrUpdateResult(InformationAnalysisParameter.Name, itable);
154      return base.Apply();
155    }
156
157    private static DataTable GetInformationTable(InformationAnalysis analysis) {
158      var dt = new DataTable("Information Analysis");
159      var ic = new DataRow("Information Content");
160      var pic = new DataRow("Partial Information Content");
161      var dbi = new DataRow("Density Basin Information");
162      var te = new DataRow("Total Entropy");
163      var e = new DataRow("Epsilon");
164      e.VisualProperties.SecondYAxis = true;
165      ic.Values.AddRange(analysis.InformationContent);
166      pic.Values.AddRange(analysis.PartialInformationContent);
167      dbi.Values.AddRange(analysis.DensityBasinInformation);
168      te.Values.AddRange(analysis.TotalEntropy);
169      e.Values.AddRange(analysis.QualityDelta);
170      dt.Rows.Add(ic);
171      dt.Rows.Add(pic);
172      dt.Rows.Add(dbi);
173      dt.Rows.Add(te);
174      dt.Rows.Add(e);
175      return dt;
176    }
177  }
178}
Note: See TracBrowser for help on using the repository browser.