Changeset 12155 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching
- Timestamp:
- 03/07/15 12:11:09 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeBottomUpSimilarityCalculator.cs
r12017 r12155 34 34 [StorableClass] 35 35 [Item("SymbolicExpressionTreeBottomUpSimilarityCalculator", "A similarity calculator which uses the tree bottom-up distance as a similarity metric.")] 36 public class SymbolicExpressionTreeBottomUpSimilarityCalculator : S ingleObjectiveSolutionSimilarityCalculator, ISymbolicDataAnalysisExpressionSimilarityCalculator {36 public class SymbolicExpressionTreeBottomUpSimilarityCalculator : SolutionSimilarityCalculator { 37 37 private readonly HashSet<string> commutativeSymbols = new HashSet<string> { "Addition", "Multiplication", "Average", "And", "Or", "Xor" }; 38 38 39 public SymbolicExpressionTreeBottomUpSimilarityCalculator() { } 40 protected override bool IsCommutative { get { return true; } } 39 41 40 42 [StorableConstructor] … … 60 62 61 63 public override double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution) { 64 if (leftSolution == rightSolution) 65 return 1.0; 66 62 67 var t1 = leftSolution.Variables[SolutionVariableName].Value as ISymbolicExpressionTree; 63 68 var t2 = rightSolution.Variables[SolutionVariableName].Value as ISymbolicExpressionTree; -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeMatching.cs
r11927 r12155 2 2 3 3 /* HeuristicLab 4 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)4 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 5 5 * 6 6 * This file is part of HeuristicLab. -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator.cs
r11927 r12155 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 30 30 [StorableClass] 31 31 [Item("SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator", "A similarity calculator based on the size of the maximum common subtree between two trees")] 32 public class SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator : S ingleObjectiveSolutionSimilarityCalculator, ISymbolicDataAnalysisExpressionSimilarityCalculator {32 public class SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator : SolutionSimilarityCalculator { 33 33 [Storable] 34 34 private readonly SymbolicExpressionTreeNodeEqualityComparer comparer; … … 42 42 set { comparer.MatchConstantValues = value; } 43 43 } 44 45 protected override bool IsCommutative { get { return true; } } 44 46 45 47 [StorableConstructor] -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeNodeComparer.cs
r11910 r12155 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeNodeEqualityComparer.cs
r11927 r12155 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreePhenotypicSimilarityCalculator.cs
r12017 r12155 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 28 29 29 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 30 [Item(" PhenotypicSimilarityCalculator", "An operator that calculates the similarity betweeon two trees based on the correlation of their outputs.")]31 [Item("SymbolicExpressionTreePhenotypicSimilarityCalculator", "An operator that calculates the similarity betweeon two trees based on the correlation of their outputs.")] 31 32 [StorableClass] 32 public class PhenotypicSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator, ISymbolicDataAnalysisExpressionSimilarityCalculator { 33 public class SymbolicExpressionTreePhenotypicSimilarityCalculator : SolutionSimilarityCalculator { 34 [Storable] 33 35 public IDataAnalysisProblemData ProblemData { get; set; } 36 [Storable] 34 37 public ISymbolicDataAnalysisExpressionTreeInterpreter Interpreter { get; set; } 35 38 39 protected override bool IsCommutative { get { return true; } } 40 36 41 [StorableConstructor] 37 protected PhenotypicSimilarityCalculator(bool deserializing) : base(deserializing) { }42 protected SymbolicExpressionTreePhenotypicSimilarityCalculator(bool deserializing) : base(deserializing) { } 38 43 39 public PhenotypicSimilarityCalculator(PhenotypicSimilarityCalculator original, Cloner cloner)44 public SymbolicExpressionTreePhenotypicSimilarityCalculator(SymbolicExpressionTreePhenotypicSimilarityCalculator original, Cloner cloner) 40 45 : base(original, cloner) { 41 this.ProblemData = original.ProblemData;42 this.Interpreter = original.Interpreter;46 this.ProblemData = cloner.Clone(original.ProblemData); 47 this.Interpreter = cloner.Clone(original.Interpreter); 43 48 } 44 49 45 50 public override IDeepCloneable Clone(Cloner cloner) { 46 return new PhenotypicSimilarityCalculator(this, cloner);51 return new SymbolicExpressionTreePhenotypicSimilarityCalculator(this, cloner); 47 52 } 48 53 49 public PhenotypicSimilarityCalculator() { }54 public SymbolicExpressionTreePhenotypicSimilarityCalculator() { } 50 55 51 56 public double CalculateSimilarity(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2) { 57 if (Interpreter == null || ProblemData == null) 58 throw new InvalidOperationException("Cannot calculate phenotypic similarity when no interpreter or problem data were set."); 59 52 60 var v1 = Interpreter.GetSymbolicExpressionTreeValues(t1, ProblemData.Dataset, ProblemData.TrainingIndices); 53 61 var v2 = Interpreter.GetSymbolicExpressionTreeValues(t2, ProblemData.Dataset, ProblemData.TrainingIndices); 62 63 if (v1.Variance().IsAlmost(0) && v2.Variance().IsAlmost(0)) 64 return 1.0; 54 65 55 66 OnlineCalculatorError error; … … 63 74 64 75 public override double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution) { 76 if (leftSolution == rightSolution) 77 return 1.0; 78 79 if (!leftSolution.Variables.ContainsKey("EstimatedValues") || !rightSolution.Variables.ContainsKey("EstimatedValues")) 80 throw new ArgumentException("No estimated values are present in the subscopes."); 81 65 82 var leftValues = (DoubleArray)leftSolution.Variables["EstimatedValues"].Value; 66 83 var rightValues = (DoubleArray)rightSolution.Variables["EstimatedValues"].Value; 84 85 if (leftValues.Variance().IsAlmost(0) && rightValues.Variance().IsAlmost(0)) 86 return 1.0; 87 67 88 OnlineCalculatorError error; 68 89 var r2 = OnlinePearsonsRSquaredCalculator.Calculate(leftValues, rightValues, out error);
Note: See TracChangeset
for help on using the changeset viewer.