Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 7729 was 7176, checked in by gkronber, 13 years ago

#1696 adapted analyzers to compile with changes of r7172 (#1584)

File size: 9.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
21using System.Linq;
22using HeuristicLab.Analysis.FitnessLandscape.DataTables;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization.Operators;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Analysis.FitnessLandscape.Analysis {
32
33  [StorableClass]
34  public class InformationAnalyzer : AlgorithmOperator, 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<InformationStabilityTable> InformationStabilityParameter {
44      get { return (LookupParameter<InformationStabilityTable>)Parameters["Information Stability"]; }
45    }
46    public LookupParameter<InformationAnalysisTable> InformationParameter {
47      get { return (LookupParameter<InformationAnalysisTable>)Parameters["Information"]; }
48    }
49    public LookupParameter<VariableCollection> ResultsParameter {
50      get { return (LookupParameter<VariableCollection>)Parameters["Results"]; }
51    }
52    public ValueLookupParameter<IntValue> NQuantilesParameter {
53      get { return (ValueLookupParameter<IntValue>)Parameters["NQuantiles"]; }
54    }
55    public LookupParameter<DoubleValue> InformationContentValueParameter {
56      get { return (LookupParameter<DoubleValue>)Parameters["InformationContentValue"]; }
57    }
58    public LookupParameter<DoubleValue> PartialInformationContentValueParameter {
59      get { return (LookupParameter<DoubleValue>)Parameters["PartialInformationContentValue"]; }
60    }
61    public LookupParameter<DoubleValue> DensityBasinInformationValueParameter {
62      get { return (LookupParameter<DoubleValue>)Parameters["DensityBasinInformationValue"]; }
63    }
64    public LookupParameter<DoubleValue> InformationStabilityValueParameter {
65      get { return (LookupParameter<DoubleValue>)Parameters["InformationStabilityValue"]; }
66    }
67    public LookupParameter<IntValue> RegularityValueParameter {
68      get { return (LookupParameter<IntValue>)Parameters["RegularityValue"]; }
69    }
70    #endregion
71
72    private InformationStabilityTable InformationStability {
73      get { return InformationStabilityParameter.ActualValue; }
74    }
75    private double InformationContentValue {
76      set { InformationContentValueParameter.ActualValue = new DoubleValue(value); }
77    }
78    private double PartialInformationContentValue {
79      set { PartialInformationContentValueParameter.ActualValue = new DoubleValue(value); }
80    }
81    private double DensityBasinInformationValue {
82      set { DensityBasinInformationValueParameter.ActualValue = new DoubleValue(value); }
83    }
84    private double InformationStabilityValue {
85      set { InformationStabilityValueParameter.ActualValue = new DoubleValue(value); }
86    }
87
88
89    [StorableConstructor]
90    protected InformationAnalyzer(bool deserializing) : base(deserializing) { }
91    protected InformationAnalyzer(InformationAnalyzer original, Cloner cloner) : base(original, cloner) { }
92
93    public InformationAnalyzer() {
94      Parameters.Add(new LookupParameter<DataTable>("Quality Trail", "The qualities of the solutions"));
95      Parameters.Add(new LookupParameter<InformationStabilityTable>("Information Stability", "Information stability development over time"));
96      Parameters.Add(new LookupParameter<InformationAnalysisTable>("Information", "A data table that information theoretic fitness landscape characteristics"));
97      Parameters.Add(new LookupParameter<VariableCollection>("Results", "The collection of all results of this algorithm"));
98      Parameters.Add(new ValueLookupParameter<IntValue>("NQuantiles", "The number of delta quantiles to display", new IntValue(20)));
99      Parameters.Add(new LookupParameter<DoubleValue>("InformationContentValue", "The information content H(0) at eps = 0"));
100      Parameters.Add(new LookupParameter<DoubleValue>("PartialInformationContentValue", "Partial information content M(0) at eps = 0"));
101      Parameters.Add(new LookupParameter<DoubleValue>("DensityBasinInformationValue", "Density Basin Information h(0) at eps = 0"));
102      Parameters.Add(new LookupParameter<DoubleValue>("InformationStabilityValue", "Information Stability Value"));
103      Parameters.Add(new LookupParameter<IntValue>("RegularityValue", "The number of different quality differences"));
104
105      var resultsCollector = new ResultsCollector();
106      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(InformationParameter.Name));
107      resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(InformationStabilityParameter.Name));
108      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(InformationContentValueParameter.Name));
109      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PartialInformationContentValueParameter.Name));
110      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(DensityBasinInformationValueParameter.Name));
111      resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(InformationStabilityValueParameter.Name));
112      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(RegularityValueParameter.Name));
113
114
115      OperatorGraph.InitialOperator = resultsCollector;
116      resultsCollector.Successor = null;
117    }
118
119    public override IDeepCloneable Clone(Cloner cloner) {
120      return new InformationAnalyzer(this, cloner);
121    }
122
123    public override IOperation Apply() {
124      DataTable qualityTrail = QualityTrailParameter.ActualValue;
125      if (qualityTrail != null && qualityTrail.Rows.Count > 0) {
126        EnsureExistsInformationStabilityTable();
127        EnsureExistsInformationTable();
128        AnalyseInformation();
129      }
130      return base.Apply();
131    }
132
133    private void AnalyseInformation() {
134      int nQuantiles = NQuantilesParameter.ActualValue.Value;
135      var qualities = QualityTrailParameter.ActualValue.Rows.First().Values.ToList();
136      if (qualities.Count > nQuantiles) {
137        InformationAnalysisTable informationTable = InformationParameter.ActualValue;
138        var informationContent = informationTable.Rows["Information Content"].Values;
139        var partialInformationContent = informationTable.Rows["Partial Information Content"].Values;
140        var densityBasinInformation = informationTable.Rows["Density Basin Information"].Values;
141        var qualityDelta = informationTable.Rows["Quality Delta"].Values;
142        var analysis = new InformationAnalysis(qualities, nQuantiles);
143        InformationStability.Rows["Regularity"].Values.Add(analysis.Regularity);
144        InformationStability.Rows["Relative Regularity"].Values.Add(1.0 * analysis.Regularity / qualities.Count);
145        InformationStability.Rows["Information Stability"].Values.Add(analysis.InformationStability);
146        informationContent.Clear();
147        informationContent.AddRange(analysis.InformationContent);
148        partialInformationContent.Clear();
149        partialInformationContent.AddRange(analysis.PartialInformationContent);
150        densityBasinInformation.Clear();
151        densityBasinInformation.AddRange(analysis.DensityBasinInformation);
152        qualityDelta.Clear();
153        qualityDelta.AddRange(analysis.QualityDelta);
154        InformationContentValue = analysis.InformationContent.FirstOrDefault();
155        PartialInformationContentValue = analysis.PartialInformationContent.FirstOrDefault();
156        DensityBasinInformationValue = analysis.DensityBasinInformation.FirstOrDefault();
157        InformationStabilityValue = analysis.InformationStability;
158        RegularityValueParameter.ActualValue = new IntValue(analysis.Regularity);
159      }
160    }
161
162    private void EnsureExistsInformationTable() {
163      InformationAnalysisTable information = InformationParameter.ActualValue;
164      if (information == null) {
165        information = new InformationAnalysisTable("Information");
166        information.Rows.Add(new DataRow("Information Content"));
167        information.Rows.Add(new DataRow("Partial Information Content"));
168        information.Rows.Add(new DataRow("Density Basin Information"));
169        var row = new DataRow("Quality Delta");
170        row.VisualProperties.SecondYAxis = true;
171        information.Rows.Add(row);
172        InformationParameter.ActualValue = information;
173      }
174    }
175
176    private void EnsureExistsInformationStabilityTable() {
177      InformationStabilityTable informationStability = InformationStabilityParameter.ActualValue;
178      if (informationStability == null) {
179        informationStability = new InformationStabilityTable("Information Stability");
180        informationStability.Rows.Add(new DataRow("Information Stability"));
181        informationStability.Rows.Add(new DataRow("Relative Regularity"));
182        var row = new DataRow("Regularity");
183        row.VisualProperties.SecondYAxis = true;
184        informationStability.Rows.Add(row);
185        InformationStabilityParameter.ActualValue = informationStability;
186      }
187    }
188  }
189}
Note: See TracBrowser for help on using the repository browser.