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/3.4/SymbolicDataAnalysisExpressionPruningOperator.cs

    r12361 r12720  
    4949    private const string EstimationLimitsParameterName = "EstimationLimits";
    5050    private const string InterpreterParameterName = "SymbolicExpressionTreeInterpreter";
     51    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
    5152    #endregion
    5253
     
    8889      get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[InterpreterParameterName]; }
    8990    }
     91    public ILookupParameter<BoolValue> ApplyLinearScalingParameter {
     92      get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParameterName]; }
     93    }
    9094    #endregion
    9195
     
    124128      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName));
    125129      Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName));
     130      Parameters.Add(new LookupParameter<BoolValue>(ApplyLinearScalingParameterName));
    126131      Parameters.Add(new ValueParameter<ISymbolicDataAnalysisSolutionImpactValuesCalculator>(ImpactValuesCalculatorParameterName, impactValuesCalculator));
    127132      #endregion
     
    141146      var model = CreateModel(tree, interpreter, problemData, estimationLimits);
    142147      var nodes = tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList();
    143       var rows = Enumerable.Range(fitnessCalculationPartition.Start, fitnessCalculationPartition.Size);
     148      var rows = Enumerable.Range(fitnessCalculationPartition.Start, fitnessCalculationPartition.Size).ToList();
    144149      var prunedSubtrees = 0;
    145150      var prunedTrees = 0;
    146151      var prunedNodes = 0;
    147152
    148       double quality = Evaluate(model);
     153      double qualityForImpactsCalculation = double.NaN;
    149154
    150155      for (int i = 0; i < nodes.Count; ++i) {
     
    153158
    154159        double impactValue, replacementValue;
    155         ImpactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, quality);
     160        double newQualityForImpacts;
     161        ImpactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, out newQualityForImpacts, qualityForImpactsCalculation);
    156162
    157163        if (PruneOnlyZeroImpactNodes && !impactValue.IsAlmost(0.0)) continue;
     
    165171        i += length - 1; // skip subtrees under the node that was folded
    166172
    167         quality -= impactValue;
    168173        prunedSubtrees++;
    169174        prunedNodes += length;
     175
     176        qualityForImpactsCalculation = newQualityForImpacts;
    170177      }
    171178
     
    174181      PrunedTreesParameter.ActualValue = new IntValue(prunedTrees);
    175182      PrunedNodesParameter.ActualValue = new IntValue(prunedNodes);
    176       QualityParameter.ActualValue.Value = quality;
     183
     184      if (prunedSubtrees > 0) // if nothing was pruned then there's no need to re-evaluate the tree
     185        QualityParameter.ActualValue.Value = Evaluate(model);
    177186
    178187      return base.Apply();
Note: See TracChangeset for help on using the changeset viewer.