Free cookie consent management tool by TermsFeed Policy Generator

source: branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis/Aggregators/InformationAnalysisPeakAggregator.cs @ 12064

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

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

File size: 4.4 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;
10using HeuristicLab.Data;
11
12namespace HeuristicLab.Analysis.FitnessLandscape {
13
14  [Item("InformationAnalysis Peak Aggregator", "Aggregates peak information anlyses.")]
15  [StorableClass]
16  public class InformationAnalysisPeakAggregator : Aggregator<InformationAnalysisTable> {
17
18    [StorableConstructor]
19    protected InformationAnalysisPeakAggregator(bool deserializing) : base(deserializing) { }
20    protected InformationAnalysisPeakAggregator(InformationAnalysisPeakAggregator original, Cloner cloner) : base(original, cloner) { }
21    public InformationAnalysisPeakAggregator() { }
22    public override IDeepCloneable Clone(Cloner cloner) {
23      return new InformationAnalysisPeakAggregator(this, cloner);
24    }
25
26    public override IResult CreateResult() {
27      return new Result("Inf. Peak", Aggregate(items, 10));
28    }
29
30    public static ResultCollection Aggregate(List<InformationAnalysisTable> informationAnalysisTables, int nQuantiles) {
31      var informationContent = new List<PointD>();
32      var partialInformationContent = new List<PointD>();
33      var densityBasinInformation = new List<PointD>();
34      foreach (var table in informationAnalysisTables) {
35        List<double> deltas = table.Rows["Quality Delta"].Values.ToList();
36        informationContent.Add(GetPeak(deltas, table.Rows["Information Content"].Values));
37        partialInformationContent.Add(GetPeak(deltas, table.Rows["Partial Information Content"].Values));
38        densityBasinInformation.Add(GetPeak(deltas, table.Rows["Density Basin Information"].Values));
39      }
40      var results = new ResultCollection();
41      results.AddRange(CreateSummary("Q Delt", "Inf Cont", informationContent, true));
42      results.AddRange(CreateSummary("Q Delt", "Part Inf Cont", partialInformationContent, false));
43      results.AddRange(CreateSummary("Q Delt", "Dens Bas Inf", densityBasinInformation, false));
44      return results;
45    }
46
47    private static PointD GetPeak(IEnumerable<double> index, IEnumerable<double> value) {
48      var max = index.Zip(value, (i, v) => new { i, v }).OrderByDescending(p => p.v).First();
49      return new PointD(max.i, max.v);
50    }
51
52    private class PointD : IComparable<PointD> {
53      public double X;
54      public double Y;
55      public PointD(double x, double y) {
56        X = x;
57        Y = y;
58      }
59
60      public int CompareTo(PointD other) {
61        return X.CompareTo(other.X);
62      }
63    }
64
65    private static IEnumerable<IResult> CreateSummary(string xName, string yName, IEnumerable<PointD> values, bool showX) {
66      var xAnalyzer = new DistributionAnalyzer(values.Select(p => p.X));
67      var yAnalyzer = new DistributionAnalyzer(values.Select(p => p.Y));
68      if (showX) {
69        yield return new Result(xName + " Avg", new DoubleValue(xAnalyzer.Mean));
70        yield return new Result(xName + " Quart-Spread", new DoubleValue(xAnalyzer[0.75] - xAnalyzer[0.25]));
71        yield return new Result(xName + " 90%-Spread", new DoubleValue(xAnalyzer[0.95] - xAnalyzer[0.05]));
72        yield return new Result(xName + " Range", new DoubleValue(xAnalyzer[1] - xAnalyzer[0]));
73      }
74      yield return new Result(yName + " Avg", new DoubleValue(yAnalyzer.Mean));
75      yield return new Result(yName + " Quart-Spread", new DoubleValue(yAnalyzer[0.75] - yAnalyzer[0.25]));
76      yield return new Result(yName + " 90%-Spread", new DoubleValue(yAnalyzer[0.95] - yAnalyzer[0.05]));
77      yield return new Result(yName + " Range", new DoubleValue(yAnalyzer[1] - yAnalyzer[0]));
78
79      yield return new Result(string.Format("{0}/{1} Quart-Spread", xName, yName), new DoubleValue(
80        Math.Sqrt(sqr(xAnalyzer[0.75] - xAnalyzer[0.25]) + sqr(yAnalyzer[0.75] - yAnalyzer[0.25]))));
81      yield return new Result(string.Format("{0}/{1} 90%-Spread", xName, yName), new DoubleValue(
82        Math.Sqrt(sqr(xAnalyzer[0.95] - xAnalyzer[0.05]) + sqr(yAnalyzer[0.75] - yAnalyzer[0.25]))));
83      yield return new Result(string.Format("{0}/{1} Range", xName, yName), new DoubleValue(
84        Math.Sqrt(sqr(xAnalyzer[1] - xAnalyzer[0]) + sqr(yAnalyzer[1] - yAnalyzer[0]))));
85    }
86
87    private static double sqr(double x) {
88      return x * x;
89    }
90  }
91}
Note: See TracBrowser for help on using the repository browser.