Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis/InformationAnalyzer.cs @ 17514

Last change on this file since 17514 was 16995, checked in by gkronber, 6 years ago

#2520 Update plugin dependencies and references for HL.FLA for new persistence

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