Changeset 8725
- Timestamp:
- 10/03/12 17:13:31 (12 years ago)
- Location:
- branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis/InformationAnalysis.cs
r7128 r8725 19 19 public List<double> PartialInformationContent { get; private set; } 20 20 public List<double> DensityBasinInformation { get; private set; } 21 public List<double> TotalEntropy { get; private set; } 21 22 public List<double> QualityDelta { get; private set; } 22 23 public double InformationStability { get; private set; } 23 24 public int Regularity { get; private set; } 25 public int Diversity { get; private set; } 24 26 public Peak PeakInformationContent { get; private set; } 25 27 public Peak PeakPartialInformationContent { get; private set; } 26 28 public Peak PeakDensityBasinInformation { get; private set; } 29 public Peak PeakTotalEntropy { get; private set; } 27 30 28 public InformationAnalysis(I Enumerable<double> qualities, int nQuantiles) {31 public InformationAnalysis(IList<double> qualities, int nQuantiles) { 29 32 InformationContent = new List<double>(); 30 33 PartialInformationContent = new List<double>(); 31 34 DensityBasinInformation = new List<double>(); 35 TotalEntropy = new List<double>(); 32 36 QualityDelta = new List<double>(); 33 37 PerformAnalysis(qualities, nQuantiles); 34 38 } 35 39 36 private void PerformAnalysis(I Enumerable<double> qualities, int nQuantiles) {40 private void PerformAnalysis(IList<double> qualities, int nQuantiles) { 37 41 var differences = Differences(qualities).ToList(); 38 42 InformationStability = differences.Select(d => Math.Abs(d)).Max(); 39 43 Regularity = new HashSet<double>(differences).Count; 40 var thresholds = UniqueThresholdCalculator.DetermineThresholds(differences, nQuantiles).ToList(); 44 Diversity = new HashSet<double>(qualities).Count; 45 //var thresholds = UniqueThresholdCalculator.DetermineThresholds(differences, nQuantiles).ToList(); 46 var thresholds = differences.Select(d => Math.Abs(d)).OrderBy(d => d); 41 47 foreach (var eps in thresholds) { 42 48 var shapes = Shapes(eps, differences).ToList(); 43 int[] shape _counts = CountShapes(shapes);49 int[] shapeCounts = CountShapes(shapes); 44 50 QualityDelta.Add(eps); 45 InformationContent.Add(CalculateInformationContent(shape _counts, shapes.Count));51 InformationContent.Add(CalculateInformationContent(shapeCounts, shapes.Count)); 46 52 PartialInformationContent.Add(CalculatePartialInformationContent(eps, differences)); 47 DensityBasinInformation.Add(CalculateDensityBasinInformation(shape_counts, shapes.Count)); 53 DensityBasinInformation.Add(CalculateDensityBasinInformation(shapeCounts, shapes.Count)); 54 TotalEntropy.Add(CalculateTotalEntropy(shapeCounts, shapes.Count)); 48 55 } 49 PeakDensityBasinInformation = GetPeak(QualityDelta, InformationContent); 56 PeakInformationContent = GetPeak(QualityDelta, InformationContent); 57 PeakDensityBasinInformation = GetPeak(QualityDelta, DensityBasinInformation); 50 58 PeakPartialInformationContent = GetPeak(QualityDelta, PartialInformationContent); 51 Peak DensityBasinInformation = GetPeak(QualityDelta, DensityBasinInformation);59 PeakTotalEntropy = GetPeak(QualityDelta, TotalEntropy); 52 60 } 53 61 … … 72 80 return Utils.Delta(differences, (x, y) => 73 81 (Shape) 74 ((x > = eps ? 1 : (x <=-eps ? -1 : 0)) +75 (y > = eps ? 3 : (y <=-eps ? -3 : 0))));82 ((x > eps ? 1 : (x < -eps ? -1 : 0)) + 83 (y > eps ? 3 : (y < -eps ? -3 : 0)))); 76 84 } 77 85 78 private static double CalculateInformationContent(int[] shape _counts, int total_n_shapes) {86 private static double CalculateInformationContent(int[] shapeCounts, int totalNShapes) { 79 87 return 80 -Entropy(shape _counts[(int)Shape.EquDec + 4], total_n_shapes, 6)81 - Entropy(shape _counts[(int)Shape.IncDec + 4], total_n_shapes, 6)82 - Entropy(shape _counts[(int)Shape.DecEqu + 4], total_n_shapes, 6)83 - Entropy(shape _counts[(int)Shape.IncEqu + 4], total_n_shapes, 6)84 - Entropy(shape _counts[(int)Shape.DecInc + 4], total_n_shapes, 6)85 - Entropy(shape _counts[(int)Shape.EquInc + 4], total_n_shapes, 6);88 -Entropy(shapeCounts[(int)Shape.EquDec + 4], totalNShapes, 6) 89 - Entropy(shapeCounts[(int)Shape.IncDec + 4], totalNShapes, 6) 90 - Entropy(shapeCounts[(int)Shape.DecEqu + 4], totalNShapes, 6) 91 - Entropy(shapeCounts[(int)Shape.IncEqu + 4], totalNShapes, 6) 92 - Entropy(shapeCounts[(int)Shape.DecInc + 4], totalNShapes, 6) 93 - Entropy(shapeCounts[(int)Shape.EquInc + 4], totalNShapes, 6); 86 94 } 87 95 88 private static double CalculateDensityBasinInformation(int[] shape _counts, int total_n_shapes) {96 private static double CalculateDensityBasinInformation(int[] shapeCounts, int totalNShapes) { 89 97 return 90 -Entropy(shape _counts[(int)Shape.DecDec + 4], total_n_shapes, 3)91 - Entropy(shape _counts[(int)Shape.EquEqu + 4], total_n_shapes, 3)92 - Entropy(shape _counts[(int)Shape.IncInc + 4], total_n_shapes, 3);98 -Entropy(shapeCounts[(int)Shape.DecDec + 4], totalNShapes, 3) 99 - Entropy(shapeCounts[(int)Shape.EquEqu + 4], totalNShapes, 3) 100 - Entropy(shapeCounts[(int)Shape.IncInc + 4], totalNShapes, 3); 93 101 } 94 102 95 private static double CalculatePartialInformationContent(double eps, List<double> differences) { 103 private static double CalculateTotalEntropy(int[] shapeCounts, int totalNShapes) { 104 return shapeCounts.Aggregate(0.0, (current, t) => current - Entropy(t, totalNShapes, 9)); 105 } 106 107 private static double CalculatePartialInformationContent(double eps, ICollection<double> differences) { 96 108 int slope = 0; 97 109 int nPeaks = 0; 98 110 foreach (var d in differences) { 99 if (d > =eps) {111 if (d > eps) { 100 112 if (slope < 0) nPeaks++; 101 113 slope = +1; 102 } else if (d < =-eps) {114 } else if (d < -eps) { 103 115 if (slope > 0) nPeaks++; 104 116 slope = -1; … … 109 121 110 122 private static int[] CountShapes(IEnumerable<Shape> shapes) { 111 int[] shape _counts = new int[9];123 int[] shapeCounts = new int[9]; 112 124 foreach (var s in shapes) { 113 shape _counts[(int)s + 4]++;125 shapeCounts[(int)s + 4]++; 114 126 } 115 return shape _counts;127 return shapeCounts; 116 128 } 117 129 118 private static double Entropy(int count, int total, int n _cases) {130 private static double Entropy(int count, int total, int nCases) { 119 131 if (count == 0) 120 132 return 0; 121 133 double freq = 1.0 * count / total; 122 return freq * Math.Log(freq, n _cases);134 return freq * Math.Log(freq, nCases); 123 135 } 124 136 -
branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis/InformationAnalysisCalculator.cs
r7128 r8725 25 25 get { return (LookupParameter<IntValue>)Parameters["Regularity"]; } 26 26 } 27 public LookupParameter<IntValue> DiversityParameter { 28 get { return (LookupParameter<IntValue>)Parameters["Diversity"]; } 29 } 27 30 public LookupParameter<DoubleArray> InformationContentParameter { 28 31 get { return (LookupParameter<DoubleArray>)Parameters["InformationContent"]; } … … 34 37 get { return (LookupParameter<DoubleArray>)Parameters["DensityBasinInformation"]; } 35 38 } 39 public LookupParameter<DoubleArray> TotalEntropyParameter { 40 get { return (LookupParameter<DoubleArray>)Parameters["TotalEntropy"]; } 41 } 36 42 public LookupParameter<DoubleArray> EpsilonQuantilesParameter { 37 43 get { return (LookupParameter<DoubleArray>)Parameters["EpsilonQuantiles"]; } … … 42 48 [StorableConstructor] 43 49 protected InformationAnalysisCalculator(bool deserializing) : base(deserializing) { } 44 public InformationAnalysisCalculator() 45 : base() { 50 public InformationAnalysisCalculator() { 46 51 Parameters.Add(new LookupParameter<DataTable>("QualityTrail", "Historical quality trail of a walk over a fitness landscape.")); 47 52 Parameters.Add(new ValueLookupParameter<IntValue>("NQuantiles", "Number of epsilon quantiles to calculate information analysis.")); 48 53 Parameters.Add(new LookupParameter<DoubleValue>("InformationStability")); 49 54 Parameters.Add(new LookupParameter<IntValue>("Regularity")); 55 Parameters.Add(new LookupParameter<IntValue>("Diversity")); 50 56 Parameters.Add(new LookupParameter<DoubleArray>("InformationContent")); 51 57 Parameters.Add(new LookupParameter<DoubleArray>("PartialInformationContent")); 52 58 Parameters.Add(new LookupParameter<DoubleArray>("DensityBasinInformation")); 59 Parameters.Add(new LookupParameter<DoubleArray>("TotalEntropy")); 53 60 Parameters.Add(new LookupParameter<DoubleArray>("EpsilonQuantiles", "Considered values of epsilon, selected as quantiles of actual quality differences")); 54 61 } … … 66 73 NQuantilesParameter.ActualValue.Value); 67 74 RegularityParameter.ActualValue = new IntValue(analysis.Regularity); 75 DiversityParameter.ActualValue = new IntValue(analysis.Diversity); 68 76 InformationStabilityParameter.ActualValue = new DoubleValue(analysis.InformationStability); 69 77 InformationContentParameter.ActualValue = new DoubleArray(analysis.InformationContent.ToArray()); 70 78 PartialInformationContentParameter.ActualValue = new DoubleArray(analysis.PartialInformationContent.ToArray()); 71 79 DensityBasinInformationParameter.ActualValue = new DoubleArray(analysis.DensityBasinInformation.ToArray()); 80 TotalEntropyParameter.ActualValue = new DoubleArray(analysis.TotalEntropy.ToArray()); 72 81 EpsilonQuantilesParameter.ActualValue = new DoubleArray(analysis.QualityDelta.ToArray()); 73 82 return base.Apply(); -
branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis/InformationAnalyzer.cs
r7176 r8725 62 62 get { return (LookupParameter<DoubleValue>)Parameters["DensityBasinInformationValue"]; } 63 63 } 64 public LookupParameter<DoubleValue> TotalEntropyValueParameter { 65 get { return (LookupParameter<DoubleValue>)Parameters["TotalEntropyValue"]; } 66 } 64 67 public LookupParameter<DoubleValue> InformationStabilityValueParameter { 65 68 get { return (LookupParameter<DoubleValue>)Parameters["InformationStabilityValue"]; } … … 68 71 get { return (LookupParameter<IntValue>)Parameters["RegularityValue"]; } 69 72 } 73 public LookupParameter<IntValue> DiversityValueParameter { 74 get { return (LookupParameter<IntValue>)Parameters["DiversityValue"]; } 75 } 76 77 #region Peaks 78 public LookupParameter<DoubleValue> PeakInformationContentParameter { 79 get { return (LookupParameter<DoubleValue>) Parameters["PeakInformationContent"]; } 80 } 81 public LookupParameter<DoubleValue> PeakInformationContentQualityDeltaParameter { 82 get { return (LookupParameter<DoubleValue>) Parameters["PeakInformationContentQualityDelta"]; } 83 } 84 public LookupParameter<DoubleValue> PeakDensityBasinInformationParameter { 85 get { return (LookupParameter<DoubleValue>) Parameters["PeakDensityBasinInformation"]; } 86 } 87 public LookupParameter<DoubleValue> PeakDensityBasinInformationQualityDeltaParameter { 88 get { return (LookupParameter<DoubleValue>) Parameters["PeakDensityBasinInformationQualityDelta"]; } 89 } 90 91 92 #endregion 93 70 94 #endregion 71 95 … … 82 106 set { DensityBasinInformationValueParameter.ActualValue = new DoubleValue(value); } 83 107 } 108 private double TotalEntropyValue { 109 set { TotalEntropyValueParameter.ActualValue = new DoubleValue(value); } 110 } 84 111 private double InformationStabilityValue { 85 112 set { InformationStabilityValueParameter.ActualValue = new DoubleValue(value); } 86 113 } 87 88 114 89 115 [StorableConstructor] … … 100 126 Parameters.Add(new LookupParameter<DoubleValue>("PartialInformationContentValue", "Partial information content M(0) at eps = 0")); 101 127 Parameters.Add(new LookupParameter<DoubleValue>("DensityBasinInformationValue", "Density Basin Information h(0) at eps = 0")); 128 Parameters.Add(new LookupParameter<DoubleValue>("TotalEntropyValue", "The overall disorder in the trajectory")); 102 129 Parameters.Add(new LookupParameter<DoubleValue>("InformationStabilityValue", "Information Stability Value")); 103 130 Parameters.Add(new LookupParameter<IntValue>("RegularityValue", "The number of different quality differences")); 131 Parameters.Add(new LookupParameter<IntValue>("DiversityValue", "The number of different quality values")); 132 Parameters.Add(new LookupParameter<DoubleValue>("PeakInformationContent", "Maximum information content at any quality delta.")); 133 Parameters.Add(new LookupParameter<DoubleValue>("PeakInformationContentQualityDelta", "Quality delta with maximum information content.")); 134 Parameters.Add(new LookupParameter<DoubleValue>("PeakDensityBasinInformation", "Maximum density basin information at any quality delta.")); 135 Parameters.Add(new LookupParameter<DoubleValue>("PeakDensityBasinInformationQualityDelta", "Quality delta with maximum density basin information.")); 104 136 105 137 var resultsCollector = new ResultsCollector(); … … 109 141 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PartialInformationContentValueParameter.Name)); 110 142 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(DensityBasinInformationValueParameter.Name)); 143 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(TotalEntropyValueParameter.Name)); 111 144 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(InformationStabilityValueParameter.Name)); 112 145 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(RegularityValueParameter.Name)); 113 146 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>(DiversityValueParameter.Name)); 147 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PeakInformationContentParameter.Name)); 148 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PeakInformationContentQualityDeltaParameter.Name)); 149 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PeakDensityBasinInformationParameter.Name)); 150 resultsCollector.CollectedValues.Add(new LookupParameter<DoubleValue>(PeakDensityBasinInformationQualityDeltaParameter.Name)); 114 151 115 152 OperatorGraph.InitialOperator = resultsCollector; … … 139 176 var partialInformationContent = informationTable.Rows["Partial Information Content"].Values; 140 177 var densityBasinInformation = informationTable.Rows["Density Basin Information"].Values; 178 var totalEntropy = informationTable.Rows["Total Entropy"].Values; 141 179 var qualityDelta = informationTable.Rows["Quality Delta"].Values; 142 180 var analysis = new InformationAnalysis(qualities, nQuantiles); 143 181 InformationStability.Rows["Regularity"].Values.Add(analysis.Regularity); 182 InformationStability.Rows["Diversity"].Values.Add(analysis.Diversity); 144 183 InformationStability.Rows["Relative Regularity"].Values.Add(1.0 * analysis.Regularity / qualities.Count); 184 InformationStability.Rows["Relative Diversity"].Values.Add(1.0 * analysis.Diversity / qualities.Count); 145 185 InformationStability.Rows["Information Stability"].Values.Add(analysis.InformationStability); 146 186 informationContent.Clear(); … … 150 190 densityBasinInformation.Clear(); 151 191 densityBasinInformation.AddRange(analysis.DensityBasinInformation); 192 totalEntropy.Clear(); 193 totalEntropy.AddRange(analysis.TotalEntropy); 152 194 qualityDelta.Clear(); 153 195 qualityDelta.AddRange(analysis.QualityDelta); … … 157 199 InformationStabilityValue = analysis.InformationStability; 158 200 RegularityValueParameter.ActualValue = new IntValue(analysis.Regularity); 201 DiversityValueParameter.ActualValue = new IntValue(analysis.Diversity); 202 PeakInformationContentParameter.ActualValue = new DoubleValue(analysis.PeakInformationContent.Value); 203 PeakDensityBasinInformationParameter.ActualValue = new DoubleValue(analysis.PeakDensityBasinInformation.Value); 204 PeakInformationContentQualityDeltaParameter.ActualValue = new DoubleValue(analysis.PeakInformationContent.QualityDelta); 205 PeakDensityBasinInformationQualityDeltaParameter.ActualValue = new DoubleValue(analysis.PeakDensityBasinInformation.QualityDelta); 159 206 } 160 207 } … … 167 214 information.Rows.Add(new DataRow("Partial Information Content")); 168 215 information.Rows.Add(new DataRow("Density Basin Information")); 169 var row = new DataRow("Quality Delta"); 170 row.VisualProperties.SecondYAxis = true; 171 information.Rows.Add(row); 216 information.Rows.Add(new DataRow("Total Entropy")); 217 information.Rows.Add(new DataRow("Quality Delta") {VisualProperties = {SecondYAxis = true}}); 172 218 InformationParameter.ActualValue = information; 173 219 } … … 180 226 informationStability.Rows.Add(new DataRow("Information Stability")); 181 227 informationStability.Rows.Add(new DataRow("Relative Regularity")); 182 var row = new DataRow("Regularity");183 row.VisualProperties.SecondYAxis = true;184 informationStability.Rows.Add( row);228 informationStability.Rows.Add(new DataRow("Relative Diversity")); 229 informationStability.Rows.Add(new DataRow("Regularity") {VisualProperties = {SecondYAxis = true}}); 230 informationStability.Rows.Add(new DataRow("Diversity") {VisualProperties = {SecondYAxis = true}}); 185 231 InformationStabilityParameter.ActualValue = informationStability; 186 232 }
Note: See TracChangeset
for help on using the changeset viewer.