Changeset 12155 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreePhenotypicSimilarityCalculator.cs
- Timestamp:
- 03/07/15 12:11:09 (10 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic
- Files:
-
- 2 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/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.