Changeset 8725 for branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis/InformationAnalysis.cs
- Timestamp:
- 10/03/12 17:13:31 (12 years ago)
- File:
-
- 1 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
Note: See TracChangeset
for help on using the changeset viewer.