Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/25/10 23:16:23 (14 years ago)
Author:
swinkler
Message:

Worked on structural population diversity analysis (#1278): Implemented calculation of structural similarity of symbolic expression trees.

File:
1 edited

Legend:

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

    r4938 r4941  
    6868
    6969    protected override double[,] CalculateSimilarities(SymbolicExpressionTree[] solutions) {
    70       Constant c = null;
     70      Constant constant = null;
    7171      foreach (Symbol symbol in FunctionTreeGrammar.Symbols) {
    7272        if (symbol is Constant) {
    73           if (c != null) throw new InvalidProgramException("There are more and one constnat definitions in the given function tree grammar.");
    74           c = (Constant)symbol;
     73          if (constant != null) throw new InvalidProgramException("There are more and one constnat definitions in the given function tree grammar.");
     74          constant = (Constant)symbol;
    7575        }
    7676      }
     
    8181      }
    8282      variableNames.Add(ProblemData.TargetVariable.Value);
    83       IList<GeneticInformationItem>[] geneticInformationItemsList = new List<GeneticInformationItem>[n];
     83      IList<GeneticInformationItem>[] geneticInformationItemsLists = new List<GeneticInformationItem>[n];
    8484      for (int i = 0; i < n; i++) {
    85         geneticInformationItemsList[i] = GeneticInformationItem.getGeneticInformationItems(solutions[i].Root, variableNames, 0, int.MaxValue);
     85        // geneticInformationItemsList[i] = GeneticInformationItem.getGeneticInformationItems(solutions[i].Root, variableNames, MinimumLEvelDelta, MaximumLevelDelta);
     86        geneticInformationItemsLists[i] = GeneticInformationItem.getGeneticInformationItems(solutions[i].Root, variableNames, 0, int.MaxValue);
    8687      }
    8788      double[,] result = new double[n, n];
     
    9091          if (i == j)
    9192            result[i, j] = 1;
    92           else
    93             result[i, j] = 0;
     93          else {
     94            IList<GeneticInformationItem> solution1GeneticItems = GeneticInformationItem.CopyList(geneticInformationItemsLists[i]);
     95            IList<GeneticInformationItem> solution2GeneticItems = GeneticInformationItem.CopyList(geneticInformationItemsLists[j]);
     96            double similarity = 0;
     97            for (int k = 0; k < solution1GeneticItems.Count; k++) {
     98              double bestPendantSimilarity;
     99              // GeneticInformationItem bestPendant = GeneticInformationItem.FindBestPendant(solution1GeneticItems[k],
     100              //   ConstantMinimum, ConstantMaximum, VariableWeightSigma, MaximumTreeHeight, MaximumTimeOffset,
     101              //   LevelDifferenceCoefficient, AncestorIndexCoefficient, ConstantValueCoefficient, VariableWeightSigma, TimeOffsetCoefficient,
     102              //   VariableWeightCoefficient, AdditiveSimilarityCalculation, out bestPendantSimilarity);
     103              GeneticInformationItem bestPendant = GeneticInformationItem.FindBestPendant(solution1GeneticItems[k], solution2GeneticItems,
     104                -10, 10, 1, 100, 10,
     105                1, 1, 1, 1, 1, 1, true, out bestPendantSimilarity);
     106              if (bestPendant != null) {
     107                similarity += bestPendantSimilarity;
     108                // if (PreventMultipleComparisonContribution)
     109                if (true)
     110                  solution2GeneticItems.Remove(bestPendant);
     111              }
     112            }
     113            result[i, j] = similarity / solution1GeneticItems.Count;
     114          }
    94115        }
    95116      }
     
    151172      }
    152173
    153       /*
    154       public static GeneticInformationItem FindBestPendant(GeneticInformationItem Item, List<GeneticInformationItem> ComparisonItems,
    155           StructuralSimilarityAnalysisParameters Parameters,
    156           int MaxTreeHeight, int MaxTimeOffset,
     174      public static IList<GeneticInformationItem> CopyList(IList<GeneticInformationItem> GeneticInformationItemsList) {
     175        List<GeneticInformationItem> list = new List<GeneticInformationItem>(GeneticInformationItemsList.Count);
     176        list.AddRange(GeneticInformationItemsList);
     177        return list;
     178      }
     179
     180      public static GeneticInformationItem FindBestPendant(GeneticInformationItem Item, IList<GeneticInformationItem> ComparisonItems,
     181          double ConstantMinimum, double ConstantMaximum, double VariableWeightSigma,
     182          int MaximumTreeHeight, int MaximumTimeOffset,
     183          double LevelDifferenceCoefficient, double AncestorIndexCoefficient,
     184          double ConstantValueCoefficient, double VariableWeightCoefficient, double TimeOffsetCoefficient, double VariableIndexCoefficient,
     185          bool AdditiveSimilarityCalculation,
    157186          out double BestPendantSimilarity) {
    158187        int maxSimilarityIndex = -1;
    159188        double similarity, maxSimilarity = -double.MaxValue;
    160189        for (int i = 0; i < ComparisonItems.Count; i++) {
    161           similarity = Similarity(Item, ComparisonItems[i], Parameters, MaxTreeHeight, MaxTimeOffset);
     190          similarity = Similarity(Item, ComparisonItems[i], ConstantMinimum, ConstantMaximum, VariableWeightSigma, MaximumTreeHeight, MaximumTimeOffset,
     191            LevelDifferenceCoefficient, AncestorIndexCoefficient, ConstantValueCoefficient, VariableWeightSigma, TimeOffsetCoefficient,
     192            VariableWeightCoefficient, AdditiveSimilarityCalculation);
    162193          if (!double.IsNaN(similarity) && similarity > maxSimilarity) {
    163194            maxSimilarity = similarity;
     
    170201        else
    171202          return null;
    172       }*/
     203      }
    173204
    174205      public static double Similarity(GeneticInformationItem Item1, GeneticInformationItem Item2,
    175           GlobalSymbolicExpressionGrammar ExpressionGrammar, double ConstantMinimum, double ConstantMaximum, double VariableWeightSigma,
     206          double ConstantMinimum, double ConstantMaximum, double VariableWeightSigma,
    176207          int MaximumTreeHeight, int MaximumTimeOffset,
    177           // StructuralSimilarityAnalysisParameters Parameters,
    178           double LevelDifferenceCoefficient,
    179           double AncestorIndexCoefficient,
    180           double ConstantValueCoefficient,
    181           double VariableWeightCoefficient,
    182           double TimeOffsetCoefficient,
    183           double VariableIndexCoefficient,
    184           bool AdditiveSimilarityCalculation
    185         ) {
     208          double LevelDifferenceCoefficient, double AncestorIndexCoefficient,
     209          double ConstantValueCoefficient, double VariableWeightCoefficient, double TimeOffsetCoefficient, double VariableIndexCoefficient,
     210          bool AdditiveSimilarityCalculation) {
    186211
    187212        if (Item1.AncestorDefinition != Item2.AncestorDefinition || Item1.DescendantDefinition != Item2.DescendantDefinition)
Note: See TracChangeset for help on using the changeset viewer.