Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12049


Ignore:
Timestamp:
02/21/15 15:55:47 (10 years ago)
Author:
bburlacu
Message:

#2326: Addressed the issues found by the reviewer.

Location:
branches/SymbolicExpressionTreeDiversityAnalyzers
Files:
8 edited

Legend:

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

    r12030 r12049  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    2322using System.Linq;
    2423using HeuristicLab.Analysis;
     
    3029using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3130
    32 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Analyzers {
     31namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
    3332  [Item("SymbolicClassificationPhenotypicDiversityAnalyzer", "An analyzer which calculates diversity based on the phenotypic distance between trees")]
    3433  [StorableClass]
     
    3938    private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
    4039    private const string ProblemDataParameterName = "ProblemData";
     40    private const string ModelCreatorParameterName = "ModelCreator";
    4141    private const string EstimationLimitsParameterName = "EstimationLimits";
    4242    private const string UseClassValuesParameterName = "UseClassValues";
     
    5353      get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; }
    5454    }
     55    public ILookupParameter<ISymbolicDiscriminantFunctionClassificationModelCreator> ModelCreatorParameter {
     56      get { return (ILookupParameter<ISymbolicDiscriminantFunctionClassificationModelCreator>)Parameters[ModelCreatorParameterName]; }
     57    }
    5558    public IValueLookupParameter<IClassificationProblemData> ProblemDataParameter {
    5659      get { return (IValueLookupParameter<IClassificationProblemData>)Parameters[ProblemDataParameterName]; }
     
    6568
    6669    #region properties
    67     bool UseClassValues {
     70    private bool UseClassValues {
    6871      get { return UseClassValuesParameter.Value.Value; }
    6972      set { UseClassValuesParameter.Value.Value = value; }
     
    7881      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic data analysis tree."));
    7982      Parameters.Add(new ValueLookupParameter<IClassificationProblemData>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated."));
     83      Parameters.Add(new LookupParameter<ISymbolicDiscriminantFunctionClassificationModelCreator>(ModelCreatorParameterName, "The model creator for creating discriminant function classification models."));
    8084      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The upper and lower limit that should be used as cut off value for the output values of symbolic data analysis trees."));
    81       Parameters.Add(new FixedValueParameter<BoolValue>(UseClassValuesParameterName,
    82         "Specifies whether the raw estimated values of the tree or the corresponding class values should be used for similarity calculation.", new BoolValue(false)));
     85      Parameters.Add(new FixedValueParameter<BoolValue>(UseClassValuesParameterName, "Specifies whether the raw estimated values of the tree or the corresponding class values should be used for similarity calculation.", new BoolValue(false)));
    8386      #endregion
    8487    }
     
    100103      var trees = SymbolicExpressionTreeParameter.ActualValue;
    101104      var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     105      var problemData = ProblemDataParameter.ActualValue;
    102106      var ds = ProblemDataParameter.ActualValue.Dataset;
    103107      var rows = ProblemDataParameter.ActualValue.TrainingIndices;
    104 
    105       if (UseClassValues) {
    106         var problemData = ProblemDataParameter.ActualValue;
    107         var evaluatedValues = new ItemArray<DoubleArray>(trees.Length);
    108         for (int i = 0; i < trees.Length; ++i) {
    109           var t = trees[i];
    110           double[] classValues, thresholds;
    111           var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(t, ds, rows).ToArray();
    112           AccuracyMaximizationThresholdCalculator.CalculateThresholds(problemData, estimatedValues,
    113             problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices),
    114             out classValues, out thresholds);
    115           var estimatedClassValues = new List<double>();
    116           foreach (var x in estimatedValues) {
    117             int classIndex = 0;
    118             // find first threshold value which is larger than x => class index = threshold index + 1
    119             for (int j = 0; j < thresholds.Length; j++) {
    120               if (x > thresholds[j]) classIndex++;
    121               else break;
    122             }
    123             estimatedClassValues.Add(classValues.ElementAt(classIndex - 1));
    124           }
    125           evaluatedValues[i] = new DoubleArray(estimatedClassValues.ToArray());
    126         }
    127         EvaluatedValuesParameter.ActualValue = evaluatedValues;
    128       } else {
    129         var evaluatedValues = new ItemArray<DoubleArray>(trees.Select(t => new DoubleArray(interpreter.GetSymbolicExpressionTreeValues(t, ds, rows).ToArray())));
    130         EvaluatedValuesParameter.ActualValue = evaluatedValues;
     108      var modelCreator = ModelCreatorParameter.ActualValue;
     109      var estimationLimits = EstimationLimitsParameter.ActualValue;
     110      var evaluatedValues = new ItemArray<DoubleArray>(trees.Length);
     111      for (int i = 0; i < trees.Length; ++i) {
     112        var model = (IDiscriminantFunctionClassificationModel)modelCreator.CreateSymbolicDiscriminantFunctionClassificationModel(trees[i], interpreter, estimationLimits.Lower, estimationLimits.Upper);
     113        model.RecalculateModelParameters(problemData, rows);
     114        var values = UseClassValues ? model.GetEstimatedClassValues(ds, rows) : model.GetEstimatedValues(ds, rows);
     115        evaluatedValues[i] = new DoubleArray(values.ToArray());
    131116      }
     117      EvaluatedValuesParameter.ActualValue = evaluatedValues;
    132118      return base.Apply();
    133119    }
  • branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveProblem.cs

    r12030 r12049  
    2424using HeuristicLab.Parameters;
    2525using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using HeuristicLab.Problems.DataAnalysis.Symbolic.Analyzers;
    2726
    2827namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
     
    147146          op.ModelCreatorParameter.ActualName = ModelCreatorParameter.Name;
    148147      }
     148
     149      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        }
     158      }
    149159    }
    150160  }
  • branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionPhenotypicDiversityAnalyzer.cs

    r12030 r12049  
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3030
    31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Analyzers {
     31namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    3232  [Item("SymbolicRegressionPhenotypicDiversityAnalyzer", "An analyzer which calculates diversity based on the phenotypic distance between trees")]
    3333  [StorableClass]
  • branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs

    r12030 r12049  
    2525using HeuristicLab.Parameters;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    27 using HeuristicLab.Problems.DataAnalysis.Symbolic.Analyzers;
    2827
    2928namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
     
    113112      Operators.Add(new SymbolicRegressionSolutionsAnalyzer());
    114113      Operators.Add(new SymbolicRegressionPhenotypicDiversityAnalyzer());
    115 
    116114      ParameterizeOperators();
    117115    }
     
    143141        }
    144142      }
     143      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      }
    145153    }
    146154  }
  • branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs

    r12030 r12049  
    119119      set { ProblemDataParameter.Value = value; }
    120120    }
    121 
    122121    public ISymbolicDataAnalysisGrammar SymbolicExpressionTreeGrammar {
    123122      get { return SymbolicExpressionTreeGrammarParameter.Value; }
     
    128127      set { SymbolicExpressionTreeInterpreterParameter.Value = value; }
    129128    }
    130 
    131129    public IntValue MaximumSymbolicExpressionTreeDepth {
    132130      get { return MaximumSymbolicExpressionTreeDepthParameter.Value; }
     
    144142      get { return RelativeNumberOfEvaluatedSamplesParameter.Value; }
    145143    }
    146 
    147144    public IntRange FitnessCalculationPartition {
    148145      get { return FitnessCalculationPartitionParameter.Value; }
     
    352349        op.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
    353350      }
     351      foreach (var op in operators.OfType<SymbolicDataAnalysisBottomUpDiversityAnalyzer>()) {
     352        var sim = op.SimilarityCalculator as SymbolicExpressionTreeBottomUpSimilarityCalculator;
     353        if (sim == null) {
     354          op.SimilarityCalculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator {
     355            SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName
     356          };
     357        } else {
     358          sim.SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
     359        }
     360      }
    354361    }
    355362
  • branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeBottomUpSimilarityCalculator.cs

    r12028 r12049  
    6060
    6161    public override double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution) {
     62      if (leftSolution == rightSolution)
     63        return 1.0;
     64
    6265      var t1 = leftSolution.Variables[SolutionVariableName].Value as ISymbolicExpressionTree;
    6366      var t2 = rightSolution.Variables[SolutionVariableName].Value as ISymbolicExpressionTree;
  • branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreePhenotypicSimilarityCalculator.cs

    r12029 r12049  
    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.
     
    6363
    6464    public override double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution) {
     65      if (leftSolution == rightSolution)
     66        return 1.0;
     67
    6568      var leftValues = (DoubleArray)leftSolution.Variables["EstimatedValues"].Value;
    6669      var rightValues = (DoubleArray)rightSolution.Variables["EstimatedValues"].Value;
Note: See TracChangeset for help on using the changeset viewer.