- Timestamp:
- 08/29/18 18:16:05 (6 years ago)
- Location:
- branches/2457_ExpertSystem/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2457_ExpertSystem/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/InformationAnalyzer.cs
r15279 r16096 20 20 #endregion 21 21 22 using System.Linq; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 27 28 using HeuristicLab.Parameters; 28 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using System.Linq;30 using System;31 30 32 31 namespace HeuristicLab.Analysis.FitnessLandscape { … … 125 124 var ic = new DoubleValue(analysis.InformationContent.FirstOrDefault()); 126 125 InformationContentParameter.ActualValue = ic; 127 AddOrUpdateResult(results,InformationContentParameter.Name, ic);126 results.AddOrUpdateResult(InformationContentParameter.Name, ic); 128 127 var pic = new DoubleValue(analysis.PartialInformationContent.FirstOrDefault()); 129 128 PartialInformationContentParameter.ActualValue = pic; 130 AddOrUpdateResult(results,PartialInformationContentParameter.Name, pic);129 results.AddOrUpdateResult(PartialInformationContentParameter.Name, pic); 131 130 var dbi = new DoubleValue(analysis.DensityBasinInformation.FirstOrDefault()); 132 131 DensityBasinInformationParameter.ActualValue = dbi; 133 AddOrUpdateResult(results,DensityBasinInformationParameter.Name, dbi);132 results.AddOrUpdateResult(DensityBasinInformationParameter.Name, dbi); 134 133 var @is = new DoubleValue(analysis.InformationStability); 135 134 InformationStabilityParameter.ActualValue = @is; 136 AddOrUpdateResult(results,InformationStabilityParameter.Name, @is);135 results.AddOrUpdateResult(InformationStabilityParameter.Name, @is); 137 136 var regularity = new DoubleValue(1.0 * analysis.Regularity / qualities.Count); 138 137 RegularityParameter.ActualValue = regularity; 139 AddOrUpdateResult(results,RegularityParameter.Name, regularity);138 results.AddOrUpdateResult(RegularityParameter.Name, regularity); 140 139 var diversity = new DoubleValue(1.0 * analysis.Diversity / qualities.Count); 141 140 DiversityParameter.ActualValue = diversity; 142 AddOrUpdateResult(results,DiversityParameter.Name, diversity);141 results.AddOrUpdateResult(DiversityParameter.Name, diversity); 143 142 var totalEntropy = new DoubleValue(analysis.TotalEntropy.FirstOrDefault()); 144 143 TotalEntropyParameter.ActualValue = totalEntropy; 145 AddOrUpdateResult(results,TotalEntropyParameter.Name, totalEntropy);144 results.AddOrUpdateResult(TotalEntropyParameter.Name, totalEntropy); 146 145 var peakIc = new DoubleValue(analysis.PeakInformationContent.Value); 147 146 PeakInformationContentParameter.ActualValue = peakIc; 148 AddOrUpdateResult(results,PeakInformationContentParameter.Name, peakIc);147 results.AddOrUpdateResult(PeakInformationContentParameter.Name, peakIc); 149 148 var peakDbi = new DoubleValue(analysis.PeakDensityBasinInformation.Value); 150 149 PeakDensityBasinInformationParameter.ActualValue = peakDbi; 151 AddOrUpdateResult(results,PeakDensityBasinInformationParameter.Name, peakDbi);150 results.AddOrUpdateResult(PeakDensityBasinInformationParameter.Name, peakDbi); 152 151 153 152 var itable = GetInformationTable(analysis); 154 AddOrUpdateResult(results,InformationAnalysisParameter.Name, itable);153 results.AddOrUpdateResult(InformationAnalysisParameter.Name, itable); 155 154 return base.Apply(); 156 155 } … … 176 175 return dt; 177 176 } 178 179 private static void AddOrUpdateResult(ResultCollection results, string name, IItem item, bool clone = false) {180 IResult r;181 if (!results.TryGetValue(name, out r)) {182 results.Add(new Result(name, clone ? (IItem)item.Clone() : item));183 } else r.Value = clone ? (IItem)item.Clone() : item;184 }185 177 } 186 178 } -
branches/2457_ExpertSystem/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/RuggednessAnalyzer.cs
r13583 r16096 20 20 #endregion 21 21 22 using System.Linq; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 27 28 using HeuristicLab.Parameters; 28 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using System.Linq;30 30 31 31 namespace HeuristicLab.Analysis.FitnessLandscape { 32 [Item("Ruggedness Analyzer", "Analyzes autocorrelation for one mutation step and correlation length. ")]32 [Item("Ruggedness Analyzer", "Analyzes autocorrelation for one mutation step and correlation length. Correlation length is calculated according to the statistical correlation length defined by Hordijk, W., 1996. A measure of landscapes. Evolutionary computation, 4(4), pp.335-360.")] 33 33 [StorableClass] 34 34 public class RuggednessAnalyzer : SingleSuccessorOperator, IQualityTrailAnalyzer { … … 50 50 get { return (LookupParameter<IntValue>)Parameters["CorrelationLength"]; } 51 51 } 52 public ValueLookupParameter<DoubleValue> LimitParameter { 53 get { return (ValueLookupParameter<DoubleValue>)Parameters["Limit"]; } 54 } 52 55 #endregion 53 56 … … 60 63 Parameters.Add(new LookupParameter<DoubleValue>("AutoCorrelation1", "Autocorrelation for one mutation step.")); 61 64 Parameters.Add(new LookupParameter<IntValue>("CorrelationLength", "The correlation length.")); 65 Parameters.Add(new ValueLookupParameter<DoubleValue>("Limit", "The limit for the statistical correlation length, if left empty 2 / sqrt(n), where n = length of walk will be used, as defined by Hordijk 1996.")); 62 66 } 63 67 … … 70 74 if (qualityTrail == null || qualityTrail.Rows.Count <= 0) return base.Apply(); 71 75 var results = ResultsParameter.ActualValue; 76 var limit = LimitParameter.ActualValue?.Value; 72 77 double[] autocorrelationValues; 73 var correlationLength = RuggednessCalculator.CalculateCorrelationLength(qualityTrail.Rows.First().Values.ToArray(), out autocorrelationValues );78 var correlationLength = RuggednessCalculator.CalculateCorrelationLength(qualityTrail.Rows.First().Values.ToArray(), out autocorrelationValues, limit); 74 79 var cl = new IntValue(correlationLength); 75 80 CorrelationLengthParameter.ActualValue = cl; 76 AddOrUpdateResult(results,CorrelationLengthParameter.Name, cl);81 results.AddOrUpdateResult(CorrelationLengthParameter.Name, cl); 77 82 var ac1 = new DoubleValue(autocorrelationValues.Length > 1 ? autocorrelationValues[1] : 0.0); 78 83 AutoCorrelation1Parameter.ActualValue = ac1; 79 AddOrUpdateResult(results,AutoCorrelation1Parameter.Name, ac1);84 results.AddOrUpdateResult(AutoCorrelation1Parameter.Name, ac1); 80 85 return base.Apply(); 81 }82 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;88 86 } 89 87 } -
branches/2457_ExpertSystem/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/RuggednessCalculator.cs
r13583 r16096 20 20 #endregion 21 21 22 using HeuristicLab.Common;23 using HeuristicLab.Core;24 using HeuristicLab.Data;25 using HeuristicLab.Operators;26 using HeuristicLab.Parameters;27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;28 22 using System; 29 23 using System.Collections.Generic; 30 using System.Linq;31 24 32 25 namespace HeuristicLab.Analysis.FitnessLandscape { 33 [Item("Ruggedness Calculator", "Calculates ruggedness descriptors froma given quality trail.")] 34 [StorableClass] 35 public class RuggednessCalculator : SingleSuccessorOperator { 36 37 #region Parameters 38 public LookupParameter<DataTable> QualityTrailParameter { 39 get { return (LookupParameter<DataTable>)Parameters["QualityTrail"]; } 40 } 41 public LookupParameter<IntValue> CorrelationLengthParameter { 42 get { return (LookupParameter<IntValue>)Parameters["CorrelationLength"]; } 43 } 44 public LookupParameter<DoubleArray> AutoCorrelationParameter { 45 get { return (LookupParameter<DoubleArray>)Parameters["AutoCorrelation"]; } 46 } 47 #endregion 48 49 #region Constructors & Cloning 50 [StorableConstructor] 51 protected RuggednessCalculator(bool deserializing) : base(deserializing) { } 52 protected RuggednessCalculator(RuggednessCalculator original, Cloner cloner) : base(original, cloner) { } 53 public RuggednessCalculator() { 54 Parameters.Add(new LookupParameter<DataTable>("QualityTrail", "Historical values of walk qualities")); 55 Parameters.Add(new LookupParameter<IntValue>("CorrelationLength", "Average maximum distances between correlated quality values.")); 56 Parameters.Add(new LookupParameter<DoubleArray>("AutoCorrelation", "AutoCorrelation")); 57 } 58 public override IDeepCloneable Clone(Cloner cloner) { 59 return new RuggednessCalculator(this, cloner); 60 } 61 #endregion 62 63 public override IOperation Apply() { 64 double[] qualities = QualityTrailParameter.ActualValue.Rows.First().Values.ToArray(); 65 double[] autocorrelation; 66 CorrelationLengthParameter.ActualValue = new IntValue(CalculateCorrelationLength(qualities, out autocorrelation)); 67 AutoCorrelationParameter.ActualValue = new DoubleArray(autocorrelation); 68 return base.Apply(); 69 } 70 71 public static int CalculateCorrelationLength(double[] qualities, out double[] acf) { 26 public static class RuggednessCalculator { 27 /// <summary> 28 /// Calculates statistical correlation length as defined by Hordijk, W., 1996. A measure of landscapes. Evolutionary computation, 4(4), pp.335-360. 29 /// </summary> 30 /// <param name="qualities">The quality trail observed.</param> 31 /// <param name="acf">The autocorrelation values for each step s, including 0 => acf[0] = 1.</param> 32 /// <param name="limit">The statistical limit, correlation length will be the last step before acf falls within this limit. If omitted it is calculated as 2 / sqrt(qualities.Length).</param> 33 /// <returns>The statistical correlation length</returns> 34 public static int CalculateCorrelationLength(double[] qualities, out double[] acf, double? limit = null) { 35 if (!limit.HasValue) limit = 2.0 / Math.Sqrt(qualities.Length); 72 36 double[] correlations = new double[qualities.Length]; 73 37 alglib.corr.corrr1dcircular(qualities, qualities.Length, qualities, qualities.Length, ref correlations); … … 86 50 value = 1; 87 51 autocorrelation.Add(value); 88 if ( value < 0&& correlationLength < 0) correlationLength = counter;52 if (Math.Abs(value) < limit && correlationLength < 0) correlationLength = counter; 89 53 } 90 54 acf = autocorrelation.ToArray(); 91 55 return correlationLength - 1; 92 56 } 93 94 public static bool AnyGreaterOne(double[] values) {95 return values.Any(d => d > 1);96 }97 57 } 98 58 } -
branches/2457_ExpertSystem/HeuristicLab.Analysis.FitnessLandscape/3.3/Analysis/UpDownWalkAnalyzer.cs
r13583 r16096 20 20 #endregion 21 21 22 using System.Linq; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 27 28 using HeuristicLab.Parameters; 28 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using System.Linq;30 30 31 31 namespace HeuristicLab.Analysis.FitnessLandscape { … … 123 123 var uv = new DoubleValue(topVals.Variance()); 124 124 UpperVarianceParameter.ActualValue = uv; 125 AddOrUpdateResult(results,UpperVarianceParameter.Name, uv);125 results.AddOrUpdateResult(UpperVarianceParameter.Name, uv); 126 126 var ul = new DoubleValue(topLengths.Average()); 127 127 UpWalkLengthParameter.ActualValue = ul; 128 AddOrUpdateResult(results,UpWalkLengthParameter.Name, ul);128 results.AddOrUpdateResult(UpWalkLengthParameter.Name, ul); 129 129 var ulv = new DoubleValue(topLengths.Variance()); 130 130 UpWalkLenVarParameter.ActualValue = ulv; 131 AddOrUpdateResult(results,UpWalkLenVarParameter.Name, ulv);131 results.AddOrUpdateResult(UpWalkLenVarParameter.Name, ulv); 132 132 } 133 133 if (bottoms.Count > 0) { … … 136 136 var lv = new DoubleValue(bottomVals.Variance()); 137 137 LowerVarianceParameter.ActualValue = lv; 138 AddOrUpdateResult(results,LowerVarianceParameter.Name, lv);138 results.AddOrUpdateResult(LowerVarianceParameter.Name, lv); 139 139 var dl = new DoubleValue(bottomLengths.Average()); 140 140 DownWalkLengthParameter.ActualValue = dl; 141 AddOrUpdateResult(results,DownWalkLengthParameter.Name, dl);141 results.AddOrUpdateResult(DownWalkLengthParameter.Name, dl); 142 142 var dlv = new DoubleValue(bottomLengths.Variance()); 143 143 DownWalkLenVarParameter.ActualValue = dlv; 144 AddOrUpdateResult(results,DownWalkLenVarParameter.Name, dlv);144 results.AddOrUpdateResult(DownWalkLenVarParameter.Name, dlv); 145 145 } 146 146 } … … 149 149 return base.Apply(); 150 150 } 151 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;157 }158 151 } 159 152 }
Note: See TracChangeset
for help on using the changeset viewer.