Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Algorithms/RepeatedInformationAnalyzer.cs @ 16591

Last change on this file since 16591 was 16573, checked in by gkronber, 6 years ago

#2520: changed HeuristicLab.FLA addon to compile with new HL.Persistence

File size: 8.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using HeuristicLab.Analysis.FitnessLandscape.DataTables;
5using HeuristicLab.Common;
6using HeuristicLab.Core;
7using HeuristicLab.Data;
8using HeuristicLab.Operators;
9using HeuristicLab.Optimization;
10using HeuristicLab.Parameters;
11using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
12using HEAL.Attic;
13
14namespace HeuristicLab.Analysis.FitnessLandscape.Algorithms {
15
16  [Item("RepeatedInformationAnalyzer", "Analyzes and consolidates repeated information analyses.")]
17  [StorableType("A53A3F9B-BC38-47E9-B435-42DEA10A4ABC")]
18  public class RepeatedInformationAnalyzer : SingleSuccessorOperator, IRepeatsAnalyzer {
19
20    #region Parameters
21    public ScopeTreeLookupParameter<InformationAnalysisTable> InformationsParameter {
22      get { return (ScopeTreeLookupParameter<InformationAnalysisTable>)Parameters["Information"]; }
23    }
24    public ScopeTreeLookupParameter<DoubleValue> InformationContentValuesParameter {
25      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["InformationContentValue"]; }
26    }
27    public ScopeTreeLookupParameter<DoubleValue> PartialInformationContentValuesParameter {
28      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["PartialInformationContentValue"]; }
29    }
30    public ScopeTreeLookupParameter<DoubleValue> DensityBasinInformationValuesParameter {
31      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["DensityBasinInformationValue"]; }
32    }
33    public ScopeTreeLookupParameter<DoubleValue> InformationStabilityValuesParameter {
34      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["InformationStabilityValue"]; }
35    }
36    public ScopeTreeLookupParameter<IntValue> RegularityValuesParameter {
37      get { return (ScopeTreeLookupParameter<IntValue>)Parameters["RegularityValue"]; }
38    }
39
40    public LookupParameter<ResultCollection> ResultsParameter {
41      get { return (LookupParameter<ResultCollection>)Parameters["Results"]; }
42    }
43    #endregion
44
45    #region Construction & Cloning
46    [StorableConstructor]
47    protected RepeatedInformationAnalyzer(StorableConstructorFlag _) : base(_) { }
48    protected RepeatedInformationAnalyzer(RepeatedInformationAnalyzer original, Cloner cloner) : base(original, cloner) { }
49    public RepeatedInformationAnalyzer() {
50      Parameters.Add(new ScopeTreeLookupParameter<InformationAnalysisTable>("Information", "A data table that information theoretic fitness landscape characteristics"));
51      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("InformationContentValue", "The information content H(0) at eps = 0"));
52      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("PartialInformationContentValue", "Partial information content M(0) at eps = 0"));
53      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("DensityBasinInformationValue", "Density Basin Information h(0) at eps = 0"));
54      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("InformationStabilityValue", "Information Stability Value"));
55      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("RegularityValue", "The number of different quality differences"));
56      Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection of all results of this algorithm"));
57      InformationsParameter.Depth = 2;
58      InformationContentValuesParameter.Depth = 2;
59      PartialInformationContentValuesParameter.Depth = 2;
60      DensityBasinInformationValuesParameter.Depth = 2;
61      InformationStabilityValuesParameter.Depth = 2;
62      RegularityValuesParameter.Depth = 2;
63    }
64    public override IDeepCloneable Clone(Cloner cloner) {
65      return new RepeatedInformationAnalyzer(this, cloner);
66    }
67    #endregion
68
69    private class Entry : IComparable<Entry> {
70
71      public double InformationContent { get; private set; }
72      public double PartialInformationContent { get; private set; }
73      public double DensityBasinInformation { get; private set; }
74      public double Epsilon { get; private set; }
75
76      public Entry(double epsilon, double informationContent, double partialInformationContent, double densityBasinInformation) {
77        Epsilon = epsilon;
78        InformationContent = informationContent;
79        PartialInformationContent = partialInformationContent;
80        DensityBasinInformation = densityBasinInformation;
81      }
82
83      public int CompareTo(Entry other) {
84        return Epsilon.CompareTo(other.Epsilon);
85      }
86
87      public override bool Equals(object obj) {
88        Entry e = obj as Entry;
89        if (e == null)
90          throw new NotSupportedException();
91        return this.Epsilon == e.Epsilon;
92      }
93
94      public override int GetHashCode() {
95        return Epsilon.GetHashCode();
96      }
97
98    }
99
100    public override IOperation Apply() {     
101      ResultCollection results = ResultsParameter.ActualValue;     
102      var informationTables = InformationsParameter.ActualValue.ToList();
103      List<Entry> entries = new List<Entry>();
104      foreach (var t in informationTables) {
105        var values = t.Rows["Quality Delta"].Values;
106        var info = t.Rows["Information Content"].Values;
107        var partInfo = t.Rows["Partial Information Content"].Values;
108        var densBas = t.Rows["Density Basin Information"].Values;
109        var eps = t.Rows["Quality Delta"].Values;
110        for (int i = 0; i < info.Count; i++) {
111          entries.Add(new Entry(eps[i], info[i], partInfo[i], densBas[i]));
112        }
113      }
114      entries.Sort();
115      double informationSum = 0;
116      double partialInformationSum = 0;
117      double densityBasinSum = 0;
118      double epsilonSum = 0;
119      DataRow informationRow = new DataRow("Information Content");
120      DataRow partialInformationRow = new DataRow("Partial Information Content");
121      DataRow densityBasinRow = new DataRow("Density Basin Information");
122      DataRow epsilonRow = new DataRow("Quality Delta");
123      epsilonRow.VisualProperties.SecondYAxis = true;
124      int n = 0;
125      foreach (var entry in entries) {
126        informationSum += entry.InformationContent;
127        partialInformationSum += entry.PartialInformationContent;
128        densityBasinSum += entry.DensityBasinInformation;
129        epsilonSum += entry.Epsilon;
130        n++;
131        if (n == informationTables.Count) {
132          informationRow.Values.Add(informationSum/n); informationSum = 0;
133          partialInformationRow.Values.Add(partialInformationSum/n); partialInformationSum = 0;
134          densityBasinRow.Values.Add(densityBasinSum/n); densityBasinSum = 0;
135          epsilonRow.Values.Add(epsilonSum/n); epsilonSum = 0;
136          n = 0;
137        }
138      }
139      if (n > 0) {
140        informationRow.Values.Add(informationSum / n);
141        partialInformationRow.Values.Add(partialInformationSum / n);
142        densityBasinRow.Values.Add(densityBasinSum / n);
143        epsilonRow.Values.Add(epsilonSum / n);
144      }
145      InformationAnalysisTable table = new InformationAnalysisTable("Avg. Information Analysis");
146      table.Rows.Add(informationRow);
147      table.Rows.Add(partialInformationRow);
148      table.Rows.Add(densityBasinRow);
149      table.Rows.Add(epsilonRow);     
150      results.Remove("Information");
151      results.Add(new Result("Information", table));
152
153      results.Remove("InformationContentValue");
154      results.Remove("PartialInformationContentValue");
155      results.Remove("DensityBasinInformationValue");
156      results.Remove("InformationStabilityValue");
157      results.Add(new Result("InformationContentValue", new DoubleValue(InformationContentValuesParameter.ActualValue.Select(v => v.Value).Average())));
158      results.Add(new Result("PartialInformationContentValue", new DoubleValue(PartialInformationContentValuesParameter.ActualValue.Select(v => v.Value).Average())));
159      results.Add(new Result("DensityBasinInformationValue", new DoubleValue(DensityBasinInformationValuesParameter.ActualValue.Select(v => v.Value).Average())));
160      results.Add(new Result("InformationStabilityValue", new DoubleValue(InformationStabilityValuesParameter.ActualValue.Select(v => v.Value).Average())));
161
162      return base.Apply();
163    }
164  }
165}
Note: See TracBrowser for help on using the repository browser.