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