Ignore:
Timestamp:
07/10/15 15:41:09 (6 years ago)
Author:
bburlacu
Message:

#2359: Changed the impact calculators so that the quality value necessary for impacts calculation is calculated with a separate method. Refactored the CalculateImpactAndReplacementValues method to return the new quality in an out-parameter (adjusted method signature in interface accordingly). Added Evaluate method to the regression and classification pruning operators that re-evaluates the tree using the problem evaluator after pruning was performed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningOperator.cs

    r12641 r12720  
    2727using HeuristicLab.Core;
    2828using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     29using HeuristicLab.Parameters;
    2930using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3031
     
    3334  [Item("SymbolicRegressionPruningOperator", "An operator which prunes symbolic regression trees.")]
    3435  public class SymbolicRegressionPruningOperator : SymbolicDataAnalysisExpressionPruningOperator {
     36    private const string EvaluatorParameterName = "Evaluator";
     37
     38    #region parameter properties
     39    public ILookupParameter<ISymbolicRegressionSingleObjectiveEvaluator> EvaluatorParameter {
     40      get { return (ILookupParameter<ISymbolicRegressionSingleObjectiveEvaluator>)Parameters[EvaluatorParameterName]; }
     41    }
     42    #endregion
     43
    3544    protected SymbolicRegressionPruningOperator(SymbolicRegressionPruningOperator original, Cloner cloner)
    3645      : base(original, cloner) {
     
    4554    public SymbolicRegressionPruningOperator(ISymbolicDataAnalysisSolutionImpactValuesCalculator impactValuesCalculator)
    4655      : base(impactValuesCalculator) {
     56      Parameters.Add(new LookupParameter<ISymbolicRegressionSingleObjectiveEvaluator>(EvaluatorParameterName));
    4757    }
    4858
     
    5262
    5363    protected override double Evaluate(IDataAnalysisModel model) {
    54       var regressionModel = (IRegressionModel)model;
     64      var regressionModel = (ISymbolicRegressionModel)model;
    5565      var regressionProblemData = (IRegressionProblemData)ProblemDataParameter.ActualValue;
    56       var rows = Enumerable.Range(FitnessCalculationPartitionParameter.ActualValue.Start, FitnessCalculationPartitionParameter.ActualValue.Size);
    57       return Evaluate(regressionModel, regressionProblemData, rows);
    58     }
    59 
    60     private static double Evaluate(IRegressionModel model, IRegressionProblemData problemData,
    61       IEnumerable<int> rows) {
    62       var estimatedValues = model.GetEstimatedValues(problemData.Dataset, rows); // also bounds the values
    63       var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    64       OnlineCalculatorError errorState;
    65       var quality = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out errorState);
    66       if (errorState != OnlineCalculatorError.None) return double.NaN;
    67       return quality*quality;
     66      var evaluator = EvaluatorParameter.ActualValue;
     67      var fitnessEvaluationPartition = FitnessCalculationPartitionParameter.ActualValue;
     68      var rows = Enumerable.Range(fitnessEvaluationPartition.Start, fitnessEvaluationPartition.Size);
     69      return evaluator.Evaluate(this.ExecutionContext, regressionModel.SymbolicExpressionTree, regressionProblemData, rows);
    6870    }
    6971
     
    7274      var model = new SymbolicRegressionModel(clonedTree, interpreter, estimationLimits.Lower, estimationLimits.Upper);
    7375      var nodes = clonedTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList(); // skip the nodes corresponding to the ProgramRootSymbol and the StartSymbol
    74       double quality = Evaluate(model, problemData, rows);
     76
     77      double qualityForImpactsCalculation = double.NaN; // pass a NaN value initially so the impact calculator will calculate the quality
    7578
    7679      for (int i = 0; i < nodes.Count; ++i) {
     
    7982
    8083        double impactValue, replacementValue;
    81         impactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, quality);
     84        double newQualityForImpactsCalculation;
     85        impactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, out newQualityForImpactsCalculation, qualityForImpactsCalculation);
    8286
    8387        if (pruneOnlyZeroImpactNodes && !impactValue.IsAlmost(0.0)) continue;
     
    9094        i += node.GetLength() - 1; // skip subtrees under the node that was folded
    9195
    92         quality -= impactValue;
     96        qualityForImpactsCalculation = newQualityForImpactsCalculation;
    9397      }
    9498      return model.SymbolicExpressionTree;
Note: See TracChangeset for help on using the changeset viewer.