Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4949 for branches


Ignore:
Timestamp:
11/26/10 22:00:21 (14 years ago)
Author:
swinkler
Message:

Worked on structural population diversity analysis (#1278): Implemented management of genetic information items in dictionaries.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis.PopulationDiversityAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/FineGrainedStructuralPopulationDiversityAnalyzer.cs

    r4948 r4949  
    161161
    162162    protected override double[,] CalculateSimilarities(SymbolicExpressionTree[] solutions) {
     163      // collect information stored int the problem's parameters
    163164      double variableWeightSigma = 0;
    164165      double constantMinimumValue = 0;
     
    187188      }
    188189      variableNames.Add(ProblemData.TargetVariable.Value);
     190      // collect genetic information item lists and store them also in dictionaries
    189191      IList<GeneticInformationItem>[] geneticInformationItemsLists = new List<GeneticInformationItem>[n];
     192      IDictionary<string, IList<GeneticInformationItem>>[] geneticInformationItemsListsDictionaries = new IDictionary<string, IList<GeneticInformationItem>>[n];
    190193      for (int i = 0; i < n; i++) {
    191194        geneticInformationItemsLists[i] = GeneticInformationItem.getGeneticInformationItems(solutions[i].Root, variableNames, MinimumLevelDelta, MaximumLevelDelta);
    192       }
    193       double[,] result = new double[n, n];
     195        geneticInformationItemsListsDictionaries[i] = GeneticInformationItem.GetDictionary(geneticInformationItemsLists[i]);
     196      }
     197      // calculate solution similarities
     198      double[,] similarities = new double[n, n];
    194199      for (int i = 0; i < n; i++) {
    195200        for (int j = 0; j < n; j++) {
    196201          if (i == j)
    197             result[i, j] = 1;
     202            similarities[i, j] = 1;
    198203          else {
    199             IList<GeneticInformationItem> solution1GeneticItems = GeneticInformationItem.CopyList(geneticInformationItemsLists[i]);
    200             IList<GeneticInformationItem> solution2GeneticItems = GeneticInformationItem.CopyList(geneticInformationItemsLists[j]);
     204            IList<GeneticInformationItem> solution1GeneticItems = geneticInformationItemsLists[i];
     205            IDictionary<string, IList<GeneticInformationItem>> solution2GeneticItemsDictionary = GeneticInformationItem.CopyDictionary(geneticInformationItemsListsDictionaries[j]);
    201206            double similarity = 0;
    202207            for (int k = 0; k < solution1GeneticItems.Count; k++) {
    203               double bestPendantSimilarity;
    204               GeneticInformationItem bestPendant = GeneticInformationItem.FindBestPendant(solution1GeneticItems[k], solution2GeneticItems,
    205                 constantMinimumValue, constantMaximumValue, variableWeightSigma,
    206                 MaximumExpressionDepth, minimumTimeOffset, maximumTimeOffset,
    207                 LevelDifferenceCoefficient, AncestorIndexCoefficient, ConstantValueCoefficient, VariableWeightCoefficient,
    208                 TimeOffsetCoefficientCoefficient, VariableIndexCoefficient, AdditiveSimilarityCalculation,
    209                 out bestPendantSimilarity);
     208              double bestPendantSimilarity = 0;
     209              GeneticInformationItem item = solution1GeneticItems[k];
     210              GeneticInformationItem bestPendant = null;
     211              IList<GeneticInformationItem> geneticInformationItemsList = null;
     212              string key = GeneticInformationItem.GetKey(item);
     213              if (solution2GeneticItemsDictionary.ContainsKey(key)) {
     214                geneticInformationItemsList = solution2GeneticItemsDictionary[GeneticInformationItem.GetKey(item)];
     215                bestPendant = GeneticInformationItem.FindBestPendant(item, geneticInformationItemsList,
     216                  constantMinimumValue, constantMaximumValue, variableWeightSigma,
     217                  MaximumExpressionDepth, minimumTimeOffset, maximumTimeOffset,
     218                  LevelDifferenceCoefficient, AncestorIndexCoefficient, ConstantValueCoefficient, VariableWeightCoefficient,
     219                  TimeOffsetCoefficientCoefficient, VariableIndexCoefficient, AdditiveSimilarityCalculation,
     220                  out bestPendantSimilarity);
     221              }
    210222              if (bestPendant != null) {
    211223                similarity += bestPendantSimilarity;
    212224                if (PreventMultipleComparisonContribution)
    213                   solution2GeneticItems.Remove(bestPendant);
     225                  geneticInformationItemsList.Remove(bestPendant);
    214226              }
    215227            }
    216             result[i, j] = similarity / solution1GeneticItems.Count;
     228            similarities[i, j] = similarity / solution1GeneticItems.Count;
    217229          }
    218230        }
    219231      }
    220       return result;
     232      return similarities;
    221233    }
    222234
     
    278290        list.AddRange(GeneticInformationItemsList);
    279291        return list;
     292      }
     293
     294      public static string GetKey(GeneticInformationItem item) {
     295        return item.AncestorDefinition.Name.ToString() + "," + item.DescendantDefinition.Name.ToString();
     296      }
     297
     298      public static IDictionary<string, IList<GeneticInformationItem>> GetDictionary(IList<GeneticInformationItem> GeneticInformationItemsList) {
     299        IDictionary<string, IList<GeneticInformationItem>> dictionary = new Dictionary<string, IList<GeneticInformationItem>>();
     300        foreach (GeneticInformationItem item in GeneticInformationItemsList) {
     301          string key = GetKey(item);
     302          if (!dictionary.ContainsKey(key))
     303            dictionary.Add(key, new List<GeneticInformationItem>());
     304          dictionary[key].Add(item);
     305        }
     306        return dictionary;
     307      }
     308
     309      public static IDictionary<string, IList<GeneticInformationItem>> CopyDictionary(IDictionary<string, IList<GeneticInformationItem>> Dictionary) {
     310        IDictionary<string, IList<GeneticInformationItem>> copy = new Dictionary<string, IList<GeneticInformationItem>>();
     311        foreach (KeyValuePair<string, IList<GeneticInformationItem>> pair in Dictionary) {
     312          copy.Add(pair.Key, CopyList(pair.Value));
     313        }
     314        return copy;
    280315      }
    281316
Note: See TracChangeset for help on using the changeset viewer.