Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis/Aggregators/AutoCorrelationAggregator.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: 3.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Optimization;
7using HeuristicLab.Data;
8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9using HeuristicLab.Common;
10using HeuristicLab.Common.Resources;
11using HeuristicLab.Analysis.FitnessLandscape.DataTables;
12using System.Drawing;
13using HeuristicLab.Analysis.FitnessLandscape.Analysis;
14using HEAL.Attic;
15
16namespace HeuristicLab.Analysis.FitnessLandscape {
17
18  [Item("Auto Correlation Aggregator", "Aggregates auto correlation analyses.")]
19  [StorableType("969A27FA-5E06-4945-BCA2-87FD869F02A4")]
20  public class AutoCorrelationAggregator : Aggregator<AutoCorrelationTable> {
21
22    [StorableConstructor]
23    protected AutoCorrelationAggregator(StorableConstructorFlag _) : base(_) { }
24    protected AutoCorrelationAggregator(AutoCorrelationAggregator original, Cloner cloner) : base(original, cloner) { }
25    public AutoCorrelationAggregator() { }
26    public override IDeepCloneable Clone(Cloner cloner) {
27      return new AutoCorrelationAggregator(this, cloner);
28    }
29
30    public override IResult CreateResult() {
31      var groupings = items.GroupBy(act => act.Name).ToList();
32      switch (groupings.Count) {
33        case 0: return new Result("Empty Autocorrelation Summary", new AutoCorrelationTable("Empty Autocorrelations"));
34        case 1: return CreateResult(groupings[0].Key, groupings[0]);
35        default:
36          ResultCollection newResults = new ResultCollection();
37          foreach (var group in groupings) {
38            newResults.Add(CreateResult(group.Key, group));
39          }
40          return new Result("Auto Correlations", newResults);
41      }
42    }
43
44    public static IResult CreateResult(string name, IEnumerable<AutoCorrelationTable> tables) {
45      return new Result(string.Format("{0} Summary", name), Aggregate(tables.ToList()));
46    }
47
48    public static DataTable Aggregate(List<AutoCorrelationTable> autoCorrelationTables) {
49      DataRow minRow = new DataRow("min");     
50      DataRow maxRow = new DataRow("max");
51      DataRow avgRow = new DataRow("avg");
52      DataRow medRow = new DataRow("med");
53      DataRow q5Row = new DataRow("Q5");
54      DataRow q25Row = new DataRow("Q25");
55      DataRow q75Row = new DataRow("Q75");
56      DataRow q95Row = new DataRow("Q95");
57      for (int i = 0; ; i++) {
58        double[] autocorrelation_i = new double[autoCorrelationTables.Count];
59        bool allzero = true;
60        for (int j = 0; j < autoCorrelationTables.Count; j++) {
61          if (autoCorrelationTables[j].Rows.First().Values.Count > i) {
62            autocorrelation_i[j] = autoCorrelationTables[j].Rows.First().Values[i];
63            allzero = false;
64          } else {
65            autocorrelation_i[j] = 0;
66          }
67        }
68        if (allzero) break;
69        DistributionAnalyzer analyzer = new DistributionAnalyzer(autocorrelation_i);
70        minRow.Values.Add(analyzer[0]);
71        q25Row.Values.Add(analyzer[0.25]);
72        medRow.Values.Add(analyzer[0.5]);
73        q75Row.Values.Add(analyzer[0.75]);
74        maxRow.Values.Add(analyzer[1]);
75        avgRow.Values.Add(analyzer.Mean);
76        q5Row.Values.Add(analyzer[0.05]);
77        q95Row.Values.Add(analyzer[0.95]);
78      }
79      DataTable table = new DataTable("Auto correlations");
80      table.Rows.Add(minRow);
81      table.Rows.Add(maxRow);
82      table.Rows.Add(avgRow);
83      table.Rows.Add(medRow);
84      table.Rows.Add(q25Row);
85      table.Rows.Add(q75Row);
86      table.Rows.Add(q5Row);
87      table.Rows.Add(q95Row);
88      foreach (var row in table.Rows)
89        row.VisualProperties.StartIndexZero = true;
90      return table;
91    }
92  }
93}
Note: See TracBrowser for help on using the repository browser.