[7128] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using HeuristicLab.Analysis.FitnessLandscape.DataTables;
|
---|
| 5 | using HeuristicLab.Common;
|
---|
| 6 | using HeuristicLab.Core;
|
---|
| 7 | using HeuristicLab.Data;
|
---|
| 8 | using HeuristicLab.Operators;
|
---|
| 9 | using HeuristicLab.Optimization;
|
---|
| 10 | using HeuristicLab.Parameters;
|
---|
[16573] | 11 | using HEAL.Attic;
|
---|
[7128] | 12 |
|
---|
| 13 | namespace HeuristicLab.Analysis.FitnessLandscape.Algorithms {
|
---|
| 14 |
|
---|
| 15 | [Item("RepeatedInformationAnalyzer", "Analyzes and consolidates repeated information analyses.")]
|
---|
[16573] | 16 | [StorableType("A53A3F9B-BC38-47E9-B435-42DEA10A4ABC")]
|
---|
[7128] | 17 | public class RepeatedInformationAnalyzer : SingleSuccessorOperator, IRepeatsAnalyzer {
|
---|
| 18 |
|
---|
| 19 | #region Parameters
|
---|
| 20 | public ScopeTreeLookupParameter<InformationAnalysisTable> InformationsParameter {
|
---|
| 21 | get { return (ScopeTreeLookupParameter<InformationAnalysisTable>)Parameters["Information"]; }
|
---|
| 22 | }
|
---|
| 23 | public ScopeTreeLookupParameter<DoubleValue> InformationContentValuesParameter {
|
---|
| 24 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["InformationContentValue"]; }
|
---|
| 25 | }
|
---|
| 26 | public ScopeTreeLookupParameter<DoubleValue> PartialInformationContentValuesParameter {
|
---|
| 27 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["PartialInformationContentValue"]; }
|
---|
| 28 | }
|
---|
| 29 | public ScopeTreeLookupParameter<DoubleValue> DensityBasinInformationValuesParameter {
|
---|
| 30 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["DensityBasinInformationValue"]; }
|
---|
| 31 | }
|
---|
| 32 | public ScopeTreeLookupParameter<DoubleValue> InformationStabilityValuesParameter {
|
---|
| 33 | get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["InformationStabilityValue"]; }
|
---|
| 34 | }
|
---|
| 35 | public ScopeTreeLookupParameter<IntValue> RegularityValuesParameter {
|
---|
| 36 | get { return (ScopeTreeLookupParameter<IntValue>)Parameters["RegularityValue"]; }
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | public LookupParameter<ResultCollection> ResultsParameter {
|
---|
| 40 | get { return (LookupParameter<ResultCollection>)Parameters["Results"]; }
|
---|
| 41 | }
|
---|
| 42 | #endregion
|
---|
| 43 |
|
---|
| 44 | #region Construction & Cloning
|
---|
| 45 | [StorableConstructor]
|
---|
[16573] | 46 | protected RepeatedInformationAnalyzer(StorableConstructorFlag _) : base(_) { }
|
---|
[7128] | 47 | protected RepeatedInformationAnalyzer(RepeatedInformationAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
| 48 | public RepeatedInformationAnalyzer() {
|
---|
| 49 | Parameters.Add(new ScopeTreeLookupParameter<InformationAnalysisTable>("Information", "A data table that information theoretic fitness landscape characteristics"));
|
---|
| 50 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("InformationContentValue", "The information content H(0) at eps = 0"));
|
---|
| 51 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("PartialInformationContentValue", "Partial information content M(0) at eps = 0"));
|
---|
| 52 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("DensityBasinInformationValue", "Density Basin Information h(0) at eps = 0"));
|
---|
| 53 | Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("InformationStabilityValue", "Information Stability Value"));
|
---|
| 54 | Parameters.Add(new ScopeTreeLookupParameter<IntValue>("RegularityValue", "The number of different quality differences"));
|
---|
| 55 | Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection of all results of this algorithm"));
|
---|
| 56 | InformationsParameter.Depth = 2;
|
---|
| 57 | InformationContentValuesParameter.Depth = 2;
|
---|
| 58 | PartialInformationContentValuesParameter.Depth = 2;
|
---|
| 59 | DensityBasinInformationValuesParameter.Depth = 2;
|
---|
| 60 | InformationStabilityValuesParameter.Depth = 2;
|
---|
| 61 | RegularityValuesParameter.Depth = 2;
|
---|
| 62 | }
|
---|
| 63 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 64 | return new RepeatedInformationAnalyzer(this, cloner);
|
---|
| 65 | }
|
---|
| 66 | #endregion
|
---|
| 67 |
|
---|
| 68 | private class Entry : IComparable<Entry> {
|
---|
| 69 |
|
---|
| 70 | public double InformationContent { get; private set; }
|
---|
| 71 | public double PartialInformationContent { get; private set; }
|
---|
| 72 | public double DensityBasinInformation { get; private set; }
|
---|
| 73 | public double Epsilon { get; private set; }
|
---|
| 74 |
|
---|
| 75 | public Entry(double epsilon, double informationContent, double partialInformationContent, double densityBasinInformation) {
|
---|
| 76 | Epsilon = epsilon;
|
---|
| 77 | InformationContent = informationContent;
|
---|
| 78 | PartialInformationContent = partialInformationContent;
|
---|
| 79 | DensityBasinInformation = densityBasinInformation;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | public int CompareTo(Entry other) {
|
---|
| 83 | return Epsilon.CompareTo(other.Epsilon);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | public override bool Equals(object obj) {
|
---|
| 87 | Entry e = obj as Entry;
|
---|
| 88 | if (e == null)
|
---|
| 89 | throw new NotSupportedException();
|
---|
| 90 | return this.Epsilon == e.Epsilon;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | public override int GetHashCode() {
|
---|
| 94 | return Epsilon.GetHashCode();
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | public override IOperation Apply() {
|
---|
| 100 | ResultCollection results = ResultsParameter.ActualValue;
|
---|
| 101 | var informationTables = InformationsParameter.ActualValue.ToList();
|
---|
| 102 | List<Entry> entries = new List<Entry>();
|
---|
| 103 | foreach (var t in informationTables) {
|
---|
| 104 | var values = t.Rows["Quality Delta"].Values;
|
---|
| 105 | var info = t.Rows["Information Content"].Values;
|
---|
| 106 | var partInfo = t.Rows["Partial Information Content"].Values;
|
---|
| 107 | var densBas = t.Rows["Density Basin Information"].Values;
|
---|
| 108 | var eps = t.Rows["Quality Delta"].Values;
|
---|
| 109 | for (int i = 0; i < info.Count; i++) {
|
---|
| 110 | entries.Add(new Entry(eps[i], info[i], partInfo[i], densBas[i]));
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 | entries.Sort();
|
---|
| 114 | double informationSum = 0;
|
---|
| 115 | double partialInformationSum = 0;
|
---|
| 116 | double densityBasinSum = 0;
|
---|
| 117 | double epsilonSum = 0;
|
---|
| 118 | DataRow informationRow = new DataRow("Information Content");
|
---|
| 119 | DataRow partialInformationRow = new DataRow("Partial Information Content");
|
---|
| 120 | DataRow densityBasinRow = new DataRow("Density Basin Information");
|
---|
| 121 | DataRow epsilonRow = new DataRow("Quality Delta");
|
---|
| 122 | epsilonRow.VisualProperties.SecondYAxis = true;
|
---|
| 123 | int n = 0;
|
---|
| 124 | foreach (var entry in entries) {
|
---|
| 125 | informationSum += entry.InformationContent;
|
---|
| 126 | partialInformationSum += entry.PartialInformationContent;
|
---|
| 127 | densityBasinSum += entry.DensityBasinInformation;
|
---|
| 128 | epsilonSum += entry.Epsilon;
|
---|
| 129 | n++;
|
---|
| 130 | if (n == informationTables.Count) {
|
---|
| 131 | informationRow.Values.Add(informationSum/n); informationSum = 0;
|
---|
| 132 | partialInformationRow.Values.Add(partialInformationSum/n); partialInformationSum = 0;
|
---|
| 133 | densityBasinRow.Values.Add(densityBasinSum/n); densityBasinSum = 0;
|
---|
| 134 | epsilonRow.Values.Add(epsilonSum/n); epsilonSum = 0;
|
---|
| 135 | n = 0;
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
| 138 | if (n > 0) {
|
---|
| 139 | informationRow.Values.Add(informationSum / n);
|
---|
| 140 | partialInformationRow.Values.Add(partialInformationSum / n);
|
---|
| 141 | densityBasinRow.Values.Add(densityBasinSum / n);
|
---|
| 142 | epsilonRow.Values.Add(epsilonSum / n);
|
---|
| 143 | }
|
---|
| 144 | InformationAnalysisTable table = new InformationAnalysisTable("Avg. Information Analysis");
|
---|
| 145 | table.Rows.Add(informationRow);
|
---|
| 146 | table.Rows.Add(partialInformationRow);
|
---|
| 147 | table.Rows.Add(densityBasinRow);
|
---|
| 148 | table.Rows.Add(epsilonRow);
|
---|
| 149 | results.Remove("Information");
|
---|
| 150 | results.Add(new Result("Information", table));
|
---|
| 151 |
|
---|
| 152 | results.Remove("InformationContentValue");
|
---|
| 153 | results.Remove("PartialInformationContentValue");
|
---|
| 154 | results.Remove("DensityBasinInformationValue");
|
---|
| 155 | results.Remove("InformationStabilityValue");
|
---|
| 156 | results.Add(new Result("InformationContentValue", new DoubleValue(InformationContentValuesParameter.ActualValue.Select(v => v.Value).Average())));
|
---|
| 157 | results.Add(new Result("PartialInformationContentValue", new DoubleValue(PartialInformationContentValuesParameter.ActualValue.Select(v => v.Value).Average())));
|
---|
| 158 | results.Add(new Result("DensityBasinInformationValue", new DoubleValue(DensityBasinInformationValuesParameter.ActualValue.Select(v => v.Value).Average())));
|
---|
| 159 | results.Add(new Result("InformationStabilityValue", new DoubleValue(InformationStabilityValuesParameter.ActualValue.Select(v => v.Value).Average())));
|
---|
| 160 |
|
---|
| 161 | return base.Apply();
|
---|
| 162 | }
|
---|
| 163 | }
|
---|
| 164 | }
|
---|