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 |
|
---|
15 | namespace HeuristicLab.Analysis.FitnessLandscape {
|
---|
16 |
|
---|
17 | [Item("Up Down Aggregator", "Aggregates scalar up down analyses.")]
|
---|
18 | [StorableClass]
|
---|
19 | public class UpDownAggregator : NamedItem, IAggregator {
|
---|
20 |
|
---|
21 | public static new Image StaticItemImage { get { return VSImageLibrary.Database; } }
|
---|
22 | public override bool CanChangeName { get { return false; } }
|
---|
23 |
|
---|
24 | [Storable]
|
---|
25 | private List<double> downWalkLengths = new List<double>();
|
---|
26 | [Storable]
|
---|
27 | private List<double> upWalkLengths = new List<double>();
|
---|
28 | [Storable]
|
---|
29 | private List<double> downWalkLenVars = new List<double>();
|
---|
30 | [Storable]
|
---|
31 | private List<double> upWalkLenVars = new List<double>();
|
---|
32 |
|
---|
33 | #region Construction & Cloning
|
---|
34 | [StorableConstructor]
|
---|
35 | protected UpDownAggregator(bool deserializing) : base(deserializing) { }
|
---|
36 | protected UpDownAggregator(UpDownAggregator original, Cloner cloner) : base(original, cloner) {
|
---|
37 | downWalkLengths = original.downWalkLengths.ToList();
|
---|
38 | upWalkLengths = original.upWalkLengths.ToList();
|
---|
39 | downWalkLenVars = original.downWalkLenVars.ToList();
|
---|
40 | upWalkLenVars = original.upWalkLenVars.ToList();
|
---|
41 | }
|
---|
42 | public UpDownAggregator() {
|
---|
43 | name = ItemName;
|
---|
44 | description = ItemDescription;
|
---|
45 | }
|
---|
46 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
47 | return new UpDownAggregator(this, cloner);
|
---|
48 | }
|
---|
49 | #endregion
|
---|
50 |
|
---|
51 | #region IAggregator interface
|
---|
52 | public virtual void MaybeAddResult(IResult result) {
|
---|
53 | MaybeAddValue(downWalkLengths, "DownWalkLength", result);
|
---|
54 | MaybeAddValue(upWalkLengths, "UpWalkLength", result);
|
---|
55 | MaybeAddValue(downWalkLenVars, "DownWalkLenVar", result);
|
---|
56 | MaybeAddValue(upWalkLenVars, "UpWalkLenVar", result);
|
---|
57 | }
|
---|
58 |
|
---|
59 | private void MaybeAddValue(List<double> values, string resultName, IResult result) {
|
---|
60 | if (result.Name != resultName) return;
|
---|
61 | var value = result.Value as DoubleValue;
|
---|
62 | if (value != null)
|
---|
63 | values.Add(value.Value);
|
---|
64 | }
|
---|
65 |
|
---|
66 | public virtual IResult CreateResult() {
|
---|
67 | var results = new ResultCollection();
|
---|
68 | results.AddRange(CreateSummary("DownWalkLength", downWalkLengths));
|
---|
69 | results.AddRange(CreateSummary("UpWalkLength", upWalkLengths));
|
---|
70 | results.AddRange(CreateSummary("DownWalkLenVar", downWalkLenVars));
|
---|
71 | results.AddRange(CreateSummary("UpWalkLenVar", upWalkLenVars));
|
---|
72 | return new Result("UpDown", results);
|
---|
73 | }
|
---|
74 |
|
---|
75 | public virtual void Reset() {
|
---|
76 | downWalkLengths.Clear();
|
---|
77 | upWalkLengths.Clear();
|
---|
78 | downWalkLenVars.Clear();
|
---|
79 | upWalkLenVars.Clear();
|
---|
80 | }
|
---|
81 | #endregion
|
---|
82 |
|
---|
83 | private IEnumerable<IResult> CreateSummary(string name, IEnumerable<double> values) {
|
---|
84 | DistributionAnalyzer analyzer = new DistributionAnalyzer(values);
|
---|
85 | return new[] {
|
---|
86 | new Result(name + " Avg", new DoubleValue(analyzer.Mean)),
|
---|
87 | new Result(name + " Quartile-Spread", new DoubleValue(analyzer[0.75]-analyzer[0.25])),
|
---|
88 | new Result(name + " 90%-Spread", new DoubleValue(analyzer[0.95]-analyzer[0.05])),
|
---|
89 | new Result(name + " Range", new DoubleValue(analyzer[1]-analyzer[0])),
|
---|
90 | };
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 |
|
---|
95 | }
|
---|
96 | }
|
---|