Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/21/14 01:31:20 (10 years ago)
Author:
bburlacu
Message:

#1772: Added the ability to ignore variable weights or constant values to the BottomUpSimilarityCalculator and added parameters to the SymbolicDataAnalysisBottomUpDiversityAnalyzer. Added separate methods in the MaxCommonSubtreeSimilarityCalculator for performing matching with full subtrees (including all leaves) or without (like the old - and better - behavior).

Location:
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
Files:
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisBottomUpDiversityAnalyzer.cs

    r11291 r11482  
    2222using HeuristicLab.Analysis;
    2323using HeuristicLab.Core;
     24using HeuristicLab.Data;
     25using HeuristicLab.Parameters;
    2426using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2527
     
    2830  [StorableClass]
    2931  public class SymbolicDataAnalysisBottomUpDiversityAnalyzer : SingleObjectivePopulationDiversityAnalyzer {
     32    private const string MatchConstantValuesParameterName = "MatchConstantValues";
     33    private const string MatchVariableWeightsParameterName = "MatchVariableWeights";
     34
     35    public IValueParameter<BoolValue> MatchVariableWeightsParameter {
     36      get { return (IValueParameter<BoolValue>)Parameters[MatchVariableWeightsParameterName]; }
     37    }
     38
     39    public IValueParameter<BoolValue> MatchConstantValuesParameter {
     40      get { return (IValueParameter<BoolValue>)Parameters[MatchConstantValuesParameterName]; }
     41    }
     42
     43    public bool MatchConstantValues {
     44      get { return MatchConstantValuesParameter.Value.Value; }
     45      set {
     46        MatchConstantValuesParameter.Value.Value = value;
     47        ((BottomUpSimilarityCalculator)SimilarityCalculator).MatchConstantValues = value;
     48      }
     49    }
     50
     51    public bool MatchVariableWeights {
     52      get { return MatchVariableWeightsParameter.Value.Value; }
     53      set {
     54        MatchVariableWeightsParameter.Value.Value = value;
     55        ((BottomUpSimilarityCalculator)SimilarityCalculator).MatchVariableWeights = value;
     56      }
     57    }
     58
    3059    [StorableConstructor]
    3160    protected SymbolicDataAnalysisBottomUpDiversityAnalyzer(bool deserializing) : base(deserializing) { }
    3261
     62    [StorableHook(HookType.AfterDeserialization)]
     63    private void AfterDeserialization() {
     64      if (!Parameters.ContainsKey(MatchConstantValuesParameterName))
     65        Parameters.Add(new ValueParameter<BoolValue>(MatchConstantValuesParameterName, "Specifies if the similarity calculator should match constant values.", new BoolValue(true)));
     66      if (!Parameters.ContainsKey(MatchVariableWeightsParameterName))
     67        Parameters.Add(new ValueParameter<BoolValue>(MatchVariableWeightsParameterName, "Specifies if the similarity calculator should match variable weights", new BoolValue(true)));
     68    }
     69
    3370    public SymbolicDataAnalysisBottomUpDiversityAnalyzer() {
    3471      SimilarityCalculator = new BottomUpSimilarityCalculator { SolutionVariableName = "SymbolicExpressionTree" };
     72      Parameters.Add(new ValueParameter<BoolValue>(MatchConstantValuesParameterName, "Specifies if the similarity calculator should match constant values.", new BoolValue(true)));
     73      Parameters.Add(new ValueParameter<BoolValue>(MatchVariableWeightsParameterName, "Specifies if the similarity calculator should match variable weights", new BoolValue(true)));
    3574    }
    3675  }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMaxCommonSubtreeDiversityAnalyzer.cs

    r11473 r11482  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Analyzers {
    27   [Item("SymbolicDataAnalysisBottomUpDiversityAnalyzer", "A diversity analyzer based on the bottom-up similarity between trees.")]
     27  [Item("SymbolicDataAnalysisMaxCommonSubtreeDiversityAnalyzer", "A diversity analyzer based on the max common subtree similarity between trees.")]
    2828  [StorableClass]
    29   public class SymbolicDataAnalysisBottomUpDiversityAnalyzer : SingleObjectivePopulationDiversityAnalyzer {
     29  public class SymbolicDataAnalysisMaxCommonSubtreeDiversityAnalyzer : SingleObjectivePopulationDiversityAnalyzer {
    3030    [StorableConstructor]
    31     protected SymbolicDataAnalysisBottomUpDiversityAnalyzer(bool deserializing) : base(deserializing) { }
     31    protected SymbolicDataAnalysisMaxCommonSubtreeDiversityAnalyzer(bool deserializing) : base(deserializing) { }
    3232
    33     public SymbolicDataAnalysisBottomUpDiversityAnalyzer() {
    34       SimilarityCalculator = new BottomUpSimilarityCalculator { SolutionVariableName = "SymbolicExpressionTree" };
     33    public SymbolicDataAnalysisMaxCommonSubtreeDiversityAnalyzer() {
     34      SimilarityCalculator = new MaxCommonSubtreeSimilarityCalculator { SolutionVariableName = "SymbolicExpressionTree" };
    3535    }
    3636  }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r11458 r11482  
    174174  </ItemGroup>
    175175  <ItemGroup>
     176    <Compile Include="Analyzers\BuildingBlockAnalyzers\SymbolicDataAnalysisPoly10Analyzer.cs" />
     177    <Compile Include="Analyzers\SymbolicDataAnalysisMaxCommonSubtreeDiversityAnalyzer.cs" />
    176178    <Compile Include="Analyzers\SymbolicDataAnalysisBottomUpDiversityAnalyzer.cs" />
    177179    <Compile Include="Analyzers\SymbolicDataAnalysisPhenotypicDiversityAnalyzer.cs" />
     
    191193      <SubType>Code</SubType>
    192194    </Compile>
    193     <Compile Include="Crossovers\SymbolicDataAnalysisExpressionDiversityPreservingCrossover.cs" />
     195    <Compile Include="Analyzers\SymbolicDataAnalysisUsefulGenesAnalyzer.cs" />
    194196    <Compile Include="Importer\SymbolicExpressionImporter.cs" />
    195197    <Compile Include="Importer\Token.cs" />
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators/BottomUpSimilarityCalculator.cs

    r11458 r11482  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Diagnostics;
    2425using System.Linq;
    2526using HeuristicLab.Common;
     
    3435  public class BottomUpSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator, ISymbolicDataAnalysisExpressionSimilarityCalculator {
    3536    private readonly HashSet<string> commutativeSymbols = new HashSet<string> { "Addition", "Multiplication", "Average", "And", "Or", "Xor" };
     37    public bool MatchVariableWeights { get; set; }
     38    public bool MatchConstantValues { get; set; }
    3639
    3740    public BottomUpSimilarityCalculator() { }
     41
     42    protected BottomUpSimilarityCalculator(BottomUpSimilarityCalculator original, Cloner cloner)
     43      : base(original, cloner) {
     44    }
    3845
    3946    public override IDeepCloneable Clone(Cloner cloner) {
     
    4754      var map = ComputeBottomUpMapping(t1.Root, t2.Root);
    4855      return 2.0 * map.Count / (t1.Length + t2.Length);
    49     }
    50 
    51     protected BottomUpSimilarityCalculator(BottomUpSimilarityCalculator original, Cloner cloner)
    52       : base(original, cloner) {
    5356    }
    5457
     
    9699          var t = eW.Current;
    97100
    98           if (reverseMap.ContainsKey(t)) {
    99             throw new Exception("A mapping to this node already exists.");
    100           }
     101          Debug.Assert(!reverseMap.ContainsKey(t));
    101102
    102103          forwardMap[s] = t;
     
    125126      foreach (var n in nodes) {
    126127        if (n.SubtreeCount == 0) {
    127           var label = n.ToString();
     128          var label = Label(n);
    128129          if (!labelMap.ContainsKey(label)) {
    129130            var z = new GraphNode { SymbolicExpressionTreeNode = n, Label = label };
     
    204205    }
    205206
     207    private string Label(ISymbolicExpressionTreeNode node) {
     208      var constant = node as ConstantTreeNode;
     209      if (constant != null && !MatchConstantValues)
     210        return constant.Symbol.Name;
     211      var variable = node as VariableTreeNode;
     212      if (variable != null && !MatchVariableWeights) {
     213        return variable.VariableName;
     214      }
     215      return node.ToString();
     216    }
     217
    206218    private class GraphNode {
    207219      public ISymbolicExpressionTreeNode SymbolicExpressionTreeNode;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators/MaxCommonSubtreeSimilarityCalculator.cs

    r11458 r11482  
    3131  [Item("MaxCommonSubtreeSimilarityCalculator", "A similarity calculator based on the size of the maximum common subtree between two trees")]
    3232  public class MaxCommonSubtreeSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator, ISymbolicDataAnalysisExpressionSimilarityCalculator {
     33    [Storable]
    3334    private readonly SymbolicExpressionTreeNodeSimilarityComparer comparer;
    3435    public bool MatchVariableNames {
     
    8889    }
    8990
    90     public static double MaxCommonSubtreeSimilarity(ISymbolicExpressionTree a, ISymbolicExpressionTree b, SymbolicExpressionTreeNodeSimilarityComparer comparer) {
     91    public static double MaxCommonSubtreeSimilarity(ISymbolicExpressionTree a, ISymbolicExpressionTree b, ISymbolicExpressionTreeNodeSimilarityComparer comparer) {
     92      int m = SymbolicExpressionTreeMatching.Match(a.Root, b.Root, comparer);
     93      return 2.0 * m / (a.Length + b.Length);
     94    }
     95
     96    public static double MaxCommonSubtreeSimilarityRestricted(ISymbolicExpressionTree a, ISymbolicExpressionTree b, SymbolicExpressionTreeNodeSimilarityComparer comparer) {
    9197      int max = 0;
    9298      var rootA = a.Root.GetSubtree(0).GetSubtree(0);
     
    99105          if (lenB <= max) continue;
    100106          int matches = SymbolicExpressionTreeMatching.Match(aa, bb, comparer);
     107          //          if (max < matches)
    101108          if (matches == lenB && max < matches)
    102109            max = matches;
Note: See TracChangeset for help on using the changeset viewer.