- Timestamp:
- 11/03/10 04:31:46 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Analysis/3.3/PopulationDiversityAnalyzer.cs
r4703 r4715 96 96 double[,] similarities = CalculateSimilarities(sortedSolutions); 97 97 98 // calculate m aximum similarities, average maximum similarity and average similarity98 // calculate minimum, average and maximum similarities 99 99 double similarity; 100 100 int count = sortedSolutions.Length; 101 double[] minSimilarities = new double[sortedSolutions.Length]; 102 double[] avgSimilarities = new double[sortedSolutions.Length]; 101 103 double[] maxSimilarities = new double[sortedSolutions.Length]; 102 double avgMaxSimilarity;103 104 double avgSimilarity = 0; 104 maxSimilarities.Initialize();105 105 for (int i = 0; i < count; i++) { 106 for (int j = i + 1; j < count; j++) { 107 similarity = similarities[i, j]; 108 avgSimilarity += similarity; 109 if (maxSimilarities[i] < similarity) maxSimilarities[i] = similarity; 110 if (maxSimilarities[j] < similarity) maxSimilarities[j] = similarity; 106 minSimilarities[i] = 1; 107 avgSimilarities[i] = 0; 108 maxSimilarities[i] = 0; 109 for (int j = 0; j < count; j++) { 110 if (i != j) { 111 similarity = similarities[i, j]; 112 avgSimilarity += similarity; 113 if (minSimilarities[i] > similarity) minSimilarities[i] = similarity; 114 avgSimilarities[i] += similarity; 115 if (maxSimilarities[i] < similarity) maxSimilarities[i] = similarity; 116 } 111 117 } 112 } 113 avgMaxSimilarity = maxSimilarities.Average(); 114 avgSimilarity = avgSimilarity / ((count - 1) * count / 2); 118 avgSimilarities[i] = avgSimilarities[i] / (count - 1); 119 } 120 double avgMinSimilarity = minSimilarities.Average(); 121 double avgAvgSimilarity = avgSimilarities.Average(); 122 double avgMaxSimilarity = maxSimilarities.Average(); 123 avgSimilarity = avgSimilarity / (count * count - count); 115 124 116 125 // fetch results collection … … 147 156 ((DoubleValue)results["Average Population Similarity"].Value).Value = avgSimilarity; 148 157 149 // store average maximum similarity 158 // store average minimum, average and maximum similarity 159 if (!results.ContainsKey("Average Minimum Solution Similarity")) 160 results.Add(new Result("Average Minimum Solution Similarity", new DoubleValue(avgMinSimilarity))); 161 else 162 ((DoubleValue)results["Average Minimum Solution Similarity"].Value).Value = avgMinSimilarity; 163 164 if (!results.ContainsKey("Average Average Solution Similarity")) 165 results.Add(new Result("Average Average Solution Similarity", new DoubleValue(avgAvgSimilarity))); 166 else 167 ((DoubleValue)results["Average Average Solution Similarity"].Value).Value = avgAvgSimilarity; 168 150 169 if (!results.ContainsKey("Average Maximum Solution Similarity")) 151 170 results.Add(new Result("Average Maximum Solution Similarity", new DoubleValue(avgMaxSimilarity))); … … 155 174 // store population similarity data table 156 175 DataTable similarityDataTable; 157 if (!results.ContainsKey(" Population Similarity")) {158 similarityDataTable = new DataTable(" Population Similarity");159 results.Add(new Result(" Population Similarity", similarityDataTable));176 if (!results.ContainsKey("Average Solution Similarity")) { 177 similarityDataTable = new DataTable("Average Solution Similarity"); 178 results.Add(new Result("Average Solution Similarity", similarityDataTable)); 160 179 DataRowVisualProperties visualProperties = new DataRowVisualProperties(); 161 180 visualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Line; 162 181 visualProperties.StartIndexZero = true; 163 182 similarityDataTable.Rows.Add(new DataRow("Average Population Similarity", null, visualProperties)); 183 similarityDataTable.Rows.Add(new DataRow("Average Minimum Solution Similarity", null, visualProperties)); 184 similarityDataTable.Rows.Add(new DataRow("Average Average Solution Similarity", null, visualProperties)); 164 185 similarityDataTable.Rows.Add(new DataRow("Average Maximum Solution Similarity", null, visualProperties)); 165 186 } else { 166 similarityDataTable = (DataTable)results[" Population Similarity"].Value;187 similarityDataTable = (DataTable)results["Average Solution Similarity"].Value; 167 188 } 168 189 similarityDataTable.Rows["Average Population Similarity"].Values.Add(avgSimilarity); 190 similarityDataTable.Rows["Average Minimum Solution Similarity"].Values.Add(avgMinSimilarity); 191 similarityDataTable.Rows["Average Average Solution Similarity"].Values.Add(avgAvgSimilarity); 169 192 similarityDataTable.Rows["Average Maximum Solution Similarity"].Values.Add(avgMaxSimilarity); 170 193 171 194 // store maximum similarities 172 DataTable maxSimilaritiesDataTable = new DataTable("Maximum Solution Similarities"); 173 maxSimilaritiesDataTable.Rows.Add(new DataRow("Maximum Solution Similarity")); 174 maxSimilaritiesDataTable.Rows["Maximum Solution Similarity"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Columns; 175 maxSimilaritiesDataTable.Rows["Maximum Solution Similarity"].Values.AddRange(maxSimilarities); 176 if (!results.ContainsKey("Maximum Solution Similarities")) { 177 results.Add(new Result("Maximum Solution Similarities", maxSimilaritiesDataTable)); 195 DataTable minAvgMaxSimilaritiesDataTable = new DataTable("Minimum/Average/Maximum Solution Similarities"); 196 minAvgMaxSimilaritiesDataTable.Rows.Add(new DataRow("Minimum Solution Similarity")); 197 minAvgMaxSimilaritiesDataTable.Rows["Minimum Solution Similarity"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Columns; 198 minAvgMaxSimilaritiesDataTable.Rows["Minimum Solution Similarity"].Values.AddRange(minSimilarities); 199 minAvgMaxSimilaritiesDataTable.Rows.Add(new DataRow("Average Solution Similarity")); 200 minAvgMaxSimilaritiesDataTable.Rows["Average Solution Similarity"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Columns; 201 minAvgMaxSimilaritiesDataTable.Rows["Average Solution Similarity"].Values.AddRange(avgSimilarities); 202 minAvgMaxSimilaritiesDataTable.Rows.Add(new DataRow("Maximum Solution Similarity")); 203 minAvgMaxSimilaritiesDataTable.Rows["Maximum Solution Similarity"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Columns; 204 minAvgMaxSimilaritiesDataTable.Rows["Maximum Solution Similarity"].Values.AddRange(maxSimilarities); 205 if (!results.ContainsKey("Minimum/Average/Maximum Solution Similarities")) { 206 results.Add(new Result("Minimum/Average/Maximum Solution Similarities", minAvgMaxSimilaritiesDataTable)); 178 207 } else { 179 results["M aximum Solution Similarities"].Value = maxSimilaritiesDataTable;208 results["Minimum/Average/Maximum Solution Similarities"].Value = minAvgMaxSimilaritiesDataTable; 180 209 } 181 210 182 211 // store maximum similarities history 183 212 if (storeHistory) { 184 if (!results.ContainsKey("M aximum Solution Similarities History")) {213 if (!results.ContainsKey("Minimum/Average/Maximum Solution Similarities History")) { 185 214 DataTableHistory history = new DataTableHistory(); 186 history.Add(m axSimilaritiesDataTable);187 results.Add(new Result("M aximum Solution Similarities History", history));215 history.Add(minAvgMaxSimilaritiesDataTable); 216 results.Add(new Result("Minimum/Average/Maximum Solution Similarities History", history)); 188 217 } else { 189 ((DataTableHistory)results["M aximum Solution Similarities History"].Value).Add(maxSimilaritiesDataTable);218 ((DataTableHistory)results["Minimum/Average/Maximum Solution Similarities History"].Value).Add(minAvgMaxSimilaritiesDataTable); 190 219 } 191 220 }
Note: See TracChangeset
for help on using the changeset viewer.