1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using HeuristicLab.Optimization;
|
---|
7 | using HeuristicLab.Data;
|
---|
8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
9 | using HeuristicLab.Common;
|
---|
10 | using HeuristicLab.Common.Resources;
|
---|
11 | using HeuristicLab.Analysis.FitnessLandscape.DataTables;
|
---|
12 | using System.Drawing;
|
---|
13 | using HeuristicLab.Analysis.FitnessLandscape.Analysis;
|
---|
14 | using HEAL.Attic;
|
---|
15 |
|
---|
16 | namespace 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 | }
|
---|