Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/24/15 17:07:41 (10 years ago)
Author:
bburlacu
Message:

#2326: Fixed mistakes and wired similarity calculators directly into the problem and correctly initialized the properties of the phenotypic similarity calculator.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreePhenotypicSimilarityCalculator.cs

    r12064 r12068  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    5354
    5455    public double CalculateSimilarity(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2) {
     56      if (Interpreter == null || ProblemData == null)
     57        throw new InvalidOperationException("Cannot calculate phenotypic similarity when no interpreter or problem data were set.");
     58
    5559      var v1 = Interpreter.GetSymbolicExpressionTreeValues(t1, ProblemData.Dataset, ProblemData.TrainingIndices);
    5660      var v2 = Interpreter.GetSymbolicExpressionTreeValues(t2, ProblemData.Dataset, ProblemData.TrainingIndices);
     61
     62      if (v1.Variance().IsAlmost(0) && v2.Variance().IsAlmost(0))
     63        return 1.0;
    5764
    5865      OnlineCalculatorError error;
     
    6875      if (leftSolution == rightSolution)
    6976        return 1.0;
     77
     78      if (!leftSolution.Variables.ContainsKey("EstimatedValues") || !rightSolution.Variables.ContainsKey("EstimatedValues"))
     79        throw new ArgumentException("No estimated values are present in the subscopes.");
    7080
    7181      var leftValues = (DoubleArray)leftSolution.Variables["EstimatedValues"].Value;
Note: See TracChangeset for help on using the changeset viewer.