Changeset 13583 for branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis
- Timestamp:
- 02/02/16 14:10:53 (9 years ago)
- Location:
- branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape
- Files:
-
- 1 added
- 6 deleted
- 9 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/EnumerableExtensions.cs
r7128 r13583 19 19 */ 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 24 23 25 namespace HeuristicLab.Analysis.FitnessLandscape { 24 26 -
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/FitnessCloudAnalyzer.cs
r7176 r13583 19 19 */ 20 20 #endregion 21 21 22 using System.Drawing; 22 23 using System.Linq; … … 28 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 30 30 namespace HeuristicLab.Analysis.FitnessLandscape .Analysis{31 namespace HeuristicLab.Analysis.FitnessLandscape { 31 32 32 33 [StorableClass] -
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/IQualityTrailAnalyzer.cs
r7128 r13583 19 19 */ 20 20 #endregion 21 21 22 using HeuristicLab.Optimization; 23 22 24 namespace HeuristicLab.Analysis.FitnessLandscape { 23 25 public interface IQualityTrailAnalyzer : IAnalyzer { } -
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/InformationAnalysis.cs
r9142 r13583 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2016 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 System; 2 23 using System.Collections.Generic; 3 24 using System.Linq; 4 25 5 namespace HeuristicLab.Analysis.FitnessLandscape .Analysis{26 namespace HeuristicLab.Analysis.FitnessLandscape { 6 27 7 28 public class InformationAnalysis { … … 19 40 public List<double> PartialInformationContent { get; private set; } 20 41 public List<double> DensityBasinInformation { get; private set; } 21 public List<double> TotalEntropy { get; private set; } 42 public List<double> TotalEntropy { get; private set; } 22 43 public List<double> QualityDelta { get; private set; } 23 44 public double InformationStability { get; private set; } … … 89 110 90 111 #region types, fields and properties 91 public enum Form { Uni, NonUni, Any}112 public enum Form { Uni, NonUni, Any } 92 113 93 114 private readonly Slope[] slopes; 94 115 95 116 private static readonly Dictionary<Tuple<Form, int>, IList<Shape>> SHAPES = 96 new Dictionary<Tuple<Form, int>,IList<Shape>>();117 new Dictionary<Tuple<Form, int>, IList<Shape>>(); 97 118 #endregion 98 119 … … 130 151 131 152 private Shape Extend(Slope s) { 132 return new Shape(slopes.Concat(new[] { s}));153 return new Shape(slopes.Concat(new[] { s })); 133 154 } 134 155 … … 157 178 #region IEnumerable Members 158 179 public IEnumerator<Slope> GetEnumerator() { 159 return (IEnumerator<Slope>) 180 return (IEnumerator<Slope>)slopes.GetEnumerator(); 160 181 } 161 182 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { … … 171 192 if (other.Length > Length) 172 193 return 1; 173 for (var i = 0; i <Length; i++) {194 for (var i = 0; i < Length; i++) { 174 195 var d = slopes[i].CompareTo(other.slopes[i]); 175 196 if (d != 0) … … 184 205 } 185 206 public override int GetHashCode() { 186 return slopes.Aggregate(0, (a, s) => a *3 + ((int)s + 1)).GetHashCode();207 return slopes.Aggregate(0, (a, s) => a * 3 + ((int)s + 1)).GetHashCode(); 187 208 } 188 209 … … 197 218 private static IEnumerable<Slope> Slopes(double eps, IEnumerable<double> differences) { 198 219 return differences.Select(d => (d > eps ? Slope.Up : (d < -eps ? Slope.Down : 0))); 199 } 220 } 200 221 201 222 private static IEnumerable<Shape> Shapes(int size, IEnumerable<Slope> slopes) { … … 243 264 244 265 private static IEnumerable<double> Differences(IEnumerable<double> values) { 245 return Utils.Delta(values,(x, y) => y - x);266 return values.Delta((x, y) => y - x); 246 267 } 247 268 -
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/InformationAnalyzer.cs
r9142 r13583 20 20 #endregion 21 21 22 using System;23 using System.Linq;24 using HeuristicLab.Analysis.FitnessLandscape.DataTables;25 22 using HeuristicLab.Common; 26 23 using HeuristicLab.Core; 27 24 using HeuristicLab.Data; 28 25 using HeuristicLab.Operators; 29 using HeuristicLab.Optimization .Operators;26 using HeuristicLab.Optimization; 30 27 using HeuristicLab.Parameters; 31 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using System.Linq; 32 30 33 namespace HeuristicLab.Analysis.FitnessLandscape .Analysis{31 namespace HeuristicLab.Analysis.FitnessLandscape { 34 32 35 33 [StorableClass] 36 public class InformationAnalyzer : AlgorithmOperator, IQualityTrailAnalyzer {34 public class InformationAnalyzer : SingleSuccessorOperator, IQualityTrailAnalyzer { 37 35 public bool EnabledByDefault { 38 36 get { return false; } … … 43 41 get { return (LookupParameter<DataTable>)Parameters["Quality Trail"]; } 44 42 } 45 public LookupParameter<InformationStabilityTable> InformationStabilityParameter { 46 get { return (LookupParameter<InformationStabilityTable>)Parameters["Information Stability"]; } 47 } 48 public LookupParameter<InformationAnalysisTable> InformationParameter { 49 get { return (LookupParameter<InformationAnalysisTable>)Parameters["Information"]; } 50 } 51 public LookupParameter<VariableCollection> ResultsParameter { 52 get { return (LookupParameter<VariableCollection>)Parameters["Results"]; } 43 public LookupParameter<ResultCollection> ResultsParameter { 44 get { return (LookupParameter<ResultCollection>)Parameters["Results"]; } 53 45 } 54 46 public ValueLookupParameter<IntValue> NQuantilesParameter { … … 58 50 get { return (ValueLookupParameter<IntValue>)Parameters["ShapeSize"]; } 59 51 } 60 public LookupParameter<DoubleValue> InformationContent ValueParameter {61 get { return (LookupParameter<DoubleValue>)Parameters["InformationContent Value"]; }52 public LookupParameter<DoubleValue> InformationContentParameter { 53 get { return (LookupParameter<DoubleValue>)Parameters["InformationContent"]; } 62 54 } 63 public LookupParameter<DoubleValue> PartialInformationContent ValueParameter {64 get { return (LookupParameter<DoubleValue>)Parameters["PartialInformationContent Value"]; }55 public LookupParameter<DoubleValue> PartialInformationContentParameter { 56 get { return (LookupParameter<DoubleValue>)Parameters["PartialInformationContent"]; } 65 57 } 66 public LookupParameter<DoubleValue> DensityBasinInformation ValueParameter {67 get { return (LookupParameter<DoubleValue>)Parameters["DensityBasinInformation Value"]; }58 public LookupParameter<DoubleValue> DensityBasinInformationParameter { 59 get { return (LookupParameter<DoubleValue>)Parameters["DensityBasinInformation"]; } 68 60 } 69 public LookupParameter<DoubleValue> TotalEntropy ValueParameter {70 get { return (LookupParameter<DoubleValue>)Parameters["TotalEntropy Value"]; }61 public LookupParameter<DoubleValue> TotalEntropyParameter { 62 get { return (LookupParameter<DoubleValue>)Parameters["TotalEntropy"]; } 71 63 } 72 public LookupParameter<DoubleValue> InformationStability ValueParameter {73 get { return (LookupParameter<DoubleValue>)Parameters["InformationStability Value"]; }64 public LookupParameter<DoubleValue> InformationStabilityParameter { 65 get { return (LookupParameter<DoubleValue>)Parameters["InformationStability"]; } 74 66 } 75 public LookupParameter< IntValue> RegularityValueParameter {76 get { return (LookupParameter< IntValue>)Parameters["RegularityValue"]; }67 public LookupParameter<DoubleValue> RegularityParameter { 68 get { return (LookupParameter<DoubleValue>)Parameters["Regularity"]; } 77 69 } 78 public LookupParameter< IntValue> DiversityValueParameter {79 get { return (LookupParameter< IntValue>)Parameters["DiversityValue"]; }70 public LookupParameter<DoubleValue> DiversityParameter { 71 get { return (LookupParameter<DoubleValue>)Parameters["Diversity"]; } 80 72 } 81 82 #region Peaks83 73 public LookupParameter<DoubleValue> PeakInformationContentParameter { 84 get { return (LookupParameter<DoubleValue>) Parameters["PeakInformationContent"]; } 85 } 86 public LookupParameter<DoubleValue> PeakInformationContentQualityDeltaParameter { 87 get { return (LookupParameter<DoubleValue>) Parameters["PeakInformationContentQualityDelta"]; } 74 get { return (LookupParameter<DoubleValue>)Parameters["PeakInformationContent"]; } 88 75 } 89 76 public LookupParameter<DoubleValue> PeakDensityBasinInformationParameter { 90 get { return (LookupParameter<DoubleValue>) 77 get { return (LookupParameter<DoubleValue>)Parameters["PeakDensityBasinInformation"]; } 91 78 } 92 public LookupParameter<DoubleValue> PeakDensityBasinInformationQualityDeltaParameter {93 get { return (LookupParameter<DoubleValue>) Parameters["PeakDensityBasinInformationQualityDelta"]; }94 }95 96 97 79 #endregion 98 99 #endregion100 101 private InformationStabilityTable InformationStability {102 get { return InformationStabilityParameter.ActualValue; }103 }104 private double InformationContentValue {105 set { InformationContentValueParameter.ActualValue = new DoubleValue(value); }106 }107 private double PartialInformationContentValue {108 set { PartialInformationContentValueParameter.ActualValue = new DoubleValue(value); }109 }110 private double DensityBasinInformationValue {111 set { DensityBasinInformationValueParameter.ActualValue = new DoubleValue(value); }112 }113 private double TotalEntropyValue {114 set { TotalEntropyValueParameter.ActualValue = new DoubleValue(value); }115 }116 private double InformationStabilityValue {117 set { InformationStabilityValueParameter.ActualValue = new DoubleValue(value); }118 }119 80 120 81 [StorableConstructor] … … 124 85 public InformationAnalyzer() { 125 86 Parameters.Add(new LookupParameter<DataTable>("Quality Trail", "The qualities of the solutions")); 126 Parameters.Add(new LookupParameter<InformationStabilityTable>("Information Stability", "Information stability development over time")); 127 Parameters.Add(new LookupParameter<InformationAnalysisTable>("Information", "A data table that information theoretic fitness landscape characteristics")); 128 Parameters.Add(new LookupParameter<VariableCollection>("Results", "The collection of all results of this algorithm")); 87 Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection of all results of this algorithm")); 129 88 130 89 Parameters.Add(new ValueLookupParameter<IntValue>("NQuantiles", "The number of delta quantiles to display", new IntValue(20))); 131 90 Parameters.Add(new ValueLookupParameter<IntValue>("ShapeSize", "The number of slopes to consider as shapes.", new IntValue(2))); 132 91 133 Parameters.Add(new LookupParameter<DoubleValue>("InformationContent Value", "The information content H(0) at eps = 0"));134 Parameters.Add(new LookupParameter<DoubleValue>("PartialInformationContent Value", "Partial information content M(0) at eps = 0"));135 Parameters.Add(new LookupParameter<DoubleValue>("DensityBasinInformation Value", "Density Basin Information h(0) at eps = 0"));136 Parameters.Add(new LookupParameter<DoubleValue>("TotalEntropy Value", "The overall disorder in the trajectory"));137 Parameters.Add(new LookupParameter<DoubleValue>("InformationStability Value", "Information Stability Value"));138 Parameters.Add(new LookupParameter< IntValue>("RegularityValue", "The number of different quality differences"));139 Parameters.Add(new LookupParameter< IntValue>("DiversityValue", "The number of different quality values"));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")); 140 99 Parameters.Add(new LookupParameter<DoubleValue>("PeakInformationContent", "Maximum information content at any quality delta.")); 141 Parameters.Add(new LookupParameter<DoubleValue>("PeakInformationContentQualityDelta", "Quality delta with maximum information content."));142 100 Parameters.Add(new LookupParameter<DoubleValue>("PeakDensityBasinInformation", "Maximum density basin information at any quality delta.")); 143 Parameters.Add(new LookupParameter<DoubleValue>("PeakDensityBasinInformationQualityDelta", "Quality delta with maximum density basin information."));144 145 var resultsCollector = new ResultsCollector();146 resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(InformationParameter.Name));147 resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(InformationStabilityParameter.Name));148 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(InformationContentValueParameter.Name));149 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PartialInformationContentValueParameter.Name));150 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(DensityBasinInformationValueParameter.Name));151 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(TotalEntropyValueParameter.Name));152 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(InformationStabilityValueParameter.Name));153 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(RegularityValueParameter.Name));154 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(DiversityValueParameter.Name));155 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PeakInformationContentParameter.Name));156 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PeakInformationContentQualityDeltaParameter.Name));157 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PeakDensityBasinInformationParameter.Name));158 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PeakDensityBasinInformationQualityDeltaParameter.Name));159 160 OperatorGraph.InitialOperator = resultsCollector;161 resultsCollector.Successor = null;162 101 } 163 102 … … 167 106 168 107 public override IOperation Apply() { 169 DataTable qualityTrail = QualityTrailParameter.ActualValue; 170 if (qualityTrail != null && qualityTrail.Rows.Count > 0) { 171 EnsureExistsInformationStabilityTable(); 172 EnsureExistsInformationTable(); 173 AnalyseInformation(); 174 } 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 175 147 return base.Apply(); 176 148 } 177 149 178 private void AnalyseInformation() { 179 int nQuantiles = NQuantilesParameter.ActualValue.Value; 180 int shapeSize = ShapeSizeParameter.ActualValue.Value; 181 var qualities = QualityTrailParameter.ActualValue.Rows.First().Values.ToList(); 182 if (qualities.Count > 2) { 183 InformationAnalysisTable informationTable = InformationParameter.ActualValue; 184 var informationContent = informationTable.Rows["Information Content"].Values; 185 var partialInformationContent = informationTable.Rows["Partial Information Content"].Values; 186 var densityBasinInformation = informationTable.Rows["Density Basin Information"].Values; 187 var totalEntropy = informationTable.Rows["Total Entropy"].Values; 188 var qualityDelta = informationTable.Rows["Quality Delta"].Values; 189 var analysis = new InformationAnalysis(qualities, nQuantiles, shapeSize); 190 InformationStability.Rows["Regularity"].Values.Add(analysis.Regularity); 191 InformationStability.Rows["Diversity"].Values.Add(analysis.Diversity); 192 InformationStability.Rows["Relative Regularity"].Values.Add(1.0*analysis.Regularity/qualities.Count); 193 InformationStability.Rows["Relative Diversity"].Values.Add(1.0*analysis.Diversity/qualities.Count); 194 InformationStability.Rows["Information Stability"].Values.Add(analysis.InformationStability); 195 informationContent.Clear(); 196 informationContent.AddRange(analysis.InformationContent); 197 partialInformationContent.Clear(); 198 partialInformationContent.AddRange(analysis.PartialInformationContent); 199 densityBasinInformation.Clear(); 200 densityBasinInformation.AddRange(analysis.DensityBasinInformation); 201 totalEntropy.Clear(); 202 totalEntropy.AddRange(analysis.TotalEntropy); 203 qualityDelta.Clear(); 204 qualityDelta.AddRange(analysis.QualityDelta); 205 InformationContentValue = analysis.InformationContent.FirstOrDefault(); 206 PartialInformationContentValue = analysis.PartialInformationContent.FirstOrDefault(); 207 DensityBasinInformationValue = analysis.DensityBasinInformation.FirstOrDefault(); 208 InformationStabilityValue = analysis.InformationStability; 209 RegularityValueParameter.ActualValue = new IntValue(analysis.Regularity); 210 DiversityValueParameter.ActualValue = new IntValue(analysis.Diversity); 211 if (analysis.PeakInformationContent != null) { 212 PeakInformationContentParameter.ActualValue = new DoubleValue(analysis.PeakInformationContent.Value); 213 PeakInformationContentQualityDeltaParameter.ActualValue = new DoubleValue(analysis.PeakInformationContent.QualityDelta); 214 } 215 if (analysis.PeakDensityBasinInformation != null) { 216 PeakDensityBasinInformationParameter.ActualValue = new DoubleValue(analysis.PeakDensityBasinInformation.Value); 217 PeakDensityBasinInformationQualityDeltaParameter.ActualValue = new DoubleValue(analysis.PeakDensityBasinInformation.QualityDelta); 218 } 219 } 220 } 221 222 private void EnsureExistsInformationTable() { 223 InformationAnalysisTable information = InformationParameter.ActualValue; 224 if (information == null) { 225 information = new InformationAnalysisTable("Information"); 226 information.Rows.Add(new DataRow("Information Content")); 227 information.Rows.Add(new DataRow("Partial Information Content")); 228 information.Rows.Add(new DataRow("Density Basin Information")); 229 information.Rows.Add(new DataRow("Total Entropy")); 230 information.Rows.Add(new DataRow("Quality Delta") {VisualProperties = {SecondYAxis = true}}); 231 InformationParameter.ActualValue = information; 232 } 233 } 234 235 private void EnsureExistsInformationStabilityTable() { 236 InformationStabilityTable informationStability = InformationStabilityParameter.ActualValue; 237 if (informationStability == null) { 238 informationStability = new InformationStabilityTable("Information Stability"); 239 informationStability.Rows.Add(new DataRow("Information Stability")); 240 informationStability.Rows.Add(new DataRow("Relative Regularity")); 241 informationStability.Rows.Add(new DataRow("Relative Diversity")); 242 informationStability.Rows.Add(new DataRow("Regularity") {VisualProperties = {SecondYAxis = true}}); 243 informationStability.Rows.Add(new DataRow("Diversity") {VisualProperties = {SecondYAxis = true}}); 244 InformationStabilityParameter.ActualValue = informationStability; 245 } 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; 246 155 } 247 156 } -
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/QualityTrailMultiAnalyzer.cs
r10299 r13583 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 0Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System.Linq;23 using HeuristicLab.Collections;24 22 using HeuristicLab.Common; 25 23 using HeuristicLab.Core; … … 27 25 using HeuristicLab.Operators; 28 26 using HeuristicLab.Optimization; 29 using HeuristicLab.Optimization.Operators;30 27 using HeuristicLab.Parameters; 31 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 29 using HeuristicLab.PluginInfrastructure; 30 using System.Linq; 31 33 32 namespace HeuristicLab.Analysis.FitnessLandscape { 34 35 33 [Item("QualityTrailAnalyzer", "An analyzer that creates a quality trail which can be further analyzed by several analyzers.")] 36 34 [StorableClass] … … 44 42 } 45 43 46 public ValueLookupParameter<IntValue> UpdateIntervalParameter {47 get { return ( ValueLookupParameter<IntValue>)Parameters["QualityTrailUpdateInterval"]; }44 public IValueLookupParameter<IntValue> UpdateIntervalParameter { 45 get { return (IValueLookupParameter<IntValue>)Parameters["QualityTrailUpdateInterval"]; } 48 46 } 49 public LookupParameter<IntValue> UpdateCounterParameter {50 get { return ( LookupParameter<IntValue>)Parameters["QualityTrailUpdateCounter"]; }47 public ILookupParameter<IntValue> UpdateCounterParameter { 48 get { return (ILookupParameter<IntValue>)Parameters["QualityTrailUpdateCounter"]; } 51 49 } 52 public ValueLookupParameter<DataTable> QualityTrailParameter {53 get { return ( ValueLookupParameter<DataTable>)Parameters["Quality Trail"]; }50 public ILookupParameter<DataTable> QualityTrailParameter { 51 get { return (ILookupParameter<DataTable>)Parameters["Quality Trail"]; } 54 52 } 55 public LookupParameter<VariableCollection> ResultsParameter {56 get { return ( LookupParameter<VariableCollection>)Parameters["Results"]; }53 public ILookupParameter<ResultCollection> ResultsParameter { 54 get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; } 57 55 } 58 public LookupParameter<DoubleValue> QualityParameter {59 get { return ( LookupParameter<DoubleValue>)Parameters["Quality"]; }56 public IScopeTreeLookupParameter<DoubleValue> QualityParameter { 57 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 60 58 } 61 public ScopeTreeLookupParameter<DoubleValue> QualitiesParameter { 62 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Qualities"]; } 63 } 64 public OperatorParameter ResultsCollector { 65 get { return (OperatorParameter)Parameters["ResultsCollector"]; } 66 } 67 public LookupParameter<BoolValue> MaximizationParameter { 68 get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; } 59 public ILookupParameter<BoolValue> MaximizationParameter { 60 get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; } 69 61 } 70 62 … … 77 69 protected QualityTrailMultiAnalyzer(bool deserializing) : base(deserializing) { } 78 70 protected QualityTrailMultiAnalyzer(QualityTrailMultiAnalyzer original, Cloner cloner) : base(original, cloner) { } 79 80 71 public QualityTrailMultiAnalyzer() 81 72 : base() { 82 73 Parameters.Add(new ValueLookupParameter<IntValue>("QualityTrailUpdateInterval", "The interval at which the contained analyzers should be applied.", new IntValue(1))); 83 74 Parameters.Add(new LookupParameter<IntValue>("QualityTrailUpdateCounter", "The number of times the Analyzer was called since the last update.")); 84 Parameters.Add(new ValueLookupParameter<DataTable>("Quality Trail", "All historical quality values throughout the algorithm run")); 85 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "Single quality value from the current iteration/generation")); 86 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Qualities", "Quality values of the whole population", "Quality", 1)); 87 Parameters.Add(new LookupParameter<VariableCollection>("Results", "The collected results")); 88 Parameters.Add(new OperatorParameter("ResultsCollector")); 75 Parameters.Add(new LookupParameter<DataTable>("Quality Trail", "All historical quality values throughout the algorithm run")); 76 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "Quality values of the whole population", 1)); 77 Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collected results")); 89 78 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "Whether the problem is a maximization problem")); 90 79 91 foreach (var analyzer in ApplicationManager.Manager.GetInstances<IQualityTrailAnalyzer>()) 92 Operators.Add(analyzer); 93 94 var resultsCollector = new ResultsCollector(); 95 resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(QualityTrailParameter.Name)); 96 ResultsCollector.Value = resultsCollector; 80 foreach (var analyzer in ApplicationManager.Manager.GetInstances<IQualityTrailAnalyzer>()) { 81 Operators.Add(analyzer, !(analyzer is FitnessCloudAnalyzer)); 82 } 97 83 } 98 84 … … 102 88 103 89 public override IOperation InstrumentedApply() { 104 UpdateQualityTrail(); 105 106 IntValue interval = UpdateIntervalParameter.ActualValue; 107 if (interval == null) interval = new IntValue(1); 108 109 IntValue counter = UpdateCounterParameter.ActualValue; 110 if (counter == null) { 111 counter = new IntValue(interval.Value); 112 UpdateCounterParameter.ActualValue = counter; 113 } else counter.Value++; 114 115 OperationCollection next = new OperationCollection(); 116 next.Add(ExecutionContext.CreateOperation(ResultsCollector.Value)); 117 if (counter.Value == interval.Value) { 118 counter.Value = 0; 119 foreach (IndexedItem<IQualityTrailAnalyzer> item in Operators.CheckedItems) 120 next.Add(ExecutionContext.CreateOperation(item.Value)); 121 122 } 123 next.Add(base.InstrumentedApply()); 124 return next; 125 } 126 127 private void UpdateQualityTrail() { 128 DataTable qualityTrail = QualityTrailParameter.ActualValue; 90 var maximization = MaximizationParameter.ActualValue.Value; 91 var qualityTrail = QualityTrailParameter.ActualValue; 129 92 if (qualityTrail == null) { 130 93 qualityTrail = new DataTable("Quality Trail"); … … 132 95 QualityTrailParameter.ActualValue = qualityTrail; 133 96 } 134 if (QualityParameter.ActualValue != null) 135 qualityTrail.Rows["Qualities"].Values.Add(QualityParameter.ActualValue.Value); 136 if (QualitiesParameter.ActualName != null && 137 QualitiesParameter.ActualValue.Count() > 0 && 138 MaximizationParameter != null) 139 if (MaximizationParameter.ActualValue.Value) 140 qualityTrail.Rows["Qualities"].Values.Add(QualitiesParameter.ActualValue.Select(dv => dv.Value).Max()); 141 else 142 qualityTrail.Rows["Qualities"].Values.Add(QualitiesParameter.ActualValue.Select(dv => dv.Value).Min()); 97 var qualities = QualityParameter.ActualValue.Select(x => x.Value); 98 qualityTrail.Rows["Qualities"].Values.Add(maximization ? qualities.Max() : qualities.Min()); 143 99 100 var interval = UpdateIntervalParameter.ActualValue.Value; 101 var counter = UpdateCounterParameter.ActualValue; 102 if (counter == null) { 103 counter = new IntValue(0); 104 UpdateCounterParameter.ActualValue = counter; 105 } 106 counter.Value++; 107 108 var next = new OperationCollection(); 109 if (counter.Value % interval == 0) { 110 counter.Value = 0; 111 foreach (var item in Operators.CheckedItems) next.Add(ExecutionContext.CreateOperation(item.Value)); 112 } 113 next.Add(base.InstrumentedApply()); 114 return next; 144 115 } 145 116 } -
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/RuggednessAnalyzer.cs
r7176 r13583 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 0Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System.Linq;23 using HeuristicLab.Analysis.FitnessLandscape.DataTables;24 22 using HeuristicLab.Common; 25 23 using HeuristicLab.Core; 26 24 using HeuristicLab.Data; 27 25 using HeuristicLab.Operators; 28 using HeuristicLab.Optimization .Operators;26 using HeuristicLab.Optimization; 29 27 using HeuristicLab.Parameters; 30 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using System.Linq; 31 30 32 namespace HeuristicLab.Analysis.FitnessLandscape .Analysis{33 31 namespace HeuristicLab.Analysis.FitnessLandscape { 32 [Item("Ruggedness Analyzer", "Analyzes autocorrelation for one mutation step and correlation length.")] 34 33 [StorableClass] 35 public class RuggednessAnalyzer : AlgorithmOperator, IQualityTrailAnalyzer {34 public class RuggednessAnalyzer : SingleSuccessorOperator, IQualityTrailAnalyzer { 36 35 public bool EnabledByDefault { 37 36 get { return false; } … … 42 41 get { return (LookupParameter<DataTable>)Parameters["Quality Trail"]; } 43 42 } 44 public LookupParameter<DataTable> CorrelationLengthTableParameter { 45 get { return (LookupParameter<DataTable>)Parameters["CorrelationLengthTable"]; } 46 } 47 public LookupParameter<AutoCorrelationTable> AutocorrelationParameter { 48 get { return (LookupParameter<AutoCorrelationTable>)Parameters["Autocorrelation"]; } 49 } 50 public LookupParameter<VariableCollection> ResultsParameter { 51 get { return (LookupParameter<VariableCollection>)Parameters["Results"]; } 43 public LookupParameter<ResultCollection> ResultsParameter { 44 get { return (LookupParameter<ResultCollection>)Parameters["Results"]; } 52 45 } 53 46 public LookupParameter<DoubleValue> AutoCorrelation1Parameter { … … 62 55 protected RuggednessAnalyzer(bool deserializing) : base(deserializing) { } 63 56 protected RuggednessAnalyzer(RuggednessAnalyzer original, Cloner cloner) : base(original, cloner) { } 64 65 57 public RuggednessAnalyzer() { 66 58 Parameters.Add(new LookupParameter<DataTable>("Quality Trail", "The quality of the solution")); 67 Parameters.Add(new LookupParameter<DataTable>("CorrelationLengthTable", "Maximum nr of steps between statistically significantly correlated quality values")); 68 Parameters.Add(new LookupParameter<AutoCorrelationTable>("Autocorrelation", "Autocorrelation function of successive quality values")); 69 Parameters.Add(new LookupParameter<VariableCollection>("Results", "The collection of all results of this algorithm")); 59 Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection of all results of this algorithm")); 70 60 Parameters.Add(new LookupParameter<DoubleValue>("AutoCorrelation1", "Autocorrelation for one mutation step.")); 71 61 Parameters.Add(new LookupParameter<IntValue>("CorrelationLength", "The correlation length.")); 72 73 var resultsCollector = new ResultsCollector();74 resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(CorrelationLengthTableParameter.Name));75 resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(AutocorrelationParameter.Name));76 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(AutoCorrelation1Parameter.Name));77 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(CorrelationLengthParameter.Name));78 79 OperatorGraph.InitialOperator = resultsCollector;80 resultsCollector.Successor = null;81 62 } 82 63 … … 86 67 87 68 public override IOperation Apply() { 88 DataTable correlationLengthTable = GetOrCreateCorrelationLengthTable(); 89 AutoCorrelationTable autocorrelationTable = GetOrCreateAutoCorrelationTable(); 90 DataTable qualityTrail = QualityTrailParameter.ActualValue; 91 if (qualityTrail != null && qualityTrail.Rows.Count > 0) { 92 double[] autocorrelationValues; 93 int correlationLength = RuggednessCalculator.CalculateCorrelationLength(qualityTrail.Rows.First().Values.ToArray(), out autocorrelationValues); 94 correlationLengthTable.Rows["Correlation Length"].Values.Add(correlationLength); 95 autocorrelationTable.Rows["Auto Correlation"].Values.Clear(); 96 autocorrelationTable.Rows["Auto Correlation"].Values.AddRange(autocorrelationValues); 97 CorrelationLengthParameter.ActualValue = new IntValue(correlationLength); 98 AutoCorrelation1Parameter.ActualValue = new DoubleValue(autocorrelationValues.Length > 1 ? autocorrelationValues[1] : 0.0); 99 } 69 var qualityTrail = QualityTrailParameter.ActualValue; 70 if (qualityTrail == null || qualityTrail.Rows.Count <= 0) return base.Apply(); 71 var results = ResultsParameter.ActualValue; 72 double[] autocorrelationValues; 73 var correlationLength = RuggednessCalculator.CalculateCorrelationLength(qualityTrail.Rows.First().Values.ToArray(), out autocorrelationValues); 74 var cl = new IntValue(correlationLength); 75 CorrelationLengthParameter.ActualValue = cl; 76 AddOrUpdateResult(results, CorrelationLengthParameter.Name, cl); 77 var ac1 = new DoubleValue(autocorrelationValues.Length > 1 ? autocorrelationValues[1] : 0.0); 78 AutoCorrelation1Parameter.ActualValue = ac1; 79 AddOrUpdateResult(results, AutoCorrelation1Parameter.Name, ac1); 100 80 return base.Apply(); 101 81 } 102 82 103 private AutoCorrelationTable GetOrCreateAutoCorrelationTable() { 104 AutoCorrelationTable autocorrelationTable = AutocorrelationParameter.ActualValue; 105 if (autocorrelationTable == null) { 106 autocorrelationTable = new AutoCorrelationTable("Auto Correlation"); 107 AutocorrelationParameter.ActualValue = autocorrelationTable; 108 var row = new DataRow("Auto Correlation"); 109 row.VisualProperties.StartIndexZero = true; 110 autocorrelationTable.Rows.Add(row); 111 } 112 return autocorrelationTable; 113 } 114 115 private DataTable GetOrCreateCorrelationLengthTable() { 116 DataTable correlationLengthTable = CorrelationLengthTableParameter.ActualValue; 117 if (correlationLengthTable == null) { 118 correlationLengthTable = new DataTable("Correlation Length"); 119 CorrelationLengthTableParameter.ActualValue = correlationLengthTable; 120 correlationLengthTable.Rows.Add(new DataRow("Correlation Length")); 121 } 122 return correlationLengthTable; 83 private static void AddOrUpdateResult(ResultCollection results, string name, IItem item, bool clone = false) { 84 IResult r; 85 if (!results.TryGetValue(name, out r)) { 86 results.Add(new Result(name, clone ? (IItem)item.Clone() : item)); 87 } else r.Value = clone ? (IItem)item.Clone() : item; 123 88 } 124 89 } -
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/RuggednessCalculator.cs
r13484 r13583 1 using System; 2 using System.Linq; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2016 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 3 22 using HeuristicLab.Common; 4 23 using HeuristicLab.Core; … … 7 26 using HeuristicLab.Parameters; 8 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using System; 9 29 using System.Collections.Generic; 30 using System.Linq; 10 31 11 namespace HeuristicLab.Analysis.FitnessLandscape .Analysis{32 namespace HeuristicLab.Analysis.FitnessLandscape { 12 33 [Item("Ruggedness Calculator", "Calculates ruggedness descriptors froma given quality trail.")] 13 34 [StorableClass] … … 25 46 } 26 47 #endregion 27 28 48 29 49 #region Constructors & Cloning … … 58 78 alglib.basestat.samplemoments(qualities, qualities.Length, ref mean, ref variance, ref skewness, ref kurtosis); 59 79 List<double> autocorrelation = new List<double>() { 1.0 }; 60 double bound = Math.Min(2 / Math.Sqrt(qualities.Length), 1.0); 61 int correlationLength = 1; 62 for (; correlationLength < qualities.Length; correlationLength++) { 63 double value = correlations[correlationLength]/qualities.Length - mean * mean; 80 int correlationLength = -1, counter = 1; 81 for (; counter < qualities.Length / 2; counter++) { 82 double value = correlations[counter] / qualities.Length - mean * mean; 64 83 if (variance > 0) 65 value = Math.Max(Math.Min(value /variance, 1.0), -1.0);84 value = Math.Max(Math.Min(value / variance, 1.0), -1.0); 66 85 else 67 86 value = 1; 68 87 autocorrelation.Add(value); 69 if ( Math.Abs(value) < bound) break;88 if (value < 0 && correlationLength < 0) correlationLength = counter; 70 89 } 71 90 acf = autocorrelation.ToArray(); 72 return correlationLength -1;91 return correlationLength - 1; 73 92 } 74 93 -
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/UniqueThresholdCalculator.cs
r7128 r13583 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2016 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 System; 23 using System.Collections.Generic; 24 using System.Diagnostics; 2 25 using System.Linq; 3 using System.Collections.Generic;4 using System.Text;5 using System.Diagnostics;6 26 7 namespace HeuristicLab.Analysis {27 namespace HeuristicLab.Analysis.FitnessLandscape { 8 28 9 29 public static class UniqueThresholdCalculator { … … 61 81 } else { 62 82 double min = thresholds[0]; 63 double max = thresholds[thresholds.Count -1];83 double max = thresholds[thresholds.Count - 1]; 64 84 if (min == max) { 65 85 yield return min; 66 86 } else { 67 87 yield return min; 68 foreach (var t in DetermineInnerThresholds(thresholds, n -2))88 foreach (var t in DetermineInnerThresholds(thresholds, n - 2)) 69 89 yield return t; 70 90 yield return max; -
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/UpDownWalkAnalyzer.cs
r7176 r13583 20 20 #endregion 21 21 22 using System.Collections.Generic;23 using System.Drawing;24 using System.Linq;25 using HeuristicLab.Collections;26 22 using HeuristicLab.Common; 27 23 using HeuristicLab.Core; 28 24 using HeuristicLab.Data; 29 25 using HeuristicLab.Operators; 30 using HeuristicLab.Optimization .Operators;26 using HeuristicLab.Optimization; 31 27 using HeuristicLab.Parameters; 32 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using System.Linq; 33 30 34 namespace HeuristicLab.Analysis.FitnessLandscape .Analysis{35 31 namespace HeuristicLab.Analysis.FitnessLandscape { 32 [Item("Up/Down Walk Analyzer", "Analyzes the quality trail produced from an up/down walk.")] 36 33 [StorableClass] 37 public class UpDownWalkAnalyzer : AlgorithmOperator, IQualityTrailAnalyzer {34 public class UpDownWalkAnalyzer : SingleSuccessorOperator, IQualityTrailAnalyzer { 38 35 public bool EnabledByDefault { 39 36 get { return false; } … … 44 41 get { return (LookupParameter<DataTable>)Parameters["Quality Trail"]; } 45 42 } 46 public LookupParameter<VariableCollection> ResultsParameter { 47 get { return (LookupParameter<VariableCollection>)Parameters["Results"]; } 48 } 49 public LookupParameter<DataTable> UpDownStepsParameter { 50 get { return (LookupParameter<DataTable>)Parameters["UpDownSteps"]; } 51 } 52 public LookupParameter<DataTable> UpDownLevelsParameter { 53 get { return (LookupParameter<DataTable>)Parameters["UpDownLevels"]; } 43 public LookupParameter<ResultCollection> ResultsParameter { 44 get { return (LookupParameter<ResultCollection>)Parameters["Results"]; } 54 45 } 55 46 public LookupParameter<DoubleValue> UpWalkLengthParameter { … … 65 56 get { return (LookupParameter<DoubleValue>)Parameters["DownWalkLenVar"]; } 66 57 } 67 public LookupParameter<DoubleValue> UpperLevelParameter {68 get { return (LookupParameter<DoubleValue>)Parameters["UpperLevel"]; }69 }70 public LookupParameter<DoubleValue> LowerLevelParameter {71 get { return (LookupParameter<DoubleValue>)Parameters["LowerLevel"]; }72 }73 58 public LookupParameter<DoubleValue> UpperVarianceParameter { 74 59 get { return (LookupParameter<DoubleValue>)Parameters["UpperVariance"]; } … … 82 67 protected UpDownWalkAnalyzer(bool deserializing) : base(deserializing) { } 83 68 protected UpDownWalkAnalyzer(UpDownWalkAnalyzer original, Cloner cloner) : base(original, cloner) { } 84 85 69 public UpDownWalkAnalyzer() { 86 70 Parameters.Add(new LookupParameter<DataTable>("Quality Trail", "The qualities of the solutions")); 87 Parameters.Add(new LookupParameter<VariableCollection>("Results", "The collection of all results of this algorithm")); 88 Parameters.Add(new LookupParameter<DataTable>("UpDownSteps", "Distribution of upward and downward steps between extremes.")); 89 Parameters.Add(new LookupParameter<DataTable>("UpDownLevels", "Distribution of upper and lower levels in up-down walks.")); 71 Parameters.Add(new LookupParameter<ResultCollection>("Results", "The collection of all results of this algorithm")); 90 72 Parameters.Add(new LookupParameter<DoubleValue>("DownWalkLength", "Average downward walk length.")); 91 73 Parameters.Add(new LookupParameter<DoubleValue>("UpWalkLength", "Average updward walk length.")); 92 74 Parameters.Add(new LookupParameter<DoubleValue>("UpWalkLenVar", "Upward walk length variance.")); 93 75 Parameters.Add(new LookupParameter<DoubleValue>("DownWalkLenVar", "Downward walk length variance.")); 94 Parameters.Add(new LookupParameter<DoubleValue>("UpperLevel", "Average maximum fitness value."));95 Parameters.Add(new LookupParameter<DoubleValue>("LowerLevel", "Average minimum fitness value."));96 76 Parameters.Add(new LookupParameter<DoubleValue>("LowerVariance", "Lower level variance.")); 97 77 Parameters.Add(new LookupParameter<DoubleValue>("UpperVariance", "Upper level variance.")); 98 99 100 var resultsCollector = new ResultsCollector();101 resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(UpDownStepsParameter.Name));102 resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>(UpDownLevelsParameter.Name));103 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(DownWalkLengthParameter.Name));104 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(UpWalkLengthParameter.Name));105 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(UpWalkLenVarParameter.Name));106 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(DownWalkLenVarParameter.Name));107 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(UpperLevelParameter.Name));108 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(LowerLevelParameter.Name));109 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(UpperVarianceParameter.Name));110 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(LowerVarianceParameter.Name));111 112 OperatorGraph.InitialOperator = resultsCollector;113 resultsCollector.Successor = null;114 78 } 115 79 … … 119 83 120 84 public override IOperation Apply() { 121 var stepsTable = GetOrCreateTable(UpDownStepsParameter, "Up", "Down"); 122 var levelsTable = GetOrCreateTable(UpDownLevelsParameter, "Top", "Bottom"); 123 DataTable qualityTrail = QualityTrailParameter.ActualValue; 85 var qualityTrail = QualityTrailParameter.ActualValue; 124 86 if (qualityTrail != null && qualityTrail.Rows.Count > 0) { 125 87 var qualities = qualityTrail.Rows.First().Values.ToList(); 126 88 if (qualities.Count > 2) { 89 var results = ResultsParameter.ActualValue; 127 90 var extremes = qualities 128 .Delta((a, b) => new { a, b, diff = b - a})129 .Select((p, i) => new { p.a, p.b, p.diff, i = i+1})91 .Delta((a, b) => new { a, b, diff = b - a }) 92 .Select((p, i) => new { p.a, p.b, p.diff, i = i + 1 }) 130 93 .Delta((s1, s2) => new { 131 94 s1.i, … … 143 106 var maxima = extremes.Where(x => x.top).ToList(); 144 107 var minima = extremes.Where(x => x.bottom).ToList(); 145 var tops = Enumerable.Repeat(new { length = 0, value = 0.0}, 0).ToList();108 var tops = Enumerable.Repeat(new { length = 0, value = 0.0 }, 0).ToList(); 146 109 var bottoms = tops; 147 110 if (maxima.Count > 0 && minima.Count > 0) { 148 111 if (maxima.First().i < minima.First().i) { 149 bottoms = maxima.Zip(minima, (t, b) => new { length = b.i - t.i, b.value}).ToList();150 minima.Insert(0, new { i = -1, value = 0.0, top = false, bottom = false});151 tops = maxima.Zip(minima, (t, b) => new { length = t.i - b.i, t.value}).ToList();112 bottoms = maxima.Zip(minima, (t, b) => new { length = b.i - t.i, b.value }).ToList(); 113 minima.Insert(0, new { i = -1, value = 0.0, top = false, bottom = false }); 114 tops = maxima.Zip(minima, (t, b) => new { length = t.i - b.i, t.value }).ToList(); 152 115 } else { 153 tops = maxima.Zip(minima, (t, b) => new { length = t.i - b.i, t.value}).ToList();154 maxima.Insert(0, new { i = -1, value = 0.0, top = false, bottom = false});155 bottoms = maxima.Zip(minima, (t, b) => new { length = b.i - t.i, b.value}).ToList();116 tops = maxima.Zip(minima, (t, b) => new { length = t.i - b.i, t.value }).ToList(); 117 maxima.Insert(0, new { i = -1, value = 0.0, top = false, bottom = false }); 118 bottoms = maxima.Zip(minima, (t, b) => new { length = b.i - t.i, b.value }).ToList(); 156 119 } 157 120 if (tops.Count > 0) { 158 var topLengths = tops.Select(t => (double) 121 var topLengths = tops.Select(t => (double)t.length).ToList(); 159 122 var topVals = tops.Select(t => t.value).ToList(); 160 ReplaceHistogram(stepsTable.Rows["Up"], topLengths); 161 ReplaceHistogram(levelsTable.Rows["Top"], topVals); 162 UpperLevelParameter.ActualValue = new DoubleValue(topVals.Average()); 163 UpperVarianceParameter.ActualValue = new DoubleValue(topVals.Variance()); 164 UpWalkLengthParameter.ActualValue = new DoubleValue(topLengths.Average()); 165 UpWalkLenVarParameter.ActualValue = new DoubleValue(topLengths.Variance()); 123 var uv = new DoubleValue(topVals.Variance()); 124 UpperVarianceParameter.ActualValue = uv; 125 AddOrUpdateResult(results, UpperVarianceParameter.Name, uv); 126 var ul = new DoubleValue(topLengths.Average()); 127 UpWalkLengthParameter.ActualValue = ul; 128 AddOrUpdateResult(results, UpWalkLengthParameter.Name, ul); 129 var ulv = new DoubleValue(topLengths.Variance()); 130 UpWalkLenVarParameter.ActualValue = ulv; 131 AddOrUpdateResult(results, UpWalkLenVarParameter.Name, ulv); 166 132 } 167 133 if (bottoms.Count > 0) { 168 var bottomLengths = bottoms.Select(b => (double) 134 var bottomLengths = bottoms.Select(b => (double)b.length).ToList(); 169 135 var bottomVals = bottoms.Select(b => b.value).ToList(); 170 ReplaceHistogram(stepsTable.Rows["Down"], bottomLengths); 171 ReplaceHistogram(levelsTable.Rows["Bottom"], bottomVals); 172 LowerLevelParameter.ActualValue = new DoubleValue(bottomVals.Average()); 173 LowerVarianceParameter.ActualValue = new DoubleValue(bottomVals.Variance()); 174 DownWalkLengthParameter.ActualValue = new DoubleValue(bottomLengths.Average()); 175 DownWalkLenVarParameter.ActualValue = new DoubleValue(bottomLengths.Variance()); 136 var lv = new DoubleValue(bottomVals.Variance()); 137 LowerVarianceParameter.ActualValue = lv; 138 AddOrUpdateResult(results, LowerVarianceParameter.Name, lv); 139 var dl = new DoubleValue(bottomLengths.Average()); 140 DownWalkLengthParameter.ActualValue = dl; 141 AddOrUpdateResult(results, DownWalkLengthParameter.Name, dl); 142 var dlv = new DoubleValue(bottomLengths.Variance()); 143 DownWalkLenVarParameter.ActualValue = dlv; 144 AddOrUpdateResult(results, DownWalkLenVarParameter.Name, dlv); 176 145 } 177 146 } … … 181 150 } 182 151 183 private void ReplaceHistogram(DataRow row, IEnumerable<double> values) { 184 row.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram; 185 row.VisualProperties.Bins = 25; 186 row.Values.Clear(); 187 row.Values.AddRange(values); 188 } 189 190 private DataTable GetOrCreateTable(LookupParameter<DataTable> tableParameter, params string[] rowNames) { 191 DataTable table = tableParameter.ActualValue; 192 if (table == null) { 193 table = new DataTable(tableParameter.Name, tableParameter.Description); 194 tableParameter.ActualValue = table; 195 foreach (var name in rowNames) { 196 table.Rows.Add(new DataRow(name)); 197 } 198 } 199 return table; 152 private static void AddOrUpdateResult(ResultCollection results, string name, IItem item, bool clone = false) { 153 IResult r; 154 if (!results.TryGetValue(name, out r)) { 155 results.Add(new Result(name, clone ? (IItem)item.Clone() : item)); 156 } else r.Value = clone ? (IItem)item.Clone() : item; 200 157 } 201 158 }
Note: See TracChangeset
for help on using the changeset viewer.