Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12068


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.

Location:
branches/SymbolicExpressionTreeDiversityAnalyzers
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveProblem.cs

    r12049 r12068  
    116116      Operators.Add(new SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer());
    117117      Operators.Add(new SymbolicClassificationPhenotypicDiversityAnalyzer());
     118      Operators.Add(new SymbolicExpressionTreePhenotypicSimilarityCalculator());
    118119      ParameterizeOperators();
    119120    }
     
    147148      }
    148149
     150      foreach (var op in Operators.OfType<SymbolicExpressionTreePhenotypicSimilarityCalculator>()) {
     151        op.SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     152        op.ProblemData = ProblemData;
     153        op.Interpreter = SymbolicExpressionTreeInterpreter;
     154      }
     155
    149156      foreach (var op in Operators.OfType<SymbolicClassificationPhenotypicDiversityAnalyzer>()) {
    150         var sim = op.SimilarityCalculator as SymbolicExpressionTreePhenotypicSimilarityCalculator;
    151         if (sim == null) {
    152           op.SimilarityCalculator = new SymbolicExpressionTreePhenotypicSimilarityCalculator {
    153             SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName
    154           };
    155         } else {
    156           sim.SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    157         }
     157        var sim = Operators.OfType<SymbolicExpressionTreePhenotypicSimilarityCalculator>().FirstOrDefault();
     158        if (sim != null)
     159          op.SimilarityCalculator = sim;
    158160      }
    159161    }
  • branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs

    r12049 r12068  
    112112      Operators.Add(new SymbolicRegressionSolutionsAnalyzer());
    113113      Operators.Add(new SymbolicRegressionPhenotypicDiversityAnalyzer());
     114      Operators.Add(new SymbolicExpressionTreePhenotypicSimilarityCalculator());
    114115      ParameterizeOperators();
    115116    }
     
    141142        }
    142143      }
     144
     145      foreach (var op in Operators.OfType<SymbolicExpressionTreePhenotypicSimilarityCalculator>()) {
     146        op.SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     147        op.ProblemData = ProblemData;
     148        op.Interpreter = SymbolicExpressionTreeInterpreter;
     149      }
     150
    143151      foreach (var op in Operators.OfType<SymbolicRegressionPhenotypicDiversityAnalyzer>()) {
    144         var sim = op.SimilarityCalculator as SymbolicExpressionTreePhenotypicSimilarityCalculator;
    145         if (sim == null) {
    146           op.SimilarityCalculator = new SymbolicExpressionTreePhenotypicSimilarityCalculator {
    147             SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName
    148           };
    149         } else {
    150           sim.SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    151         }
     152        var sim = Operators.OfType<SymbolicExpressionTreePhenotypicSimilarityCalculator>().FirstOrDefault();
     153        if (sim != null)
     154          op.SimilarityCalculator = sim;
    152155      }
    153156    }
  • branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs

    r12064 r12068  
    229229      Operators.Add(new SymbolicExpressionTreeLengthAnalyzer());
    230230      Operators.Add(new SymbolicDataAnalysisBottomUpDiversityAnalyzer());
     231      Operators.Add(new SymbolicExpressionTreeBottomUpSimilarityCalculator());
    231232      ParameterizeOperators();
    232233    }
     
    348349        op.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
    349350      }
     351      foreach (var op in operators.OfType<SymbolicExpressionTreeBottomUpSimilarityCalculator>()) {
     352        op.SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     353      }
    350354      foreach (var op in operators.OfType<SymbolicDataAnalysisBottomUpDiversityAnalyzer>()) {
    351         var sim = op.SimilarityCalculator as SymbolicExpressionTreeBottomUpSimilarityCalculator;
    352         if (sim == null) {
    353           op.SimilarityCalculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator {
    354             SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName
    355           };
    356         } else {
    357           sim.SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    358         }
     355        var sim = Operators.OfType<SymbolicExpressionTreeBottomUpSimilarityCalculator>().FirstOrDefault();
     356        if (sim != null)
     357          op.SimilarityCalculator = sim;
    359358      }
    360359    }
  • 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.