Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2520 Update plugin dependencies and references for HL.FLA for new persistence

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