Free cookie consent management tool by TermsFeed Policy Generator

source: branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis/Aggregators/UpDownAggregatorAggregator.cs @ 14808

Last change on this file since 14808 was 9143, checked in by epitzer, 12 years ago

#1696 implement repeated up-down walks and multi-trajectory aggregation of up-down walks

File size: 3.6 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;
14
15namespace 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}
Note: See TracBrowser for help on using the repository browser.