Changeset 8283 for trunk/sources/HeuristicLab.Analysis
- Timestamp:
- 07/11/12 01:29:52 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Analysis/3.3/AlleleFrequencyAnalysis/AlleleFrequencyAnalyzer.cs
r7259 r8283 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 88 89 } 89 90 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 } 91 100 private class AlleleFrequencyIdEqualityComparer : IEqualityComparer<AlleleFrequency> { 92 101 public bool Equals(AlleleFrequency x, AlleleFrequency y) { … … 112 121 bool max = MaximizationParameter.ActualValue.Value; 113 122 ItemArray<T> solutions = SolutionParameter.ActualValue; 114 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;123 double[] qualities = QualityParameter.ActualValue.Select(x => x.Value).ToArray(); 115 124 T bestKnownSolution = BestKnownSolutionParameter.ActualValue; 116 125 bool storeHistory = StoreHistoryParameter.Value.Value; … … 120 129 if (!max) { 121 130 bestIndex = qualities 122 .Select((x, i ndex) => new { index, x.Value})131 .Select((x, i) => new { Index = i, Value = x }) 123 132 .OrderBy(x => x.Value) 124 .First(). index;133 .First().Index; 125 134 } else { 126 135 bestIndex = qualities 127 .Select((x, i ndex) => new { index, x.Value})136 .Select((x, i) => new { Index = i, Value = x }) 128 137 .OrderByDescending(x => x.Value) 129 .First(). index;138 .First().Index; 130 139 } 131 140 … … 142 151 x.Count() / ((double)solutions.Length), 143 152 x.Average(a => a.Allele.Impact), 144 x.Average(a => a.Quality .Value),153 x.Average(a => a.Quality), 145 154 bestKnownAlleles == null ? false : bestKnownAlleles.Any(a => a.Id == x.Key), 146 155 bestAlleles.Any(a => a.Id == x.Key))); … … 159 168 } else { 160 169 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 } 161 205 } 162 206 … … 205 249 allelesTable.Rows["Lost Alleles of Best Known Solution"].VisualProperties.SecondYAxis = true; 206 250 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; 207 255 208 256 results.Add(new Result("Alleles", allelesTable)); … … 222 270 allelesTable.Rows["Fixed Alleles of Best Known Solution"].Values.Add(fixedRelevantAllelesCount); 223 271 allelesTable.Rows["Lost Alleles of Best Known Solution"].Values.Add(lostRelevantAllelesCount); 272 allelesTable.Rows["Average Contained Alleles of Best Known Solution"].Values.Add(avgContainedReleventAlleles); 224 273 225 274 // store alleles values
Note: See TracChangeset
for help on using the changeset viewer.