Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 16824 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
RevLine 
[7128]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
[9142]21
[16096]22using System.Linq;
[7128]23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
[13583]27using HeuristicLab.Optimization;
[7128]28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
[13583]31namespace HeuristicLab.Analysis.FitnessLandscape {
[7128]32
33  [StorableClass]
[13583]34  public class InformationAnalyzer : 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 ValueLookupParameter<IntValue> NQuantilesParameter {
47      get { return (ValueLookupParameter<IntValue>)Parameters["NQuantiles"]; }
48    }
[8744]49    public ValueLookupParameter<IntValue> ShapeSizeParameter {
50      get { return (ValueLookupParameter<IntValue>)Parameters["ShapeSize"]; }
51    }
[13583]52    public LookupParameter<DoubleValue> InformationContentParameter {
53      get { return (LookupParameter<DoubleValue>)Parameters["InformationContent"]; }
[7128]54    }
[13583]55    public LookupParameter<DoubleValue> PartialInformationContentParameter {
56      get { return (LookupParameter<DoubleValue>)Parameters["PartialInformationContent"]; }
[7128]57    }
[13583]58    public LookupParameter<DoubleValue> DensityBasinInformationParameter {
59      get { return (LookupParameter<DoubleValue>)Parameters["DensityBasinInformation"]; }
[7128]60    }
[13583]61    public LookupParameter<DoubleValue> TotalEntropyParameter {
62      get { return (LookupParameter<DoubleValue>)Parameters["TotalEntropy"]; }
[8725]63    }
[13583]64    public LookupParameter<DoubleValue> InformationStabilityParameter {
65      get { return (LookupParameter<DoubleValue>)Parameters["InformationStability"]; }
[7128]66    }
[13583]67    public LookupParameter<DoubleValue> RegularityParameter {
68      get { return (LookupParameter<DoubleValue>)Parameters["Regularity"]; }
[7128]69    }
[13583]70    public LookupParameter<DoubleValue> DiversityParameter {
71      get { return (LookupParameter<DoubleValue>)Parameters["Diversity"]; }
[8725]72    }
73    public LookupParameter<DoubleValue> PeakInformationContentParameter {
[13583]74      get { return (LookupParameter<DoubleValue>)Parameters["PeakInformationContent"]; }
[8725]75    }
76    public LookupParameter<DoubleValue> PeakDensityBasinInformationParameter {
[13583]77      get { return (LookupParameter<DoubleValue>)Parameters["PeakDensityBasinInformation"]; }
[8725]78    }
[15279]79    public ILookupParameter<DataTable> InformationAnalysisParameter {
80      get { return (ILookupParameter<DataTable>)Parameters["InformationAnalysis"]; }
81    }
[7128]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"));
[13583]90      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection of all results of this algorithm"));
[8744]91
[7128]92      Parameters.Add(new ValueLookupParameter<IntValue>("NQuantiles", "The number of delta quantiles to display", new IntValue(20)));
[8744]93
[13583]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"));
[8725]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."));
[15279]103
104      Parameters.Add(new LookupParameter<DataTable>("InformationAnalysis", "Graphical analysis of information theoretic features."));
[7128]105    }
106
107    public override IDeepCloneable Clone(Cloner cloner) {
108      return new InformationAnalyzer(this, cloner);
109    }
110
111    public override IOperation Apply() {
[13583]112      var qualityTrail = QualityTrailParameter.ActualValue;
113      if (qualityTrail == null || qualityTrail.Rows.Count == 0) return base.Apply();
[7128]114
115      var qualities = QualityTrailParameter.ActualValue.Rows.First().Values.ToList();
[13583]116      if (qualities.Count <= 2) return base.Apply();
[7128]117
[13583]118      var nQuantiles = NQuantilesParameter.ActualValue.Value;
119      var results = ResultsParameter.ActualValue;
120
[16137]121      var analysis = new InformationAnalysis(qualities, nQuantiles);
[13583]122      var ic = new DoubleValue(analysis.InformationContent.FirstOrDefault());
123      InformationContentParameter.ActualValue = ic;
[16096]124      results.AddOrUpdateResult(InformationContentParameter.Name, ic);
[13583]125      var pic = new DoubleValue(analysis.PartialInformationContent.FirstOrDefault());
126      PartialInformationContentParameter.ActualValue = pic;
[16096]127      results.AddOrUpdateResult(PartialInformationContentParameter.Name, pic);
[13583]128      var dbi = new DoubleValue(analysis.DensityBasinInformation.FirstOrDefault());
129      DensityBasinInformationParameter.ActualValue = dbi;
[16096]130      results.AddOrUpdateResult(DensityBasinInformationParameter.Name, dbi);
[13583]131      var @is = new DoubleValue(analysis.InformationStability);
132      InformationStabilityParameter.ActualValue = @is;
[16096]133      results.AddOrUpdateResult(InformationStabilityParameter.Name, @is);
[13583]134      var regularity = new DoubleValue(1.0 * analysis.Regularity / qualities.Count);
135      RegularityParameter.ActualValue = regularity;
[16096]136      results.AddOrUpdateResult(RegularityParameter.Name, regularity);
[13583]137      var diversity = new DoubleValue(1.0 * analysis.Diversity / qualities.Count);
138      DiversityParameter.ActualValue = diversity;
[16096]139      results.AddOrUpdateResult(DiversityParameter.Name, diversity);
[13583]140      var totalEntropy = new DoubleValue(analysis.TotalEntropy.FirstOrDefault());
141      TotalEntropyParameter.ActualValue = totalEntropy;
[16096]142      results.AddOrUpdateResult(TotalEntropyParameter.Name, totalEntropy);
[13583]143      var peakIc = new DoubleValue(analysis.PeakInformationContent.Value);
144      PeakInformationContentParameter.ActualValue = peakIc;
[16096]145      results.AddOrUpdateResult(PeakInformationContentParameter.Name, peakIc);
[13583]146      var peakDbi = new DoubleValue(analysis.PeakDensityBasinInformation.Value);
147      PeakDensityBasinInformationParameter.ActualValue = peakDbi;
[16096]148      results.AddOrUpdateResult(PeakDensityBasinInformationParameter.Name, peakDbi);
[13583]149
[15279]150      var itable = GetInformationTable(analysis);
[16096]151      results.AddOrUpdateResult(InformationAnalysisParameter.Name, itable);
[13583]152      return base.Apply();
[7128]153    }
154
[15279]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    }
[7128]175  }
176}
Note: See TracBrowser for help on using the repository browser.