Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/03/10 04:31:46 (14 years ago)
Author:
swagner
Message:

Worked on population diversity analysis (#1188)

File:
1 edited

Legend:

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

    r4703 r4715  
    9696        double[,] similarities = CalculateSimilarities(sortedSolutions);
    9797
    98         // calculate maximum similarities, average maximum similarity and average similarity
     98        // calculate minimum, average and maximum similarities
    9999        double similarity;
    100100        int count = sortedSolutions.Length;
     101        double[] minSimilarities = new double[sortedSolutions.Length];
     102        double[] avgSimilarities = new double[sortedSolutions.Length];
    101103        double[] maxSimilarities = new double[sortedSolutions.Length];
    102         double avgMaxSimilarity;
    103104        double avgSimilarity = 0;
    104         maxSimilarities.Initialize();
    105105        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            }
    111117          }
    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);
    115124
    116125        // fetch results collection
     
    147156          ((DoubleValue)results["Average Population Similarity"].Value).Value = avgSimilarity;
    148157
    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
    150169        if (!results.ContainsKey("Average Maximum Solution Similarity"))
    151170          results.Add(new Result("Average Maximum Solution Similarity", new DoubleValue(avgMaxSimilarity)));
     
    155174        // store population similarity data table
    156175        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));
    160179          DataRowVisualProperties visualProperties = new DataRowVisualProperties();
    161180          visualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Line;
    162181          visualProperties.StartIndexZero = true;
    163182          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));
    164185          similarityDataTable.Rows.Add(new DataRow("Average Maximum Solution Similarity", null, visualProperties));
    165186        } else {
    166           similarityDataTable = (DataTable)results["Population Similarity"].Value;
     187          similarityDataTable = (DataTable)results["Average Solution Similarity"].Value;
    167188        }
    168189        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);
    169192        similarityDataTable.Rows["Average Maximum Solution Similarity"].Values.Add(avgMaxSimilarity);
    170193
    171194        // 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));
    178207        } else {
    179           results["Maximum Solution Similarities"].Value = maxSimilaritiesDataTable;
     208          results["Minimum/Average/Maximum Solution Similarities"].Value = minAvgMaxSimilaritiesDataTable;
    180209        }
    181210
    182211        // store maximum similarities history
    183212        if (storeHistory) {
    184           if (!results.ContainsKey("Maximum Solution Similarities History")) {
     213          if (!results.ContainsKey("Minimum/Average/Maximum Solution Similarities History")) {
    185214            DataTableHistory history = new DataTableHistory();
    186             history.Add(maxSimilaritiesDataTable);
    187             results.Add(new Result("Maximum Solution Similarities History", history));
     215            history.Add(minAvgMaxSimilaritiesDataTable);
     216            results.Add(new Result("Minimum/Average/Maximum Solution Similarities History", history));
    188217          } else {
    189             ((DataTableHistory)results["Maximum Solution Similarities History"].Value).Add(maxSimilaritiesDataTable);
     218            ((DataTableHistory)results["Minimum/Average/Maximum Solution Similarities History"].Value).Add(minAvgMaxSimilaritiesDataTable);
    190219          }
    191220        }
Note: See TracChangeset for help on using the changeset viewer.