Changeset 11239 for branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic
- Timestamp:
- 07/30/14 13:44:14 (10 years ago)
- Location:
- branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Files:
-
- 5 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisInternalDiversityAnalyzer.cs
r11224 r11239 42 42 43 43 private const string ResultCollectionParameterName = "Results"; 44 private readonly BottomUp SimilarityCalculator busCalculator;44 private readonly BottomUpTreeSimilarityCalculator busCalculator; 45 45 46 46 public SymbolicDataAnalysisInternalDiversityAnalyzer() { 47 busCalculator = new BottomUp SimilarityCalculator();47 busCalculator = new BottomUpTreeSimilarityCalculator(); 48 48 49 49 Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName)); -
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r11221 r11239 225 225 <Compile Include="Matching\SymbolicExpressionTreeNodeComparer.cs" /> 226 226 <Compile Include="Matching\SymbolicExpressionTreeNodeSimilarityComparer.cs" /> 227 <Compile Include="SimilarityCalculators\BottomUp SimilarityCalculator.cs" />227 <Compile Include="SimilarityCalculators\BottomUpTreeSimilarityCalculator.cs" /> 228 228 <Compile Include="SimilarityCalculators\MaxCommonSubtreeSimilarityCalculator.cs" /> 229 229 <Compile Include="SymbolicExpressionTreeBacktransformator.cs" /> -
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Matching/SymbolicExpressionTreeMatching.cs
r10562 r11239 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 5 * This file is part of HeuristicLab. 6 * 7 * HeuristicLab is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * HeuristicLab is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 #endregion 21 22 using System; 2 23 using System.Collections.Generic; 3 24 using System.Linq; … … 29 50 /// </summary> 30 51 /// <returns>Number of pairs that were matched</returns> 31 public static int Match(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b, SymbolicExpressionTreeNodeSimilarityComparer comp) {52 public static int Match(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b, ISymbolicExpressionTreeNodeSimilarityComparer comp) { 32 53 if (!comp.Equals(a, b)) return 0; 33 54 int m = a.SubtreeCount; -
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators/BottomUpTreeSimilarityCalculator.cs
r11236 r11239 31 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 32 32 [StorableClass] 33 [Item("BottomUpSimilarityCalculator", "A similarity calculator which uses the tree bottom-up distance as a similarity metric.")] 34 public class BottomUpSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator { 35 private readonly HashSet<string> commutativeSymbols = new HashSet<string> { "Addition", "Multiplication", "Average", "And", "Or", "Xor" }; 36 37 public BottomUpSimilarityCalculator() { } 33 [Item("BottomUpTreeSimilarityCalculator", "A similarity calculator which uses the tree bottom-up distance as a similarity metric.")] 34 public class BottomUpTreeSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator { 35 private readonly HashSet<string> commutativeSymbols; 36 37 public BottomUpTreeSimilarityCalculator() { 38 commutativeSymbols = new HashSet<string>(); 39 } 40 41 public BottomUpTreeSimilarityCalculator(IEnumerable<string> commutativeSymbols) { 42 this.commutativeSymbols = new HashSet<string>(commutativeSymbols); 43 } 38 44 39 45 public override IDeepCloneable Clone(Cloner cloner) { 40 return new BottomUp SimilarityCalculator(this, cloner);41 } 42 43 protected BottomUp SimilarityCalculator(BottomUpSimilarityCalculator original, Cloner cloner)46 return new BottomUpTreeSimilarityCalculator(this, cloner); 47 } 48 49 protected BottomUpTreeSimilarityCalculator(BottomUpTreeSimilarityCalculator original, Cloner cloner) 44 50 : base(original, cloner) { 45 51 } … … 57 63 58 64 return similarity; 65 } 66 67 public bool AddCommutativeSymbol(string symbolName) { 68 return commutativeSymbols.Add(symbolName); 69 } 70 71 public bool RemoveCommutativeSymbol(string symbolName) { 72 return commutativeSymbols.Remove(symbolName); 59 73 } 60 74 … … 187 201 } 188 202 203 /// <summary> 204 /// This method iterates the nodes of a subtree in breadth order while also sorting the subtrees of commutative symbols based on their label. 205 /// This is necessary in order for the mapping to be realized correctly. 206 /// </summary> 207 /// <param name="node">The root of the subtree</param> 208 /// <returns>A list of nodes in breadth order (with children of commutative symbols sorted by label)</returns> 189 209 private IEnumerable<ISymbolicExpressionTreeNode> IterateBreadthOrdered(ISymbolicExpressionTreeNode node) { 190 210 var list = new List<ISymbolicExpressionTreeNode> { node }; -
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators/MaxCommonSubtreeSimilarityCalculator.cs
r11230 r11239 56 56 } 57 57 58 public static double MaxCommonSubtreeSimilarity(ISymbolicExpressionTree a, ISymbolicExpressionTree b, SymbolicExpressionTreeNodeSimilarityComparer comparer) {58 public static double MaxCommonSubtreeSimilarity(ISymbolicExpressionTree a, ISymbolicExpressionTree b, ISymbolicExpressionTreeNodeSimilarityComparer comparer) { 59 59 int max = 0; 60 60 var rootA = a.Root.GetSubtree(0).GetSubtree(0); -
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r11221 r11239 234 234 Operators.Add(new SymbolicExpressionTreeLengthAnalyzer()); 235 235 Operators.Add(new SingleObjectivePopulationDiversityAnalyzer()); 236 Operators.Add(new BottomUp SimilarityCalculator());236 Operators.Add(new BottomUpTreeSimilarityCalculator()); 237 237 ParameterizeOperators(); 238 238 } … … 359 359 } 360 360 foreach (var op in operators.OfType<SingleObjectivePopulationDiversityAnalyzer>()) { 361 op.SimilarityCalculator = operators.OfType<BottomUp SimilarityCalculator>().SingleOrDefault();361 op.SimilarityCalculator = operators.OfType<BottomUpTreeSimilarityCalculator>().SingleOrDefault(); 362 362 } 363 363 }
Note: See TracChangeset
for help on using the changeset viewer.