Free cookie consent management tool by TermsFeed Policy Generator

source: branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis/Aggregators/InformationAnalysisValueAggregator.cs @ 11271

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

#1696: Add static item image according to #1651

File size: 4.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4using System.Linq;
5using HeuristicLab.Analysis.FitnessLandscape.DataTables;
6using HeuristicLab.Common;
7using HeuristicLab.Core;
8using HeuristicLab.Optimization;
9using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
10using HeuristicLab.Data;
11using HeuristicLab.Common.Resources;
12
13namespace HeuristicLab.Analysis.FitnessLandscape {
14
15  [Item("InformationAnalysisValue Aggregator", "Aggregates information anlysis values.")]
16  [StorableClass]
17  public class InformationAnalysisValueAggregator : NamedItem, IAggregator {
18
19    #region Fields
20    [Storable]
21    private List<double> InformationContentValues;
22    [Storable]
23    private List<double> PartialInformationContentValues;
24    [Storable]
25    private List<double> DensityBasinInformationValues;
26    [Storable]
27    private List<double> InformationStabilityValues;
28    #endregion   
29
30    #region Properties
31    public static new Image StaticItemImage { get { return VSImageLibrary.Database; } }
32    public override bool CanChangeName { get { return false; } }
33    #endregion
34
35    #region Construction and Cloning
36    [StorableConstructor]
37    protected InformationAnalysisValueAggregator(bool deserializing) : base(deserializing) { }
38    protected InformationAnalysisValueAggregator(InformationAnalysisValueAggregator original, Cloner cloner)
39      : base(original, cloner) {
40      InformationContentValues = original.InformationContentValues.ToList();
41      PartialInformationContentValues = original.PartialInformationContentValues.ToList();     
42      DensityBasinInformationValues = original.DensityBasinInformationValues.ToList();
43      InformationStabilityValues = original.InformationStabilityValues.ToList();
44    }
45    public InformationAnalysisValueAggregator() {
46      name = ItemName;
47      description = ItemDescription;
48      InformationContentValues = new List<double>();
49      PartialInformationContentValues = new List<double>();   
50      DensityBasinInformationValues = new List<double>();
51      InformationStabilityValues = new List<double>();
52    }
53    public override IDeepCloneable Clone(Cloner cloner) {
54      return new InformationAnalysisValueAggregator(this, cloner);
55    }
56    #endregion
57
58    #region IAggregator Members
59    public void MaybeAddResult(IResult result) {
60      if (result.DataType == typeof(DoubleValue)) {
61        double value = ((DoubleValue)result.Value).Value;
62        switch (result.Name) {
63          case "InformationContentValue": InformationContentValues.Add(value); break;
64          case "PartialInformationContentValue": PartialInformationContentValues.Add(value); break;
65          case "DensityBasinInformationValue": DensityBasinInformationValues.Add(value); break;
66          case "InformationStabilityValue": InformationStabilityValues.Add(value); break;
67        }
68      }
69    }
70
71    public void Reset() {
72      InformationContentValues.Clear();
73      PartialInformationContentValues.Clear();
74      InformationStabilityValues.Clear();
75      DensityBasinInformationValues.Clear();
76    }
77
78    public IResult CreateResult() {
79      var results = new ResultCollection();
80      results.AddRange(CreateSummary("Inf Cont", InformationContentValues));
81      results.AddRange(CreateSummary("Part Inf Cont", PartialInformationContentValues));
82      results.AddRange(CreateSummary("Dens Bas Inf", DensityBasinInformationValues));
83      results.AddRange(CreateSummary("Inf Stab", InformationStabilityValues));
84      return new Result("Inf. Val.", results);
85    }
86
87    private static IEnumerable<IResult> CreateSummary(string name, IEnumerable<double> values) {
88      DistributionAnalyzer analyzer = new DistributionAnalyzer(values);
89      return new[] {
90        new Result(name + " Avg", new DoubleValue(analyzer.Mean)),
91        new Result(name + " Quart-Spread", new DoubleValue(analyzer[0.75]-analyzer[0.25])),
92        new Result(name + " 90%-Spread", new DoubleValue(analyzer[0.95]-analyzer[0.05])),
93        new Result(name + " Range", new DoubleValue(analyzer[1]-analyzer[0])),
94      };
95    }
96    #endregion
97  }
98}
Note: See TracBrowser for help on using the repository browser.