[7128] | 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
|
---|
[9142] | 21 |
|
---|
[7128] | 22 | using System.Linq;
|
---|
| 23 | using HeuristicLab.Analysis.FitnessLandscape.DataTables;
|
---|
| 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Data;
|
---|
| 27 | using HeuristicLab.Operators;
|
---|
| 28 | using HeuristicLab.Optimization.Operators;
|
---|
| 29 | using HeuristicLab.Parameters;
|
---|
[16573] | 30 | using HEAL.Attic;
|
---|
[7128] | 31 |
|
---|
| 32 | namespace HeuristicLab.Analysis.FitnessLandscape.Analysis {
|
---|
| 33 |
|
---|
[16573] | 34 | [StorableType("57803A7A-E1A7-4AD8-9F32-D97F5983ACBD")]
|
---|
[7128] | 35 | public class InformationAnalyzer : AlgorithmOperator, IQualityTrailAnalyzer {
|
---|
[7176] | 36 | public bool EnabledByDefault {
|
---|
| 37 | get { return false; }
|
---|
| 38 | }
|
---|
[7128] | 39 |
|
---|
| 40 | #region Parameters
|
---|
| 41 | public LookupParameter<DataTable> QualityTrailParameter {
|
---|
| 42 | get { return (LookupParameter<DataTable>)Parameters["Quality Trail"]; }
|
---|
| 43 | }
|
---|
| 44 | public LookupParameter<InformationStabilityTable> InformationStabilityParameter {
|
---|
| 45 | get { return (LookupParameter<InformationStabilityTable>)Parameters["Information Stability"]; }
|
---|
| 46 | }
|
---|
| 47 | public LookupParameter<InformationAnalysisTable> InformationParameter {
|
---|
| 48 | get { return (LookupParameter<InformationAnalysisTable>)Parameters["Information"]; }
|
---|
| 49 | }
|
---|
| 50 | public LookupParameter<VariableCollection> ResultsParameter {
|
---|
| 51 | get { return (LookupParameter<VariableCollection>)Parameters["Results"]; }
|
---|
| 52 | }
|
---|
| 53 | public ValueLookupParameter<IntValue> NQuantilesParameter {
|
---|
| 54 | get { return (ValueLookupParameter<IntValue>)Parameters["NQuantiles"]; }
|
---|
| 55 | }
|
---|
[8744] | 56 | public ValueLookupParameter<IntValue> ShapeSizeParameter {
|
---|
| 57 | get { return (ValueLookupParameter<IntValue>)Parameters["ShapeSize"]; }
|
---|
| 58 | }
|
---|
[7128] | 59 | public LookupParameter<DoubleValue> InformationContentValueParameter {
|
---|
| 60 | get { return (LookupParameter<DoubleValue>)Parameters["InformationContentValue"]; }
|
---|
| 61 | }
|
---|
| 62 | public LookupParameter<DoubleValue> PartialInformationContentValueParameter {
|
---|
| 63 | get { return (LookupParameter<DoubleValue>)Parameters["PartialInformationContentValue"]; }
|
---|
| 64 | }
|
---|
| 65 | public LookupParameter<DoubleValue> DensityBasinInformationValueParameter {
|
---|
| 66 | get { return (LookupParameter<DoubleValue>)Parameters["DensityBasinInformationValue"]; }
|
---|
| 67 | }
|
---|
[8725] | 68 | public LookupParameter<DoubleValue> TotalEntropyValueParameter {
|
---|
| 69 | get { return (LookupParameter<DoubleValue>)Parameters["TotalEntropyValue"]; }
|
---|
| 70 | }
|
---|
[7128] | 71 | public LookupParameter<DoubleValue> InformationStabilityValueParameter {
|
---|
| 72 | get { return (LookupParameter<DoubleValue>)Parameters["InformationStabilityValue"]; }
|
---|
| 73 | }
|
---|
| 74 | public LookupParameter<IntValue> RegularityValueParameter {
|
---|
| 75 | get { return (LookupParameter<IntValue>)Parameters["RegularityValue"]; }
|
---|
| 76 | }
|
---|
[8725] | 77 | public LookupParameter<IntValue> DiversityValueParameter {
|
---|
| 78 | get { return (LookupParameter<IntValue>)Parameters["DiversityValue"]; }
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | #region Peaks
|
---|
| 82 | public LookupParameter<DoubleValue> PeakInformationContentParameter {
|
---|
| 83 | get { return (LookupParameter<DoubleValue>) Parameters["PeakInformationContent"]; }
|
---|
| 84 | }
|
---|
| 85 | public LookupParameter<DoubleValue> PeakInformationContentQualityDeltaParameter {
|
---|
| 86 | get { return (LookupParameter<DoubleValue>) Parameters["PeakInformationContentQualityDelta"]; }
|
---|
| 87 | }
|
---|
| 88 | public LookupParameter<DoubleValue> PeakDensityBasinInformationParameter {
|
---|
| 89 | get { return (LookupParameter<DoubleValue>) Parameters["PeakDensityBasinInformation"]; }
|
---|
| 90 | }
|
---|
| 91 | public LookupParameter<DoubleValue> PeakDensityBasinInformationQualityDeltaParameter {
|
---|
| 92 | get { return (LookupParameter<DoubleValue>) Parameters["PeakDensityBasinInformationQualityDelta"]; }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 |
|
---|
[7128] | 96 | #endregion
|
---|
| 97 |
|
---|
[8725] | 98 | #endregion
|
---|
| 99 |
|
---|
[7128] | 100 | private InformationStabilityTable InformationStability {
|
---|
| 101 | get { return InformationStabilityParameter.ActualValue; }
|
---|
| 102 | }
|
---|
| 103 | private double InformationContentValue {
|
---|
| 104 | set { InformationContentValueParameter.ActualValue = new DoubleValue(value); }
|
---|
| 105 | }
|
---|
| 106 | private double PartialInformationContentValue {
|
---|
| 107 | set { PartialInformationContentValueParameter.ActualValue = new DoubleValue(value); }
|
---|
| 108 | }
|
---|
| 109 | private double DensityBasinInformationValue {
|
---|
| 110 | set { DensityBasinInformationValueParameter.ActualValue = new DoubleValue(value); }
|
---|
| 111 | }
|
---|
[8725] | 112 | private double TotalEntropyValue {
|
---|
| 113 | set { TotalEntropyValueParameter.ActualValue = new DoubleValue(value); }
|
---|
| 114 | }
|
---|
[7128] | 115 | private double InformationStabilityValue {
|
---|
| 116 | set { InformationStabilityValueParameter.ActualValue = new DoubleValue(value); }
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | [StorableConstructor]
|
---|
[16573] | 120 | protected InformationAnalyzer(StorableConstructorFlag _) : base(_) { }
|
---|
[7128] | 121 | protected InformationAnalyzer(InformationAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
| 122 |
|
---|
| 123 | public InformationAnalyzer() {
|
---|
| 124 | Parameters.Add(new LookupParameter<DataTable>("Quality Trail", "The qualities of the solutions"));
|
---|
| 125 | Parameters.Add(new LookupParameter<InformationStabilityTable>("Information Stability", "Information stability development over time"));
|
---|
| 126 | Parameters.Add(new LookupParameter<InformationAnalysisTable>("Information", "A data table that information theoretic fitness landscape characteristics"));
|
---|
| 127 | Parameters.Add(new LookupParameter<VariableCollection>("Results", "The collection of all results of this algorithm"));
|
---|
[8744] | 128 |
|
---|
[7128] | 129 | Parameters.Add(new ValueLookupParameter<IntValue>("NQuantiles", "The number of delta quantiles to display", new IntValue(20)));
|
---|
[8744] | 130 | Parameters.Add(new ValueLookupParameter<IntValue>("ShapeSize", "The number of slopes to consider as shapes.", new IntValue(2)));
|
---|
| 131 |
|
---|
[7128] | 132 | Parameters.Add(new LookupParameter<DoubleValue>("InformationContentValue", "The information content H(0) at eps = 0"));
|
---|
| 133 | Parameters.Add(new LookupParameter<DoubleValue>("PartialInformationContentValue", "Partial information content M(0) at eps = 0"));
|
---|
| 134 | Parameters.Add(new LookupParameter<DoubleValue>("DensityBasinInformationValue", "Density Basin Information h(0) at eps = 0"));
|
---|
[8725] | 135 | Parameters.Add(new LookupParameter<DoubleValue>("TotalEntropyValue", "The overall disorder in the trajectory"));
|
---|
[7128] | 136 | Parameters.Add(new LookupParameter<DoubleValue>("InformationStabilityValue", "Information Stability Value"));
|
---|
| 137 | Parameters.Add(new LookupParameter<IntValue>("RegularityValue", "The number of different quality differences"));
|
---|
[8725] | 138 | Parameters.Add(new LookupParameter<IntValue>("DiversityValue", "The number of different quality values"));
|
---|
| 139 | Parameters.Add(new LookupParameter<DoubleValue>("PeakInformationContent", "Maximum information content at any quality delta."));
|
---|
| 140 | Parameters.Add(new LookupParameter<DoubleValue>("PeakInformationContentQualityDelta", "Quality delta with maximum information content."));
|
---|
| 141 | Parameters.Add(new LookupParameter<DoubleValue>("PeakDensityBasinInformation", "Maximum density basin information at any quality delta."));
|
---|
| 142 | Parameters.Add(new LookupParameter<DoubleValue>("PeakDensityBasinInformationQualityDelta", "Quality delta with maximum density basin information."));
|
---|
[7128] | 143 |
|
---|
| 144 | var resultsCollector = new ResultsCollector();
|
---|
| 145 | resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(InformationParameter.Name));
|
---|
| 146 | resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(InformationStabilityParameter.Name));
|
---|
| 147 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(InformationContentValueParameter.Name));
|
---|
| 148 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PartialInformationContentValueParameter.Name));
|
---|
| 149 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(DensityBasinInformationValueParameter.Name));
|
---|
[8725] | 150 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(TotalEntropyValueParameter.Name));
|
---|
[7128] | 151 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(InformationStabilityValueParameter.Name));
|
---|
| 152 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(RegularityValueParameter.Name));
|
---|
[8725] | 153 | resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(DiversityValueParameter.Name));
|
---|
| 154 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PeakInformationContentParameter.Name));
|
---|
| 155 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PeakInformationContentQualityDeltaParameter.Name));
|
---|
| 156 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PeakDensityBasinInformationParameter.Name));
|
---|
| 157 | resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PeakDensityBasinInformationQualityDeltaParameter.Name));
|
---|
[7128] | 158 |
|
---|
| 159 | OperatorGraph.InitialOperator = resultsCollector;
|
---|
| 160 | resultsCollector.Successor = null;
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 164 | return new InformationAnalyzer(this, cloner);
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | public override IOperation Apply() {
|
---|
| 168 | DataTable qualityTrail = QualityTrailParameter.ActualValue;
|
---|
| 169 | if (qualityTrail != null && qualityTrail.Rows.Count > 0) {
|
---|
| 170 | EnsureExistsInformationStabilityTable();
|
---|
| 171 | EnsureExistsInformationTable();
|
---|
| 172 | AnalyseInformation();
|
---|
| 173 | }
|
---|
| 174 | return base.Apply();
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | private void AnalyseInformation() {
|
---|
| 178 | int nQuantiles = NQuantilesParameter.ActualValue.Value;
|
---|
[8744] | 179 | int shapeSize = ShapeSizeParameter.ActualValue.Value;
|
---|
[7128] | 180 | var qualities = QualityTrailParameter.ActualValue.Rows.First().Values.ToList();
|
---|
[9142] | 181 | if (qualities.Count > 2) {
|
---|
[7128] | 182 | InformationAnalysisTable informationTable = InformationParameter.ActualValue;
|
---|
| 183 | var informationContent = informationTable.Rows["Information Content"].Values;
|
---|
| 184 | var partialInformationContent = informationTable.Rows["Partial Information Content"].Values;
|
---|
| 185 | var densityBasinInformation = informationTable.Rows["Density Basin Information"].Values;
|
---|
[8725] | 186 | var totalEntropy = informationTable.Rows["Total Entropy"].Values;
|
---|
[7128] | 187 | var qualityDelta = informationTable.Rows["Quality Delta"].Values;
|
---|
[8744] | 188 | var analysis = new InformationAnalysis(qualities, nQuantiles, shapeSize);
|
---|
[7128] | 189 | InformationStability.Rows["Regularity"].Values.Add(analysis.Regularity);
|
---|
[8725] | 190 | InformationStability.Rows["Diversity"].Values.Add(analysis.Diversity);
|
---|
[8744] | 191 | InformationStability.Rows["Relative Regularity"].Values.Add(1.0*analysis.Regularity/qualities.Count);
|
---|
| 192 | InformationStability.Rows["Relative Diversity"].Values.Add(1.0*analysis.Diversity/qualities.Count);
|
---|
[7128] | 193 | InformationStability.Rows["Information Stability"].Values.Add(analysis.InformationStability);
|
---|
| 194 | informationContent.Clear();
|
---|
| 195 | informationContent.AddRange(analysis.InformationContent);
|
---|
| 196 | partialInformationContent.Clear();
|
---|
| 197 | partialInformationContent.AddRange(analysis.PartialInformationContent);
|
---|
| 198 | densityBasinInformation.Clear();
|
---|
| 199 | densityBasinInformation.AddRange(analysis.DensityBasinInformation);
|
---|
[8725] | 200 | totalEntropy.Clear();
|
---|
| 201 | totalEntropy.AddRange(analysis.TotalEntropy);
|
---|
[7128] | 202 | qualityDelta.Clear();
|
---|
| 203 | qualityDelta.AddRange(analysis.QualityDelta);
|
---|
| 204 | InformationContentValue = analysis.InformationContent.FirstOrDefault();
|
---|
| 205 | PartialInformationContentValue = analysis.PartialInformationContent.FirstOrDefault();
|
---|
| 206 | DensityBasinInformationValue = analysis.DensityBasinInformation.FirstOrDefault();
|
---|
| 207 | InformationStabilityValue = analysis.InformationStability;
|
---|
| 208 | RegularityValueParameter.ActualValue = new IntValue(analysis.Regularity);
|
---|
[8725] | 209 | DiversityValueParameter.ActualValue = new IntValue(analysis.Diversity);
|
---|
[8744] | 210 | if (analysis.PeakInformationContent != null) {
|
---|
| 211 | PeakInformationContentParameter.ActualValue = new DoubleValue(analysis.PeakInformationContent.Value);
|
---|
| 212 | PeakInformationContentQualityDeltaParameter.ActualValue = new DoubleValue(analysis.PeakInformationContent.QualityDelta);
|
---|
| 213 | }
|
---|
| 214 | if (analysis.PeakDensityBasinInformation != null) {
|
---|
| 215 | PeakDensityBasinInformationParameter.ActualValue = new DoubleValue(analysis.PeakDensityBasinInformation.Value);
|
---|
| 216 | PeakDensityBasinInformationQualityDeltaParameter.ActualValue = new DoubleValue(analysis.PeakDensityBasinInformation.QualityDelta);
|
---|
| 217 | }
|
---|
[7128] | 218 | }
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | private void EnsureExistsInformationTable() {
|
---|
| 222 | InformationAnalysisTable information = InformationParameter.ActualValue;
|
---|
| 223 | if (information == null) {
|
---|
| 224 | information = new InformationAnalysisTable("Information");
|
---|
| 225 | information.Rows.Add(new DataRow("Information Content"));
|
---|
| 226 | information.Rows.Add(new DataRow("Partial Information Content"));
|
---|
| 227 | information.Rows.Add(new DataRow("Density Basin Information"));
|
---|
[8725] | 228 | information.Rows.Add(new DataRow("Total Entropy"));
|
---|
| 229 | information.Rows.Add(new DataRow("Quality Delta") {VisualProperties = {SecondYAxis = true}});
|
---|
[7128] | 230 | InformationParameter.ActualValue = information;
|
---|
| 231 | }
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | private void EnsureExistsInformationStabilityTable() {
|
---|
| 235 | InformationStabilityTable informationStability = InformationStabilityParameter.ActualValue;
|
---|
| 236 | if (informationStability == null) {
|
---|
| 237 | informationStability = new InformationStabilityTable("Information Stability");
|
---|
| 238 | informationStability.Rows.Add(new DataRow("Information Stability"));
|
---|
| 239 | informationStability.Rows.Add(new DataRow("Relative Regularity"));
|
---|
[8725] | 240 | informationStability.Rows.Add(new DataRow("Relative Diversity"));
|
---|
| 241 | informationStability.Rows.Add(new DataRow("Regularity") {VisualProperties = {SecondYAxis = true}});
|
---|
| 242 | informationStability.Rows.Add(new DataRow("Diversity") {VisualProperties = {SecondYAxis = true}});
|
---|
[7128] | 243 | InformationStabilityParameter.ActualValue = informationStability;
|
---|
| 244 | }
|
---|
| 245 | }
|
---|
| 246 | }
|
---|
| 247 | }
|
---|