Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/07/15 12:11:09 (9 years ago)
Author:
bburlacu
Message:

#1772: Merged trunk changes.

Location:
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic

  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeBottomUpSimilarityCalculator.cs

    r12017 r12155  
    3434  [StorableClass]
    3535  [Item("SymbolicExpressionTreeBottomUpSimilarityCalculator", "A similarity calculator which uses the tree bottom-up distance as a similarity metric.")]
    36   public class SymbolicExpressionTreeBottomUpSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator, ISymbolicDataAnalysisExpressionSimilarityCalculator {
     36  public class SymbolicExpressionTreeBottomUpSimilarityCalculator : SolutionSimilarityCalculator {
    3737    private readonly HashSet<string> commutativeSymbols = new HashSet<string> { "Addition", "Multiplication", "Average", "And", "Or", "Xor" };
     38
    3839    public SymbolicExpressionTreeBottomUpSimilarityCalculator() { }
     40    protected override bool IsCommutative { get { return true; } }
    3941
    4042    [StorableConstructor]
     
    6062
    6163    public override double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution) {
     64      if (leftSolution == rightSolution)
     65        return 1.0;
     66
    6267      var t1 = leftSolution.Variables[SolutionVariableName].Value as ISymbolicExpressionTree;
    6368      var t2 = rightSolution.Variables[SolutionVariableName].Value as ISymbolicExpressionTree;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeMatching.cs

    r11927 r12155  
    22
    33/* HeuristicLab
    4  * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    55 *
    66 * This file is part of HeuristicLab.
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator.cs

    r11927 r12155  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    3030  [StorableClass]
    3131  [Item("SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator", "A similarity calculator based on the size of the maximum common subtree between two trees")]
    32   public class SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator, ISymbolicDataAnalysisExpressionSimilarityCalculator {
     32  public class SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator : SolutionSimilarityCalculator {
    3333    [Storable]
    3434    private readonly SymbolicExpressionTreeNodeEqualityComparer comparer;
     
    4242      set { comparer.MatchConstantValues = value; }
    4343    }
     44
     45    protected override bool IsCommutative { get { return true; } }
    4446
    4547    [StorableConstructor]
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeNodeComparer.cs

    r11910 r12155  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeNodeEqualityComparer.cs

    r11927 r12155  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreePhenotypicSimilarityCalculator.cs

    r12017 r12155  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    2829
    2930namespace 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.")]
    3132  [StorableClass]
    32   public class PhenotypicSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator, ISymbolicDataAnalysisExpressionSimilarityCalculator {
     33  public class SymbolicExpressionTreePhenotypicSimilarityCalculator : SolutionSimilarityCalculator {
     34    [Storable]
    3335    public IDataAnalysisProblemData ProblemData { get; set; }
     36    [Storable]
    3437    public ISymbolicDataAnalysisExpressionTreeInterpreter Interpreter { get; set; }
    3538
     39    protected override bool IsCommutative { get { return true; } }
     40
    3641    [StorableConstructor]
    37     protected PhenotypicSimilarityCalculator(bool deserializing) : base(deserializing) { }
     42    protected SymbolicExpressionTreePhenotypicSimilarityCalculator(bool deserializing) : base(deserializing) { }
    3843
    39     public PhenotypicSimilarityCalculator(PhenotypicSimilarityCalculator original, Cloner cloner)
     44    public SymbolicExpressionTreePhenotypicSimilarityCalculator(SymbolicExpressionTreePhenotypicSimilarityCalculator original, Cloner cloner)
    4045      : 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);
    4348    }
    4449
    4550    public override IDeepCloneable Clone(Cloner cloner) {
    46       return new PhenotypicSimilarityCalculator(this, cloner);
     51      return new SymbolicExpressionTreePhenotypicSimilarityCalculator(this, cloner);
    4752    }
    4853
    49     public PhenotypicSimilarityCalculator() { }
     54    public SymbolicExpressionTreePhenotypicSimilarityCalculator() { }
    5055
    5156    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
    5260      var v1 = Interpreter.GetSymbolicExpressionTreeValues(t1, ProblemData.Dataset, ProblemData.TrainingIndices);
    5361      var v2 = Interpreter.GetSymbolicExpressionTreeValues(t2, ProblemData.Dataset, ProblemData.TrainingIndices);
     62
     63      if (v1.Variance().IsAlmost(0) && v2.Variance().IsAlmost(0))
     64        return 1.0;
    5465
    5566      OnlineCalculatorError error;
     
    6374
    6475    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
    6582      var leftValues = (DoubleArray)leftSolution.Variables["EstimatedValues"].Value;
    6683      var rightValues = (DoubleArray)rightSolution.Variables["EstimatedValues"].Value;
     84
     85      if (leftValues.Variance().IsAlmost(0) && rightValues.Variance().IsAlmost(0))
     86        return 1.0;
     87
    6788      OnlineCalculatorError error;
    6889      var r2 = OnlinePearsonsRSquaredCalculator.Calculate(leftValues, rightValues, out error);
Note: See TracChangeset for help on using the changeset viewer.