Free cookie consent management tool by TermsFeed Policy Generator

source: branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis/Aggregators/RuggednessAggregator.cs @ 7202

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

#1696: Add static item image according to #1651

File size: 3.5 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("Ruggedness Aggregator", "Aggregates scalar ruggedness analyses.")]
18  [StorableClass]
19  public class RuggednessAggregator : NamedItem, IAggregator {
20
21    public static new Image StaticItemImage { get { return VSImageLibrary.Database; } }
22    public override bool CanChangeName { get { return false; } }
23
24    private List<double> correlationLengthValues = new List<double>();
25    private List<double> autocorrelations = new List<double>();
26
27    #region Construction & Cloning
28    [StorableConstructor]
29    protected RuggednessAggregator(bool deserializing) : base(deserializing) { }
30    protected RuggednessAggregator(RuggednessAggregator original, Cloner cloner) : base(original, cloner) {
31      autocorrelations = original.autocorrelations.ToList();
32      correlationLengthValues = original.correlationLengthValues.ToList();
33    }
34    public RuggednessAggregator() {
35      name = ItemName;
36      description = ItemDescription;
37    }
38    public override IDeepCloneable Clone(Cloner cloner) {
39      return new RuggednessAggregator(this, cloner);
40    }
41    #endregion
42
43    #region IAggregator interface   
44    public virtual void MaybeAddResult(IResult result) {
45      MaybeAddAutoCorrelation1(result);
46      MaybeAddCorrelationLength(result);
47    }
48
49    public virtual IResult CreateResult() {
50      var results = new ResultCollection();
51      results.AddRange(CreateSummary("AutoCorrelation1", autocorrelations));
52      results.AddRange(CreateSummary("CorrelationLength", correlationLengthValues.Select(l => (double)l)));
53      return new Result("Ruggedness", results);
54    }
55
56    public virtual void Reset() {
57      autocorrelations.Clear();
58      correlationLengthValues.Clear();
59    }
60    #endregion
61
62    private void MaybeAddAutoCorrelation1(IResult result) {
63      if (result.Name != "AutoCorrelation1")
64        return;
65      DoubleValue autocorrelation1 = result.Value as DoubleValue;
66      if (autocorrelation1 != null)
67        autocorrelations.Add(autocorrelation1.Value);
68    }
69
70    private void MaybeAddCorrelationLength(IResult result) {
71      if (result.Name != "CorrelationLength")
72        return;
73      IntValue correlationLength = result.Value as IntValue;
74      if (correlationLength != null)
75        correlationLengthValues.Add(correlationLength.Value);
76      else {
77        DoubleValue correlationLength2 = result.Value as DoubleValue;
78        if (correlationLength2 != null)
79          correlationLengthValues.Add(correlationLength2.Value);
80      }
81    }
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.