Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis/Aggregators/InformationAnalysisValueAggregator.cs @ 16591

Last change on this file since 16591 was 16573, checked in by gkronber, 6 years ago

#2520: changed HeuristicLab.FLA addon to compile with new HL.Persistence

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