1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Data;
|
---|
25 | using HeuristicLab.Operators;
|
---|
26 | using HeuristicLab.Optimization;
|
---|
27 | using HeuristicLab.Parameters;
|
---|
28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
29 | using System.Linq;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Analysis.FitnessLandscape {
|
---|
32 |
|
---|
33 | [StorableClass]
|
---|
34 | public class InformationAnalyzer : SingleSuccessorOperator, IQualityTrailAnalyzer {
|
---|
35 | public bool EnabledByDefault {
|
---|
36 | get { return false; }
|
---|
37 | }
|
---|
38 |
|
---|
39 | #region Parameters
|
---|
40 | public LookupParameter<DataTable> QualityTrailParameter {
|
---|
41 | get { return (LookupParameter<DataTable>)Parameters["Quality Trail"]; }
|
---|
42 | }
|
---|
43 | public LookupParameter<ResultCollection> ResultsParameter {
|
---|
44 | get { return (LookupParameter<ResultCollection>)Parameters["Results"]; }
|
---|
45 | }
|
---|
46 | public ValueLookupParameter<IntValue> NQuantilesParameter {
|
---|
47 | get { return (ValueLookupParameter<IntValue>)Parameters["NQuantiles"]; }
|
---|
48 | }
|
---|
49 | public ValueLookupParameter<IntValue> ShapeSizeParameter {
|
---|
50 | get { return (ValueLookupParameter<IntValue>)Parameters["ShapeSize"]; }
|
---|
51 | }
|
---|
52 | public LookupParameter<DoubleValue> InformationContentParameter {
|
---|
53 | get { return (LookupParameter<DoubleValue>)Parameters["InformationContent"]; }
|
---|
54 | }
|
---|
55 | public LookupParameter<DoubleValue> PartialInformationContentParameter {
|
---|
56 | get { return (LookupParameter<DoubleValue>)Parameters["PartialInformationContent"]; }
|
---|
57 | }
|
---|
58 | public LookupParameter<DoubleValue> DensityBasinInformationParameter {
|
---|
59 | get { return (LookupParameter<DoubleValue>)Parameters["DensityBasinInformation"]; }
|
---|
60 | }
|
---|
61 | public LookupParameter<DoubleValue> TotalEntropyParameter {
|
---|
62 | get { return (LookupParameter<DoubleValue>)Parameters["TotalEntropy"]; }
|
---|
63 | }
|
---|
64 | public LookupParameter<DoubleValue> InformationStabilityParameter {
|
---|
65 | get { return (LookupParameter<DoubleValue>)Parameters["InformationStability"]; }
|
---|
66 | }
|
---|
67 | public LookupParameter<DoubleValue> RegularityParameter {
|
---|
68 | get { return (LookupParameter<DoubleValue>)Parameters["Regularity"]; }
|
---|
69 | }
|
---|
70 | public LookupParameter<DoubleValue> DiversityParameter {
|
---|
71 | get { return (LookupParameter<DoubleValue>)Parameters["Diversity"]; }
|
---|
72 | }
|
---|
73 | public LookupParameter<DoubleValue> PeakInformationContentParameter {
|
---|
74 | get { return (LookupParameter<DoubleValue>)Parameters["PeakInformationContent"]; }
|
---|
75 | }
|
---|
76 | public LookupParameter<DoubleValue> PeakDensityBasinInformationParameter {
|
---|
77 | get { return (LookupParameter<DoubleValue>)Parameters["PeakDensityBasinInformation"]; }
|
---|
78 | }
|
---|
79 | #endregion
|
---|
80 |
|
---|
81 | [StorableConstructor]
|
---|
82 | protected InformationAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
83 | protected InformationAnalyzer(InformationAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
84 |
|
---|
85 | public InformationAnalyzer() {
|
---|
86 | Parameters.Add(new LookupParameter<DataTable>("Quality Trail", "The qualities of the solutions"));
|
---|
87 | Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection of all results of this algorithm"));
|
---|
88 |
|
---|
89 | Parameters.Add(new ValueLookupParameter<IntValue>("NQuantiles", "The number of delta quantiles to display", new IntValue(20)));
|
---|
90 | Parameters.Add(new ValueLookupParameter<IntValue>("ShapeSize", "The number of slopes to consider as shapes.", new IntValue(2)));
|
---|
91 |
|
---|
92 | Parameters.Add(new LookupParameter<DoubleValue>("InformationContent", "The information content H(0) at eps = 0"));
|
---|
93 | Parameters.Add(new LookupParameter<DoubleValue>("PartialInformationContent", "Partial information content M(0) at eps = 0"));
|
---|
94 | Parameters.Add(new LookupParameter<DoubleValue>("DensityBasinInformation", "Density Basin Information h(0) at eps = 0"));
|
---|
95 | Parameters.Add(new LookupParameter<DoubleValue>("TotalEntropy", "The overall disorder in the trajectory"));
|
---|
96 | Parameters.Add(new LookupParameter<DoubleValue>("InformationStability", "Information Stability Value"));
|
---|
97 | Parameters.Add(new LookupParameter<DoubleValue>("Regularity", "The number of different quality differences"));
|
---|
98 | Parameters.Add(new LookupParameter<DoubleValue>("Diversity", "The number of different quality values"));
|
---|
99 | Parameters.Add(new LookupParameter<DoubleValue>("PeakInformationContent", "Maximum information content at any quality delta."));
|
---|
100 | Parameters.Add(new LookupParameter<DoubleValue>("PeakDensityBasinInformation", "Maximum density basin information at any quality delta."));
|
---|
101 | }
|
---|
102 |
|
---|
103 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
104 | return new InformationAnalyzer(this, cloner);
|
---|
105 | }
|
---|
106 |
|
---|
107 | public override IOperation Apply() {
|
---|
108 | var qualityTrail = QualityTrailParameter.ActualValue;
|
---|
109 | if (qualityTrail == null || qualityTrail.Rows.Count == 0) return base.Apply();
|
---|
110 |
|
---|
111 | var qualities = QualityTrailParameter.ActualValue.Rows.First().Values.ToList();
|
---|
112 | if (qualities.Count <= 2) return base.Apply();
|
---|
113 |
|
---|
114 | var nQuantiles = NQuantilesParameter.ActualValue.Value;
|
---|
115 | var shapeSize = ShapeSizeParameter.ActualValue.Value;
|
---|
116 | var results = ResultsParameter.ActualValue;
|
---|
117 |
|
---|
118 | var analysis = new InformationAnalysis(qualities, nQuantiles, shapeSize);
|
---|
119 | var ic = new DoubleValue(analysis.InformationContent.FirstOrDefault());
|
---|
120 | InformationContentParameter.ActualValue = ic;
|
---|
121 | AddOrUpdateResult(results, InformationContentParameter.Name, ic);
|
---|
122 | var pic = new DoubleValue(analysis.PartialInformationContent.FirstOrDefault());
|
---|
123 | PartialInformationContentParameter.ActualValue = pic;
|
---|
124 | AddOrUpdateResult(results, PartialInformationContentParameter.Name, pic);
|
---|
125 | var dbi = new DoubleValue(analysis.DensityBasinInformation.FirstOrDefault());
|
---|
126 | DensityBasinInformationParameter.ActualValue = dbi;
|
---|
127 | AddOrUpdateResult(results, DensityBasinInformationParameter.Name, dbi);
|
---|
128 | var @is = new DoubleValue(analysis.InformationStability);
|
---|
129 | InformationStabilityParameter.ActualValue = @is;
|
---|
130 | AddOrUpdateResult(results, InformationStabilityParameter.Name, @is);
|
---|
131 | var regularity = new DoubleValue(1.0 * analysis.Regularity / qualities.Count);
|
---|
132 | RegularityParameter.ActualValue = regularity;
|
---|
133 | AddOrUpdateResult(results, RegularityParameter.Name, regularity);
|
---|
134 | var diversity = new DoubleValue(1.0 * analysis.Diversity / qualities.Count);
|
---|
135 | DiversityParameter.ActualValue = diversity;
|
---|
136 | AddOrUpdateResult(results, DiversityParameter.Name, diversity);
|
---|
137 | var totalEntropy = new DoubleValue(analysis.TotalEntropy.FirstOrDefault());
|
---|
138 | TotalEntropyParameter.ActualValue = totalEntropy;
|
---|
139 | AddOrUpdateResult(results, TotalEntropyParameter.Name, totalEntropy);
|
---|
140 | var peakIc = new DoubleValue(analysis.PeakInformationContent.Value);
|
---|
141 | PeakInformationContentParameter.ActualValue = peakIc;
|
---|
142 | AddOrUpdateResult(results, PeakInformationContentParameter.Name, peakIc);
|
---|
143 | var peakDbi = new DoubleValue(analysis.PeakDensityBasinInformation.Value);
|
---|
144 | PeakDensityBasinInformationParameter.ActualValue = peakDbi;
|
---|
145 | AddOrUpdateResult(results, PeakDensityBasinInformationParameter.Name, peakDbi);
|
---|
146 |
|
---|
147 | return base.Apply();
|
---|
148 | }
|
---|
149 |
|
---|
150 | private static void AddOrUpdateResult(ResultCollection results, string name, IItem item, bool clone = false) {
|
---|
151 | IResult r;
|
---|
152 | if (!results.TryGetValue(name, out r)) {
|
---|
153 | results.Add(new Result(name, clone ? (IItem)item.Clone() : item));
|
---|
154 | } else r.Value = clone ? (IItem)item.Clone() : item;
|
---|
155 | }
|
---|
156 | }
|
---|
157 | }
|
---|