Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2457_ExpertSystem/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/InformationAnalyzer.cs @ 16137

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

#2457:

  • Restructured FLA plugin (moved files between folders, added common base classes)
  • Fixed AC1 in QAPDirectedWalk (ouch!)
  • Changed PartialInformationContent to be in range [0;1]
  • Added unit test for information analysis
  • Refactored information analysis and discard ability to use more symbols than 2 as shapes
File size: 8.9 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
94      Parameters.Add(new LookupParameter<DoubleValue>("InformationContent", "The information content H(0) at eps = 0"));
95      Parameters.Add(new LookupParameter<DoubleValue>("PartialInformationContent", "Partial information content M(0) at eps = 0"));
96      Parameters.Add(new LookupParameter<DoubleValue>("DensityBasinInformation", "Density Basin Information h(0) at eps = 0"));
97      Parameters.Add(new LookupParameter<DoubleValue>("TotalEntropy", "The overall disorder in the trajectory"));
98      Parameters.Add(new LookupParameter<DoubleValue>("InformationStability", "Information Stability Value"));
99      Parameters.Add(new LookupParameter<DoubleValue>("Regularity", "The number of different quality differences"));
100      Parameters.Add(new LookupParameter<DoubleValue>("Diversity", "The number of different quality values"));
101      Parameters.Add(new LookupParameter<DoubleValue>("PeakInformationContent", "Maximum information content at any quality delta."));
102      Parameters.Add(new LookupParameter<DoubleValue>("PeakDensityBasinInformation", "Maximum density basin information at any quality delta."));
103
104      Parameters.Add(new LookupParameter<DataTable>("InformationAnalysis", "Graphical analysis of information theoretic features."));
105    }
106
107    public override IDeepCloneable Clone(Cloner cloner) {
108      return new InformationAnalyzer(this, cloner);
109    }
110
111    public override IOperation Apply() {
112      var qualityTrail = QualityTrailParameter.ActualValue;
113      if (qualityTrail == null || qualityTrail.Rows.Count == 0) return base.Apply();
114
115      var qualities = QualityTrailParameter.ActualValue.Rows.First().Values.ToList();
116      if (qualities.Count <= 2) return base.Apply();
117
118      var nQuantiles = NQuantilesParameter.ActualValue.Value;
119      var results = ResultsParameter.ActualValue;
120
121      var analysis = new InformationAnalysis(qualities, nQuantiles);
122      var ic = new DoubleValue(analysis.InformationContent.FirstOrDefault());
123      InformationContentParameter.ActualValue = ic;
124      results.AddOrUpdateResult(InformationContentParameter.Name, ic);
125      var pic = new DoubleValue(analysis.PartialInformationContent.FirstOrDefault());
126      PartialInformationContentParameter.ActualValue = pic;
127      results.AddOrUpdateResult(PartialInformationContentParameter.Name, pic);
128      var dbi = new DoubleValue(analysis.DensityBasinInformation.FirstOrDefault());
129      DensityBasinInformationParameter.ActualValue = dbi;
130      results.AddOrUpdateResult(DensityBasinInformationParameter.Name, dbi);
131      var @is = new DoubleValue(analysis.InformationStability);
132      InformationStabilityParameter.ActualValue = @is;
133      results.AddOrUpdateResult(InformationStabilityParameter.Name, @is);
134      var regularity = new DoubleValue(1.0 * analysis.Regularity / qualities.Count);
135      RegularityParameter.ActualValue = regularity;
136      results.AddOrUpdateResult(RegularityParameter.Name, regularity);
137      var diversity = new DoubleValue(1.0 * analysis.Diversity / qualities.Count);
138      DiversityParameter.ActualValue = diversity;
139      results.AddOrUpdateResult(DiversityParameter.Name, diversity);
140      var totalEntropy = new DoubleValue(analysis.TotalEntropy.FirstOrDefault());
141      TotalEntropyParameter.ActualValue = totalEntropy;
142      results.AddOrUpdateResult(TotalEntropyParameter.Name, totalEntropy);
143      var peakIc = new DoubleValue(analysis.PeakInformationContent.Value);
144      PeakInformationContentParameter.ActualValue = peakIc;
145      results.AddOrUpdateResult(PeakInformationContentParameter.Name, peakIc);
146      var peakDbi = new DoubleValue(analysis.PeakDensityBasinInformation.Value);
147      PeakDensityBasinInformationParameter.ActualValue = peakDbi;
148      results.AddOrUpdateResult(PeakDensityBasinInformationParameter.Name, peakDbi);
149
150      var itable = GetInformationTable(analysis);
151      results.AddOrUpdateResult(InformationAnalysisParameter.Name, itable);
152      return base.Apply();
153    }
154
155    private static DataTable GetInformationTable(InformationAnalysis analysis) {
156      var dt = new DataTable("Information Analysis");
157      var ic = new DataRow("Information Content");
158      var pic = new DataRow("Partial Information Content");
159      var dbi = new DataRow("Density Basin Information");
160      var te = new DataRow("Total Entropy");
161      var e = new DataRow("Epsilon");
162      e.VisualProperties.SecondYAxis = true;
163      ic.Values.AddRange(analysis.InformationContent);
164      pic.Values.AddRange(analysis.PartialInformationContent);
165      dbi.Values.AddRange(analysis.DensityBasinInformation);
166      te.Values.AddRange(analysis.TotalEntropy);
167      e.Values.AddRange(analysis.QualityDelta);
168      dt.Rows.Add(ic);
169      dt.Rows.Add(pic);
170      dt.Rows.Add(dbi);
171      dt.Rows.Add(te);
172      dt.Rows.Add(e);
173      return dt;
174    }
175  }
176}
Note: See TracBrowser for help on using the repository browser.