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.Regression
Files:
2 edited

Legend:

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

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

    r12049 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("SymbolicRegressionPhenotypicDiversityAnalyzer", "An analyzer which calculates diversity based on the phenotypic distance between trees")]
    3335  [StorableClass]
    34   public class SymbolicRegressionPhenotypicDiversityAnalyzer : SingleObjectivePopulationDiversityAnalyzer {
     36  public class SymbolicRegressionPhenotypicDiversityAnalyzer : PopulationSimilarityAnalyzer {
    3537    #region parameter names
    3638    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
     
    5961    #endregion
    6062
    61     public SymbolicRegressionPhenotypicDiversityAnalyzer() {
    62       SimilarityCalculator = new SymbolicExpressionTreePhenotypicSimilarityCalculator { SolutionVariableName = "SymbolicExpressionTree", QualityVariableName = "Quality" };
     63    public SymbolicRegressionPhenotypicDiversityAnalyzer(IEnumerable<ISingleObjectiveSolutionSimilarityCalculator> validSimilarityCalculators)
     64      : base(validSimilarityCalculators) {
    6365      #region add parameters
    6466      Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees."));
     
    6870      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."));
    6971      #endregion
     72
     73      UpdateCounterParameter.ActualName = "PhenotypicDiversityAnalyzerUpdateCounter";
    7074    }
    7175
     
    8488
    8589    public override IOperation Apply() {
    86       var trees = SymbolicExpressionTreeParameter.ActualValue;
    87       var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
    88       var ds = ProblemDataParameter.ActualValue.Dataset;
    89       var rows = ProblemDataParameter.ActualValue.TrainingIndices;
     90      int updateInterval = UpdateIntervalParameter.Value.Value;
     91      IntValue updateCounter = UpdateCounterParameter.ActualValue;
    9092
    91       var evaluatedValues = new ItemArray<DoubleArray>(trees.Select(t => new DoubleArray(interpreter.GetSymbolicExpressionTreeValues(t, ds, rows).ToArray())));
    92       EvaluatedValuesParameter.ActualValue = evaluatedValues;
     93      if (updateCounter == null) {
     94        updateCounter = new IntValue(updateInterval);
     95        UpdateCounterParameter.ActualValue = updateCounter;
     96      }
    9397
     98      if (updateCounter.Value == updateInterval) {
     99        var trees = SymbolicExpressionTreeParameter.ActualValue;
     100        var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue;
     101        var ds = ProblemDataParameter.ActualValue.Dataset;
     102        var rows = ProblemDataParameter.ActualValue.TrainingIndices;
     103
     104        var evaluatedValues = new ItemArray<DoubleArray>(trees.Select(t => new DoubleArray(interpreter.GetSymbolicExpressionTreeValues(t, ds, rows).ToArray())));
     105        EvaluatedValuesParameter.ActualValue = evaluatedValues;
     106      }
    94107      return base.Apply();
    95108    }
Note: See TracChangeset for help on using the changeset viewer.