Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1614_GeneralizedQAP/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/InformationAnalyzer.cs @ 17874

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

#1614: updated to new persistence and .NET 4.6.1

File size: 9.5 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
[16728]22using System.Linq;
23using HEAL.Attic;
[7128]24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Operators;
[13583]28using HeuristicLab.Optimization;
[7128]29using HeuristicLab.Parameters;
30
[13583]31namespace HeuristicLab.Analysis.FitnessLandscape {
[7128]32
[16728]33  [StorableType("FBA53C13-1456-42F7-B594-01FCA2C58809")]
[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]
[16728]85    protected InformationAnalyzer(StorableConstructorFlag _) : base(_) { }
[7128]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      Parameters.Add(new ValueLookupParameter<IntValue>("ShapeSize", "The number of slopes to consider as shapes.", new IntValue(2)));
94
[13583]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"));
[8725]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."));
[15279]104
105      Parameters.Add(new LookupParameter<DataTable>("InformationAnalysis", "Graphical analysis of information theoretic features."));
[7128]106    }
107
108    public override IDeepCloneable Clone(Cloner cloner) {
109      return new InformationAnalyzer(this, cloner);
110    }
111
112    public override IOperation Apply() {
[13583]113      var qualityTrail = QualityTrailParameter.ActualValue;
114      if (qualityTrail == null || qualityTrail.Rows.Count == 0) return base.Apply();
[7128]115
116      var qualities = QualityTrailParameter.ActualValue.Rows.First().Values.ToList();
[13583]117      if (qualities.Count <= 2) return base.Apply();
[7128]118
[13583]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      AddOrUpdateResult(results, InformationContentParameter.Name, ic);
127      var pic = new DoubleValue(analysis.PartialInformationContent.FirstOrDefault());
128      PartialInformationContentParameter.ActualValue = pic;
129      AddOrUpdateResult(results, PartialInformationContentParameter.Name, pic);
130      var dbi = new DoubleValue(analysis.DensityBasinInformation.FirstOrDefault());
131      DensityBasinInformationParameter.ActualValue = dbi;
132      AddOrUpdateResult(results, DensityBasinInformationParameter.Name, dbi);
133      var @is = new DoubleValue(analysis.InformationStability);
134      InformationStabilityParameter.ActualValue = @is;
135      AddOrUpdateResult(results, InformationStabilityParameter.Name, @is);
136      var regularity = new DoubleValue(1.0 * analysis.Regularity / qualities.Count);
137      RegularityParameter.ActualValue = regularity;
138      AddOrUpdateResult(results, RegularityParameter.Name, regularity);
139      var diversity = new DoubleValue(1.0 * analysis.Diversity / qualities.Count);
140      DiversityParameter.ActualValue = diversity;
141      AddOrUpdateResult(results, DiversityParameter.Name, diversity);
142      var totalEntropy = new DoubleValue(analysis.TotalEntropy.FirstOrDefault());
143      TotalEntropyParameter.ActualValue = totalEntropy;
144      AddOrUpdateResult(results, TotalEntropyParameter.Name, totalEntropy);
145      var peakIc = new DoubleValue(analysis.PeakInformationContent.Value);
146      PeakInformationContentParameter.ActualValue = peakIc;
147      AddOrUpdateResult(results, PeakInformationContentParameter.Name, peakIc);
148      var peakDbi = new DoubleValue(analysis.PeakDensityBasinInformation.Value);
149      PeakDensityBasinInformationParameter.ActualValue = peakDbi;
150      AddOrUpdateResult(results, PeakDensityBasinInformationParameter.Name, peakDbi);
151
[15279]152      var itable = GetInformationTable(analysis);
153      AddOrUpdateResult(results, InformationAnalysisParameter.Name, itable);
[13583]154      return base.Apply();
[7128]155    }
156
[15279]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
[13583]178    private static void AddOrUpdateResult(ResultCollection results, string name, IItem item, bool clone = false) {
179      IResult r;
180      if (!results.TryGetValue(name, out r)) {
181        results.Add(new Result(name, clone ? (IItem)item.Clone() : item));
182      } else r.Value = clone ? (IItem)item.Clone() : item;
[7128]183    }
184  }
185}
Note: See TracBrowser for help on using the repository browser.