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