Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/03/12 17:13:31 (12 years ago)
Author:
epitzer
Message:

improve information analysis #1696

  • fixed a bug in quality delta filtering
  • report finer-grained results
  • add total entropy
  • add peak values to results
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape/Analysis/InformationAnalysis.cs

    r7128 r8725  
    1919    public List<double> PartialInformationContent { get; private set; }
    2020    public List<double> DensityBasinInformation { get; private set; }
     21    public List<double> TotalEntropy { get; private set; }
    2122    public List<double> QualityDelta { get; private set; }
    2223    public double InformationStability { get; private set; }
    2324    public int Regularity { get; private set; }
     25    public int Diversity { get; private set; }
    2426    public Peak PeakInformationContent { get; private set; }
    2527    public Peak PeakPartialInformationContent { get; private set; }
    2628    public Peak PeakDensityBasinInformation { get; private set; }
     29    public Peak PeakTotalEntropy { get; private set; }
    2730
    28     public InformationAnalysis(IEnumerable<double> qualities, int nQuantiles) {
     31    public InformationAnalysis(IList<double> qualities, int nQuantiles) {
    2932      InformationContent = new List<double>();
    3033      PartialInformationContent = new List<double>();
    3134      DensityBasinInformation = new List<double>();
     35      TotalEntropy = new List<double>();
    3236      QualityDelta = new List<double>();
    3337      PerformAnalysis(qualities, nQuantiles);
    3438    }
    3539
    36     private void PerformAnalysis(IEnumerable<double> qualities, int nQuantiles) {
     40    private void PerformAnalysis(IList<double> qualities, int nQuantiles) {
    3741      var differences = Differences(qualities).ToList();
    3842      InformationStability = differences.Select(d => Math.Abs(d)).Max();
    3943      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);
    4147      foreach (var eps in thresholds) {
    4248        var shapes = Shapes(eps, differences).ToList();
    43         int[] shape_counts = CountShapes(shapes);
     49        int[] shapeCounts = CountShapes(shapes);
    4450        QualityDelta.Add(eps);
    45         InformationContent.Add(CalculateInformationContent(shape_counts, shapes.Count));
     51        InformationContent.Add(CalculateInformationContent(shapeCounts, shapes.Count));
    4652        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));
    4855      }
    49       PeakDensityBasinInformation = GetPeak(QualityDelta, InformationContent);
     56      PeakInformationContent = GetPeak(QualityDelta, InformationContent);
     57      PeakDensityBasinInformation = GetPeak(QualityDelta, DensityBasinInformation);
    5058      PeakPartialInformationContent = GetPeak(QualityDelta, PartialInformationContent);
    51       PeakDensityBasinInformation = GetPeak(QualityDelta, DensityBasinInformation);
     59      PeakTotalEntropy = GetPeak(QualityDelta, TotalEntropy);
    5260    }
    5361
     
    7280      return Utils.Delta(differences, (x, y) =>
    7381        (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))));
    7684    }
    7785
    78     private static double CalculateInformationContent(int[] shape_counts, int total_n_shapes) {
     86    private static double CalculateInformationContent(int[] shapeCounts, int totalNShapes) {
    7987      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);
    8694    }
    8795
    88     private static double CalculateDensityBasinInformation(int[] shape_counts, int total_n_shapes) {
     96    private static double CalculateDensityBasinInformation(int[] shapeCounts, int totalNShapes) {
    8997      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);
    93101    }
    94102
    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) {
    96108      int slope = 0;
    97109      int nPeaks = 0;
    98110      foreach (var d in differences) {
    99         if (d >= eps) {
     111        if (d > eps) {
    100112          if (slope < 0) nPeaks++;
    101113          slope = +1;
    102         } else if (d <= -eps) {
     114        } else if (d < -eps) {
    103115          if (slope > 0) nPeaks++;
    104116          slope = -1;
     
    109121
    110122    private static int[] CountShapes(IEnumerable<Shape> shapes) {
    111       int[] shape_counts = new int[9];
     123      int[] shapeCounts = new int[9];
    112124      foreach (var s in shapes) {
    113         shape_counts[(int)s + 4]++;
     125        shapeCounts[(int)s + 4]++;
    114126      }
    115       return shape_counts;
     127      return shapeCounts;
    116128    }
    117129
    118     private static double Entropy(int count, int total, int n_cases) {
     130    private static double Entropy(int count, int total, int nCases) {
    119131      if (count == 0)
    120132        return 0;
    121133      double freq = 1.0 * count / total;
    122       return freq * Math.Log(freq, n_cases);
     134      return freq * Math.Log(freq, nCases);
    123135    }
    124136
Note: See TracChangeset for help on using the changeset viewer.