Free cookie consent management tool by TermsFeed Policy Generator

source: branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis/Aggregators/InformationAnalysisAggregator.cs @ 8694

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

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

File size: 5.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4using System.Linq;
5using HeuristicLab.Analysis.FitnessLandscape.DataTables;
6using HeuristicLab.Common;
7using HeuristicLab.Core;
8using HeuristicLab.Optimization;
9using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
10
11namespace HeuristicLab.Analysis.FitnessLandscape {
12
13  [Item("InformationAnalysis Aggregator", "Aggregates information anlyses.")]
14  [StorableClass]
15  public class InformationAnalysisAggregator : Aggregator<InformationAnalysisTable> {
16
17    [StorableConstructor]
18    protected InformationAnalysisAggregator(bool deserializing) : base(deserializing) { }
19    protected InformationAnalysisAggregator(InformationAnalysisAggregator original, Cloner cloner) : base(original, cloner) { }
20    public InformationAnalysisAggregator() { }
21    public override IDeepCloneable Clone(Cloner cloner) {
22      return new InformationAnalysisAggregator(this, cloner);
23    }
24
25    public override IResult CreateResult() {
26      return new Result("Information Analysis Summary", Aggregate(items, 10));
27    }
28
29    private class InformationAnalysis : IComparable<InformationAnalysis> {
30      public double Delta { get; private set; }
31      public double InformationContent { get; private set; }
32      public double PartialInformationContent { get; private set; }
33      public double DensityBasinInformation { get; private set; }
34      public InformationAnalysis(double delta, double informationContent, double partialInformationContent, double densityBasinInformation) {
35        Delta = delta;
36        InformationContent = informationContent;
37        PartialInformationContent = partialInformationContent;
38        DensityBasinInformation = densityBasinInformation;
39      }
40
41      public int CompareTo(InformationAnalysis ia) {
42        return Delta.CompareTo(ia.Delta);
43      }
44
45    }
46
47    public static DataTable Aggregate(List<InformationAnalysisTable> informationAnalysisTables, int nQuantiles) {
48      var values = new List<InformationAnalysis>();
49      foreach (var table in informationAnalysisTables) {
50        List<double> deltas = table.Rows["Quality Delta"].Values.ToList();
51        for (int i = 0; i < deltas.Count; i++) {
52          values.Add(new InformationAnalysis(
53            deltas[i],
54            table.Rows["Information Content"].Values[i],
55            table.Rows["Partial Information Content"].Values[i],
56            table.Rows["Density Basin Information"].Values[i]));
57        }
58      }
59      values.Sort();
60      Rows informationContent = new Rows("Information Content", Color.Red);
61      Rows partialInformationContent = new Rows("Partial Information Content", Color.FromArgb(255, 0, 255));
62      Rows densityBasinInformation = new Rows("Density Basin Information", Color.FromArgb(0, 255, 0));
63      Rows qualityDelta = new Rows("Quality Delta", Color.Blue, true);
64      var aggregatedValues = new List<InformationAnalysis>();
65      var valueIt = values.GetEnumerator();
66      int it = 0;
67      for (int q = 0; q < nQuantiles; q++) {
68        aggregatedValues.Clear();
69        for (; it < values.Count * (q + 1) / nQuantiles && valueIt.MoveNext(); it++)
70          aggregatedValues.Add(valueIt.Current);
71        if (aggregatedValues.Count == 0)
72          break;
73        informationContent.AppendValues(aggregatedValues.Select(v => v.InformationContent));
74        partialInformationContent.AppendValues(aggregatedValues.Select(v => v.PartialInformationContent));
75        densityBasinInformation.AppendValues(aggregatedValues.Select(v => v.DensityBasinInformation));
76        qualityDelta.AppendValues(aggregatedValues.Select(v => v.Delta));
77      }
78      DataTable summaryTable = new DataTable("Information Analysis Summary");
79      informationContent.Incorporate(summaryTable);
80      partialInformationContent.Incorporate(summaryTable);
81      densityBasinInformation.Incorporate(summaryTable);
82      qualityDelta.Incorporate(summaryTable);
83      return summaryTable;
84    }
85
86    private class Rows {
87
88      private DataRow MinRow, AvgRow, MaxRow;
89
90      public Rows(string name, Color baseColor) {
91        MaxRow = new DataRow(name + " Max");
92        AvgRow = new DataRow(name + " Avg");
93        MinRow = new DataRow(name + " Min");
94        MaxRow.VisualProperties.Color = baseColor;
95        AvgRow.VisualProperties.Color = Color.FromArgb(
96          (int)Math.Round(baseColor.R * 0.75),
97          (int)Math.Round(baseColor.G * 0.75),
98          (int)Math.Round(baseColor.B * 0.75));
99        MinRow.VisualProperties.Color = Color.FromArgb(
100          (int)Math.Round(baseColor.R * 0.5),
101          (int)Math.Round(baseColor.G * 0.5),
102          (int)Math.Round(baseColor.B * 0.5));
103      }
104
105      public Rows(string name, Color baseColor, bool secondYAxis) : this(name, baseColor) {
106        MinRow.VisualProperties.SecondYAxis = secondYAxis;
107        AvgRow.VisualProperties.SecondYAxis = secondYAxis;
108        MaxRow.VisualProperties.SecondYAxis = secondYAxis;
109      }
110
111      public void AppendValues(IEnumerable<double> values) {
112        MinRow.Values.Add(values.Min());
113        AvgRow.Values.Add(values.Average());
114        MaxRow.Values.Add(values.Max());
115      }
116
117      public void Incorporate(DataTable table) {
118        table.Rows.Add(MinRow);
119        table.Rows.Add(AvgRow);
120        table.Rows.Add(MaxRow);
121      }
122    }   
123  }
124}
Note: See TracBrowser for help on using the repository browser.