Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1696 Integrate fitness landscape analysis plugins from Heureka! repository.

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