Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8283


Ignore:
Timestamp:
07/11/12 01:29:52 (11 years ago)
Author:
swagner
Message:

Worked on AlleleFrequencyAnalyzer (#1893)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Analysis/3.3/AlleleFrequencyAnalysis/AlleleFrequencyAnalyzer.cs

    r7259 r8283  
    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)));
     
    159168        } else {
    160169          results = (ResultCollection)ResultsParameter.ActualValue[Name + " Results"].Value;
     170        }
     171
     172        // calculate scatter plot of contained relevant alleles and relative quality
     173        double avgContainedReleventAlleles = 0;
     174        if (bestKnownAlleles != null) {
     175          double qualityRange = Math.Abs(qualities.Max() - qualities.Min());
     176          var points = solutions.Select((s, index) => new Point2D<double>(CalculateAlleles(s).Intersect(bestKnownAlleles, new AlleleIdEqualityComparer()).Count(),
     177                                                                          Math.Abs(qualities[index] - qualities[bestIndex]) / qualityRange));
     178          avgContainedReleventAlleles = points.Select(x => x.X).Average();
     179          var plot = new ScatterPlot("Contained Alleles of Best Known Solution and Relative Solution Qualtiy", null);
     180          plot.VisualProperties.XAxisTitle = "Contained Alleles of Best Known Solution";
     181          plot.VisualProperties.YAxisTitle = "Relative Solution Quality";
     182          plot.VisualProperties.XAxisMinimumAuto = false;
     183          plot.VisualProperties.XAxisMinimumFixedValue = 0.0;
     184          plot.VisualProperties.XAxisMaximumAuto = false;
     185          plot.VisualProperties.XAxisMaximumFixedValue = bestKnownAlleles.Length;
     186          plot.VisualProperties.YAxisMinimumAuto = false;
     187          plot.VisualProperties.YAxisMinimumFixedValue = 0.0;
     188          plot.VisualProperties.YAxisMaximumAuto = false;
     189          plot.VisualProperties.YAxisMaximumFixedValue = 1.0;
     190          var row = new ScatterPlotDataRow("Solutions of Current Generation", null, points);
     191          row.VisualProperties.PointStyle = ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Circle;
     192          row.VisualProperties.PointSize = 5;
     193          plot.Rows.Add(row);
     194
     195          if (!results.ContainsKey("Scatter Plot"))
     196            results.Add(new Result("Scatter Plot", plot));
     197          else
     198            results["Scatter Plot"].Value = plot;
     199          if (storeHistory) {
     200            if (!results.ContainsKey("Scatter Plot History")) {
     201              results.Add(new Result("Scatter Plot History", new ScatterPlotHistory()));
     202            }
     203            ((ScatterPlotHistory)results["Scatter Plot History"].Value).Add(plot);
     204          }
    161205        }
    162206
     
    205249          allelesTable.Rows["Lost Alleles of Best Known Solution"].VisualProperties.SecondYAxis = true;
    206250          allelesTable.Rows["Lost Alleles of Best Known Solution"].VisualProperties.StartIndexZero = true;
     251
     252          allelesTable.Rows.Add(new DataRow("Average Contained Alleles of Best Known Solution", null));
     253          allelesTable.Rows["Average Contained Alleles of Best Known Solution"].VisualProperties.SecondYAxis = true;
     254          allelesTable.Rows["Average Contained Alleles of Best Known Solution"].VisualProperties.StartIndexZero = true;
    207255
    208256          results.Add(new Result("Alleles", allelesTable));
     
    222270        allelesTable.Rows["Fixed Alleles of Best Known Solution"].Values.Add(fixedRelevantAllelesCount);
    223271        allelesTable.Rows["Lost Alleles of Best Known Solution"].Values.Add(lostRelevantAllelesCount);
     272        allelesTable.Rows["Average Contained Alleles of Best Known Solution"].Values.Add(avgContainedReleventAlleles);
    224273
    225274        // store alleles values
Note: See TracChangeset for help on using the changeset viewer.