Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11221


Ignore:
Timestamp:
07/23/14 22:49:51 (10 years ago)
Author:
bburlacu
Message:

#2215: Fixed incorrect namespace of the BottomUpSimilarityCalculator. Changed signature of ComputeBottomMapping method to take tree nodes as arguments rather than trees, because we should be able to compute the bottom-up distance for any two subtrees. Added internal diversity calculator based on the bottom-up distance, which computes the average diversity of all the nodes inside a tree individual.

Location:
branches/HeuristicLab.BottomUpTreeDistance
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r11219 r11221  
    197197  </ItemGroup>
    198198  <ItemGroup>
     199    <Compile Include="Analyzers\SymbolicDataAnalysisInternalDiversityAnalyzer.cs" />
    199200    <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs" />
    200201    <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer.cs" />
  • branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators/BottomUpSimilarityCalculator.cs

    r11220 r11221  
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3030
    31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.SimilarityCalculators {
     31namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    3232  [StorableClass]
    3333  [Item("BottomUpSimilarityCalculator", "A similarity calculator which uses the tree bottom-up distance as a similarity metric.")]
     
    5959        return 1;
    6060
    61       var map = ComputeBottomUpMapping(t1, t2);
     61      var map = ComputeBottomUpMapping(t1.Root, t2.Root);
    6262      return 2.0 * map.Count / (t1.Length + t2.Length);
    6363    }
    6464
    65 
    66     public Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> ComputeBottomUpMapping(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2) {
    67       var compactedGraph = Compact(t1, t2);
     65    public Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> ComputeBottomUpMapping(ISymbolicExpressionTreeNode n1, ISymbolicExpressionTreeNode n2) {
     66      var compactedGraph = Compact(n1, n2);
    6867
    6968      var forwardMap = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>(); // nodes of t1 => nodes of t2
    7069      var reverseMap = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>(); // nodes of t2 => nodes of t1
    7170
    72       foreach (var v in t1.IterateNodesBreadth()) {
     71      foreach (var v in n1.IterateNodesBreadth()) {
    7372        if (forwardMap.ContainsKey(v)) continue;
    7473        var kv = compactedGraph[v];
    7574        ISymbolicExpressionTreeNode w = null;
    76         foreach (var t in t2.IterateNodesBreadth()) {
     75        foreach (var t in n2.IterateNodesBreadth()) {
    7776          if (reverseMap.ContainsKey(t) || compactedGraph[t] != kv) continue;
    7877          w = t;
     
    103102    /// <param name="t2">The second tree</param>
    104103    /// <returns>The compacted DAG representing the two trees</returns>
    105     private Dictionary<ISymbolicExpressionTreeNode, IVertex> Compact(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2) {
     104    private Dictionary<ISymbolicExpressionTreeNode, IVertex> Compact(ISymbolicExpressionTreeNode n1, ISymbolicExpressionTreeNode n2) {
    106105      var nodesToVertices = new Dictionary<ISymbolicExpressionTreeNode, IVertex>(); // K
    107106      var labelsToVertices = new Dictionary<string, IVertex>(); // L
     
    109108      var vertices = new List<IVertex>(); // G
    110109
    111       var nodes = t1.IterateNodesPostfix().Concat(t2.IterateNodesPostfix()); // the disjoint union F
     110      var nodes = n1.IterateNodesPostfix().Concat(n2.IterateNodesPostfix()); // the disjoint union F
    112111      var queue = new Queue<ISymbolicExpressionTreeNode>();
    113112
  • branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators/MaxCommonSubtreeSimilarityCalculator.cs

    r11219 r11221  
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2828
    29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.SimilarityCalculators {
     29namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    3030  [StorableClass]
    3131  [Item("MaxCommonSubtreeSimilarityCalculator", "A similarity calculator based on the size of the maximum common subtree between two trees")]
  • branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs

    r11219 r11221  
    3434using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3535using HeuristicLab.PluginInfrastructure;
    36 using HeuristicLab.Problems.DataAnalysis.Symbolic.SimilarityCalculators;
    3736using HeuristicLab.Problems.Instances;
    3837
  • branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Tests/BottomUpSimilarityCalculatorTest.cs

    r11220 r11221  
    88using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    99using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
    10 using HeuristicLab.Problems.DataAnalysis.Symbolic.SimilarityCalculators;
    1110using HeuristicLab.Random;
    1211using Microsoft.VisualStudio.TestTools.UnitTesting;
     
    3332      TestMatchedNodes("(+ 1 2)", "(+ 2 1)", 5);
    3433      TestMatchedNodes("(- 2 1)", "(- 1 2)", 2);
     34      TestMatchedNodes("(* (variable 1 X1) (variable 1 X2))", "(* (+ (variable 1 X1) 1) (+ (variable 1 X2) 1))", 2);
    3535
    3636      TestMatchedNodes("(* (variable 1 X1) (variable 1 X2))", "(* (+ (variable 1 X1) 1) (variable 1 X2))", 2);
     
    5252      var t2 = importer.Import(expr2);
    5353
    54       var mapping = busCalculator.ComputeBottomUpMapping(t1, t2);
     54      var mapping = busCalculator.ComputeBottomUpMapping(t1.Root, t2.Root);
    5555      var c = mapping.Count;
    5656
Note: See TracChangeset for help on using the changeset viewer.