Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis/Aggregators/InformationAnalysisPeakAggregator.cs @ 16573

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

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

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