Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/25/15 17:53:25 (10 years ago)
Author:
bburlacu
Message:

#2326: Adapted code in the diversity analyzers according to the new base class. Improved wiring of similarity calculators and analyzers.

Location:
branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationPhenotypicDiversityAnalyzer.cs

    r12064 r12075  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using System.Linq;
    2324using HeuristicLab.Analysis;
     
    2627using HeuristicLab.Data;
    2728using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     29using HeuristicLab.Optimization;
    2830using HeuristicLab.Parameters;
    2931using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3234  [Item("SymbolicClassificationPhenotypicDiversityAnalyzer", "An analyzer which calculates diversity based on the phenotypic distance between trees")]
    3335  [StorableClass]
    34   public class SymbolicClassificationPhenotypicDiversityAnalyzer : SingleObjectivePopulationDiversityAnalyzer {
     36  public class SymbolicClassificationPhenotypicDiversityAnalyzer : PopulationSimilarityAnalyzer {
    3537    #region parameter names
    3638    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
     
    7476    #endregion
    7577
    76     public SymbolicClassificationPhenotypicDiversityAnalyzer() {
    77       SimilarityCalculator = new SymbolicExpressionTreePhenotypicSimilarityCalculator() { SolutionVariableName = "SymbolicExpressionTree", QualityVariableName = "Quality" };
     78    public SymbolicClassificationPhenotypicDiversityAnalyzer(IEnumerable<ISingleObjectiveSolutionSimilarityCalculator> validSimilarityCalculators)
     79      : base(validSimilarityCalculators) {
    7880      #region add parameters
    7981      Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees."));
     
    8587      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)));
    8688      #endregion
     89
     90      UpdateCounterParameter.ActualName = "PhenotypicDiversityAnalyzerUpdateCounter";
    8791    }
    8892
     
    101105
    102106    public override IOperation Apply() {
    103       var trees = SymbolicExpressionTreeParameter.ActualValue;
    104       var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
    105       var problemData = ProblemDataParameter.ActualValue;
    106       var ds = ProblemDataParameter.ActualValue.Dataset;
    107       var rows = ProblemDataParameter.ActualValue.TrainingIndices;
    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());
     107      int updateInterval = UpdateIntervalParameter.Value.Value;
     108      IntValue updateCounter = UpdateCounterParameter.ActualValue;
     109
     110      if (updateCounter == null) {
     111        updateCounter = new IntValue(updateInterval);
     112        UpdateCounterParameter.ActualValue = updateCounter;
    116113      }
    117       EvaluatedValuesParameter.ActualValue = evaluatedValues;
     114
     115      if (updateCounter.Value == updateInterval) {
     116        var trees = SymbolicExpressionTreeParameter.ActualValue;
     117        var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     118        var problemData = ProblemDataParameter.ActualValue;
     119        var ds = ProblemDataParameter.ActualValue.Dataset;
     120        var rows = ProblemDataParameter.ActualValue.TrainingIndices;
     121        var modelCreator = ModelCreatorParameter.ActualValue;
     122        var estimationLimits = EstimationLimitsParameter.ActualValue;
     123        var evaluatedValues = new ItemArray<DoubleArray>(trees.Length);
     124        for (int i = 0; i < trees.Length; ++i) {
     125          var model =
     126            (IDiscriminantFunctionClassificationModel)
     127              modelCreator.CreateSymbolicDiscriminantFunctionClassificationModel(trees[i], interpreter,
     128                estimationLimits.Lower, estimationLimits.Upper);
     129          model.RecalculateModelParameters(problemData, rows);
     130          var values = UseClassValues ? model.GetEstimatedClassValues(ds, rows) : model.GetEstimatedValues(ds, rows);
     131          evaluatedValues[i] = new DoubleArray(values.ToArray());
     132        }
     133        EvaluatedValuesParameter.ActualValue = evaluatedValues;
     134      }
    118135      return base.Apply();
    119136    }
  • branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveProblem.cs

    r12068 r12075  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
     24using HeuristicLab.Optimization;
    2425using HeuristicLab.Parameters;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    115116      Operators.Add(new SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer());
    116117      Operators.Add(new SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer());
    117       Operators.Add(new SymbolicClassificationPhenotypicDiversityAnalyzer());
    118118      Operators.Add(new SymbolicExpressionTreePhenotypicSimilarityCalculator());
     119      Operators.Add(new SymbolicClassificationPhenotypicDiversityAnalyzer(Operators.OfType<SymbolicExpressionTreePhenotypicSimilarityCalculator>()) { DiversityResultName = "Phenotypic Similarity" });
    119120      ParameterizeOperators();
    120121    }
     
    148149      }
    149150
    150       foreach (var op in Operators.OfType<SymbolicExpressionTreePhenotypicSimilarityCalculator>()) {
     151      foreach (var op in Operators.OfType<ISingleObjectiveSolutionSimilarityCalculator>()) {
    151152        op.SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;
    152         op.ProblemData = ProblemData;
    153         op.Interpreter = SymbolicExpressionTreeInterpreter;
    154       }
     153        op.QualityVariableName = Evaluator.QualityParameter.ActualName;
    155154
    156       foreach (var op in Operators.OfType<SymbolicClassificationPhenotypicDiversityAnalyzer>()) {
    157         var sim = Operators.OfType<SymbolicExpressionTreePhenotypicSimilarityCalculator>().FirstOrDefault();
    158         if (sim != null)
    159           op.SimilarityCalculator = sim;
     155        if (op is SymbolicExpressionTreePhenotypicSimilarityCalculator) {
     156          var phenotypicSimilarityCalculator = (SymbolicExpressionTreePhenotypicSimilarityCalculator)op;
     157          phenotypicSimilarityCalculator.ProblemData = ProblemData;
     158          phenotypicSimilarityCalculator.Interpreter = SymbolicExpressionTreeInterpreter;
     159        }
    160160      }
    161161    }
Note: See TracChangeset for help on using the changeset viewer.