Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/14/12 18:58:15 (12 years ago)
Author:
gkronber
Message:

#1847 merged r8205:8635 from trunk into branch

Location:
branches/GP-MoveOperators
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/GP-MoveOperators

  • branches/GP-MoveOperators/HeuristicLab.Analysis

  • branches/GP-MoveOperators/HeuristicLab.Analysis/3.3/AlleleFrequencyAnalysis/AlleleFrequencyAnalyzer.cs

    r7259 r8660  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    8889    }
    8990
    90     #region AlleleFrequencyIdEqualityComparer
     91    #region Equality Comparers
     92    private class AlleleIdEqualityComparer : IEqualityComparer<Allele> {
     93      public bool Equals(Allele x, Allele y) {
     94        return x.Id == y.Id;
     95      }
     96      public int GetHashCode(Allele obj) {
     97        return obj.Id.GetHashCode();
     98      }
     99    }
    91100    private class AlleleFrequencyIdEqualityComparer : IEqualityComparer<AlleleFrequency> {
    92101      public bool Equals(AlleleFrequency x, AlleleFrequency y) {
     
    112121        bool max = MaximizationParameter.ActualValue.Value;
    113122        ItemArray<T> solutions = SolutionParameter.ActualValue;
    114         ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
     123        double[] qualities = QualityParameter.ActualValue.Select(x => x.Value).ToArray();
    115124        T bestKnownSolution = BestKnownSolutionParameter.ActualValue;
    116125        bool storeHistory = StoreHistoryParameter.Value.Value;
     
    120129        if (!max) {
    121130          bestIndex = qualities
    122             .Select((x, index) => new { index, x.Value })
     131            .Select((x, i) => new { Index = i, Value = x })
    123132            .OrderBy(x => x.Value)
    124             .First().index;
     133            .First().Index;
    125134        } else {
    126135          bestIndex = qualities
    127             .Select((x, index) => new { index, x.Value })
     136            .Select((x, i) => new { Index = i, Value = x })
    128137            .OrderByDescending(x => x.Value)
    129             .First().index;
     138            .First().Index;
    130139        }
    131140
     
    142151                                                          x.Count() / ((double)solutions.Length),
    143152                                                          x.Average(a => a.Allele.Impact),
    144                                                           x.Average(a => a.Quality.Value),
     153                                                          x.Average(a => a.Quality),
    145154                                                          bestKnownAlleles == null ? false : bestKnownAlleles.Any(a => a.Id == x.Key),
    146155                                                          bestAlleles.Any(a => a.Id == x.Key)));
     
    248257        else
    249258          ((DoubleValue)results["Lost Alleles of Best Known Solution"].Value).Value = lostRelevantAllelesCount;
     259
     260        // calculate contained alleles of best known solution and relative quality
     261        if (bestKnownAlleles != null) {
     262          double qualityRange = Math.Abs(qualities.Max() - qualities.Min());
     263          var points = solutions.Select((s, index) => new Point2D<double>(CalculateAlleles(s).Intersect(bestKnownAlleles, new AlleleIdEqualityComparer()).Count(),
     264                                                                          Math.Abs(qualities[index] - qualities[bestIndex]) / qualityRange));
     265          var avgContainedReleventAlleles = points.Select(x => x.X).Average();
     266
     267          var plot = new ScatterPlot("Contained Alleles of Best Known Solution and Relative Solution Qualtiy", null);
     268          plot.VisualProperties.XAxisTitle = "Contained Alleles of Best Known Solution";
     269          plot.VisualProperties.YAxisTitle = "Relative Solution Quality";
     270          plot.VisualProperties.XAxisMinimumAuto = false;
     271          plot.VisualProperties.XAxisMinimumFixedValue = 0.0;
     272          plot.VisualProperties.XAxisMaximumAuto = false;
     273          plot.VisualProperties.XAxisMaximumFixedValue = bestKnownAlleles.Length;
     274          plot.VisualProperties.YAxisMinimumAuto = false;
     275          plot.VisualProperties.YAxisMinimumFixedValue = 0.0;
     276          plot.VisualProperties.YAxisMaximumAuto = false;
     277          plot.VisualProperties.YAxisMaximumFixedValue = 1.0;
     278          var row = new ScatterPlotDataRow("Solutions of Current Generation", null, points);
     279          row.VisualProperties.PointStyle = ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Circle;
     280          row.VisualProperties.PointSize = 5;
     281          plot.Rows.Add(row);
     282
     283          if (!results.ContainsKey("Scatter Plot"))
     284            results.Add(new Result("Scatter Plot", plot));
     285          else
     286            results["Scatter Plot"].Value = plot;
     287          if (storeHistory) {
     288            if (!results.ContainsKey("Scatter Plot History")) {
     289              results.Add(new Result("Scatter Plot History", new ScatterPlotHistory()));
     290            }
     291            ((ScatterPlotHistory)results["Scatter Plot History"].Value).Add(plot);
     292          }
     293
     294          if (!allelesTable.Rows.ContainsKey("Average Contained Alleles of Best Known Solution")) {
     295            allelesTable.Rows.Add(new DataRow("Average Contained Alleles of Best Known Solution", null));
     296            allelesTable.Rows["Average Contained Alleles of Best Known Solution"].VisualProperties.SecondYAxis = true;
     297            allelesTable.Rows["Average Contained Alleles of Best Known Solution"].VisualProperties.StartIndexZero = true;
     298          }
     299          allelesTable.Rows["Average Contained Alleles of Best Known Solution"].Values.Add(avgContainedReleventAlleles);
     300
     301          if (!results.ContainsKey("Average Contained Alleles of Best Known Solution"))
     302            results.Add(new Result("Average Contained Alleles of Best Known Solution", new DoubleValue(avgContainedReleventAlleles)));
     303          else
     304            ((DoubleValue)results["Average Contained Alleles of Best Known Solution"].Value).Value = avgContainedReleventAlleles;
     305        }
    250306      }
    251307      return base.Apply();
Note: See TracChangeset for help on using the changeset viewer.