Free cookie consent management tool by TermsFeed Policy Generator

source: branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis/InformationAnalyzer.cs @ 11316

Last change on this file since 11316 was 9142, checked in by epitzer, 12 years ago

#1696 enable information analysis on very short walks

File size: 14.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;
23using System.Linq;
24using HeuristicLab.Analysis.FitnessLandscape.DataTables;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Operators;
29using HeuristicLab.Optimization.Operators;
30using HeuristicLab.Parameters;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
32
33namespace HeuristicLab.Analysis.FitnessLandscape.Analysis {
34
35  [StorableClass]
36  public class InformationAnalyzer : AlgorithmOperator, IQualityTrailAnalyzer {
37    public bool EnabledByDefault {
38      get { return false; }
39    }
40
41    #region Parameters
42    public LookupParameter<DataTable> QualityTrailParameter {
43      get { return (LookupParameter<DataTable>)Parameters["Quality Trail"]; }
44    }
45    public LookupParameter<InformationStabilityTable> InformationStabilityParameter {
46      get { return (LookupParameter<InformationStabilityTable>)Parameters["Information Stability"]; }
47    }
48    public LookupParameter<InformationAnalysisTable> InformationParameter {
49      get { return (LookupParameter<InformationAnalysisTable>)Parameters["Information"]; }
50    }
51    public LookupParameter<VariableCollection> ResultsParameter {
52      get { return (LookupParameter<VariableCollection>)Parameters["Results"]; }
53    }
54    public ValueLookupParameter<IntValue> NQuantilesParameter {
55      get { return (ValueLookupParameter<IntValue>)Parameters["NQuantiles"]; }
56    }
57    public ValueLookupParameter<IntValue> ShapeSizeParameter {
58      get { return (ValueLookupParameter<IntValue>)Parameters["ShapeSize"]; }
59    }
60    public LookupParameter<DoubleValue> InformationContentValueParameter {
61      get { return (LookupParameter<DoubleValue>)Parameters["InformationContentValue"]; }
62    }
63    public LookupParameter<DoubleValue> PartialInformationContentValueParameter {
64      get { return (LookupParameter<DoubleValue>)Parameters["PartialInformationContentValue"]; }
65    }
66    public LookupParameter<DoubleValue> DensityBasinInformationValueParameter {
67      get { return (LookupParameter<DoubleValue>)Parameters["DensityBasinInformationValue"]; }
68    }
69    public LookupParameter<DoubleValue> TotalEntropyValueParameter {
70      get { return (LookupParameter<DoubleValue>)Parameters["TotalEntropyValue"]; }
71    }
72    public LookupParameter<DoubleValue> InformationStabilityValueParameter {
73      get { return (LookupParameter<DoubleValue>)Parameters["InformationStabilityValue"]; }
74    }
75    public LookupParameter<IntValue> RegularityValueParameter {
76      get { return (LookupParameter<IntValue>)Parameters["RegularityValue"]; }
77    }
78    public LookupParameter<IntValue> DiversityValueParameter {
79      get { return (LookupParameter<IntValue>)Parameters["DiversityValue"]; }
80    }
81
82    #region Peaks
83    public LookupParameter<DoubleValue> PeakInformationContentParameter {
84      get { return (LookupParameter<DoubleValue>) Parameters["PeakInformationContent"]; }
85    }
86    public LookupParameter<DoubleValue> PeakInformationContentQualityDeltaParameter {
87      get { return (LookupParameter<DoubleValue>) Parameters["PeakInformationContentQualityDelta"]; }
88    }
89    public LookupParameter<DoubleValue> PeakDensityBasinInformationParameter {
90      get { return (LookupParameter<DoubleValue>) Parameters["PeakDensityBasinInformation"]; }
91    }
92    public LookupParameter<DoubleValue> PeakDensityBasinInformationQualityDeltaParameter {
93      get { return (LookupParameter<DoubleValue>) Parameters["PeakDensityBasinInformationQualityDelta"]; }
94    }
95
96
97    #endregion
98
99    #endregion
100
101    private InformationStabilityTable InformationStability {
102      get { return InformationStabilityParameter.ActualValue; }
103    }
104    private double InformationContentValue {
105      set { InformationContentValueParameter.ActualValue = new DoubleValue(value); }
106    }
107    private double PartialInformationContentValue {
108      set { PartialInformationContentValueParameter.ActualValue = new DoubleValue(value); }
109    }
110    private double DensityBasinInformationValue {
111      set { DensityBasinInformationValueParameter.ActualValue = new DoubleValue(value); }
112    }
113    private double TotalEntropyValue {
114      set { TotalEntropyValueParameter.ActualValue = new DoubleValue(value); }
115    }
116    private double InformationStabilityValue {
117      set { InformationStabilityValueParameter.ActualValue = new DoubleValue(value); }
118    }
119
120    [StorableConstructor]
121    protected InformationAnalyzer(bool deserializing) : base(deserializing) { }
122    protected InformationAnalyzer(InformationAnalyzer original, Cloner cloner) : base(original, cloner) { }
123
124    public InformationAnalyzer() {
125      Parameters.Add(new LookupParameter<DataTable>("Quality Trail", "The qualities of the solutions"));
126      Parameters.Add(new LookupParameter<InformationStabilityTable>("Information Stability", "Information stability development over time"));
127      Parameters.Add(new LookupParameter<InformationAnalysisTable>("Information", "A data table that information theoretic fitness landscape characteristics"));
128      Parameters.Add(new LookupParameter<VariableCollection>("Results", "The collection of all results of this algorithm"));
129
130      Parameters.Add(new ValueLookupParameter<IntValue>("NQuantiles", "The number of delta quantiles to display", new IntValue(20)));
131      Parameters.Add(new ValueLookupParameter<IntValue>("ShapeSize", "The number of slopes to consider as shapes.", new IntValue(2)));
132
133      Parameters.Add(new LookupParameter<DoubleValue>("InformationContentValue", "The information content H(0) at eps = 0"));
134      Parameters.Add(new LookupParameter<DoubleValue>("PartialInformationContentValue", "Partial information content M(0) at eps = 0"));
135      Parameters.Add(new LookupParameter<DoubleValue>("DensityBasinInformationValue", "Density Basin Information h(0) at eps = 0"));
136      Parameters.Add(new LookupParameter<DoubleValue>("TotalEntropyValue", "The overall disorder in the trajectory"));
137      Parameters.Add(new LookupParameter<DoubleValue>("InformationStabilityValue", "Information Stability Value"));
138      Parameters.Add(new LookupParameter<IntValue>("RegularityValue", "The number of different quality differences"));
139      Parameters.Add(new LookupParameter<IntValue>("DiversityValue", "The number of different quality values"));
140      Parameters.Add(new LookupParameter<DoubleValue>("PeakInformationContent", "Maximum information content at any quality delta."));
141      Parameters.Add(new LookupParameter<DoubleValue>("PeakInformationContentQualityDelta", "Quality delta with maximum information content."));
142      Parameters.Add(new LookupParameter<DoubleValue>("PeakDensityBasinInformation", "Maximum density basin information at any quality delta."));
143      Parameters.Add(new LookupParameter<DoubleValue>("PeakDensityBasinInformationQualityDelta", "Quality delta with maximum density basin information."));
144
145      var resultsCollector = new ResultsCollector();
146      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(InformationParameter.Name));
147      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(InformationStabilityParameter.Name));
148      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(InformationContentValueParameter.Name));
149      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PartialInformationContentValueParameter.Name));
150      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(DensityBasinInformationValueParameter.Name));
151      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(TotalEntropyValueParameter.Name));
152      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(InformationStabilityValueParameter.Name));
153      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(RegularityValueParameter.Name));
154      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(DiversityValueParameter.Name));
155      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PeakInformationContentParameter.Name));
156      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PeakInformationContentQualityDeltaParameter.Name));
157      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PeakDensityBasinInformationParameter.Name));
158      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PeakDensityBasinInformationQualityDeltaParameter.Name));
159
160      OperatorGraph.InitialOperator = resultsCollector;
161      resultsCollector.Successor = null;
162    }
163
164    public override IDeepCloneable Clone(Cloner cloner) {
165      return new InformationAnalyzer(this, cloner);
166    }
167
168    public override IOperation Apply() {
169      DataTable qualityTrail = QualityTrailParameter.ActualValue;
170      if (qualityTrail != null && qualityTrail.Rows.Count > 0) {
171        EnsureExistsInformationStabilityTable();
172        EnsureExistsInformationTable();
173        AnalyseInformation();
174      }
175      return base.Apply();
176    }
177
178    private void AnalyseInformation() {
179      int nQuantiles = NQuantilesParameter.ActualValue.Value;
180      int shapeSize = ShapeSizeParameter.ActualValue.Value;
181      var qualities = QualityTrailParameter.ActualValue.Rows.First().Values.ToList();
182      if (qualities.Count > 2) {
183        InformationAnalysisTable informationTable = InformationParameter.ActualValue;
184        var informationContent = informationTable.Rows["Information Content"].Values;
185        var partialInformationContent = informationTable.Rows["Partial Information Content"].Values;
186        var densityBasinInformation = informationTable.Rows["Density Basin Information"].Values;
187        var totalEntropy = informationTable.Rows["Total Entropy"].Values;
188        var qualityDelta = informationTable.Rows["Quality Delta"].Values;
189        var analysis = new InformationAnalysis(qualities, nQuantiles, shapeSize);
190        InformationStability.Rows["Regularity"].Values.Add(analysis.Regularity);
191        InformationStability.Rows["Diversity"].Values.Add(analysis.Diversity);
192        InformationStability.Rows["Relative Regularity"].Values.Add(1.0*analysis.Regularity/qualities.Count);
193        InformationStability.Rows["Relative Diversity"].Values.Add(1.0*analysis.Diversity/qualities.Count);
194        InformationStability.Rows["Information Stability"].Values.Add(analysis.InformationStability);
195        informationContent.Clear();
196        informationContent.AddRange(analysis.InformationContent);
197        partialInformationContent.Clear();
198        partialInformationContent.AddRange(analysis.PartialInformationContent);
199        densityBasinInformation.Clear();
200        densityBasinInformation.AddRange(analysis.DensityBasinInformation);
201        totalEntropy.Clear();
202        totalEntropy.AddRange(analysis.TotalEntropy);
203        qualityDelta.Clear();
204        qualityDelta.AddRange(analysis.QualityDelta);
205        InformationContentValue = analysis.InformationContent.FirstOrDefault();
206        PartialInformationContentValue = analysis.PartialInformationContent.FirstOrDefault();
207        DensityBasinInformationValue = analysis.DensityBasinInformation.FirstOrDefault();
208        InformationStabilityValue = analysis.InformationStability;
209        RegularityValueParameter.ActualValue = new IntValue(analysis.Regularity);
210        DiversityValueParameter.ActualValue = new IntValue(analysis.Diversity);
211        if (analysis.PeakInformationContent != null) {
212          PeakInformationContentParameter.ActualValue = new DoubleValue(analysis.PeakInformationContent.Value);
213          PeakInformationContentQualityDeltaParameter.ActualValue = new DoubleValue(analysis.PeakInformationContent.QualityDelta);
214        }
215        if (analysis.PeakDensityBasinInformation != null) {
216          PeakDensityBasinInformationParameter.ActualValue = new DoubleValue(analysis.PeakDensityBasinInformation.Value);
217          PeakDensityBasinInformationQualityDeltaParameter.ActualValue = new DoubleValue(analysis.PeakDensityBasinInformation.QualityDelta);
218        }
219      }
220    }
221
222    private void EnsureExistsInformationTable() {
223      InformationAnalysisTable information = InformationParameter.ActualValue;
224      if (information == null) {
225        information = new InformationAnalysisTable("Information");
226        information.Rows.Add(new DataRow("Information Content"));
227        information.Rows.Add(new DataRow("Partial Information Content"));
228        information.Rows.Add(new DataRow("Density Basin Information"));
229        information.Rows.Add(new DataRow("Total Entropy"));
230        information.Rows.Add(new DataRow("Quality Delta") {VisualProperties = {SecondYAxis = true}});
231        InformationParameter.ActualValue = information;
232      }
233    }
234
235    private void EnsureExistsInformationStabilityTable() {
236      InformationStabilityTable informationStability = InformationStabilityParameter.ActualValue;
237      if (informationStability == null) {
238        informationStability = new InformationStabilityTable("Information Stability");
239        informationStability.Rows.Add(new DataRow("Information Stability"));
240        informationStability.Rows.Add(new DataRow("Relative Regularity"));
241        informationStability.Rows.Add(new DataRow("Relative Diversity"));
242        informationStability.Rows.Add(new DataRow("Regularity") {VisualProperties = {SecondYAxis = true}});
243        informationStability.Rows.Add(new DataRow("Diversity") {VisualProperties = {SecondYAxis = true}});
244        InformationStabilityParameter.ActualValue = informationStability;
245      }
246    }
247  }
248}
Note: See TracBrowser for help on using the repository browser.