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/SymbolicRegressionSolutionImpactValuesCalculator.cs

    r12641 r12720  
    4848    }
    4949
    50     public override double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double originalQuality = double.NaN) {
    51       double impactValue, replacementValue;
    52       CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, originalQuality);
     50    public override double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double qualityForImpactsCalculation = double.NaN) {
     51      double impactValue, replacementValue, newQualityForImpactsCalculation;
     52      CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, out newQualityForImpactsCalculation, qualityForImpactsCalculation);
    5353      return impactValue;
    5454    }
    5555
    5656    public override void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node,
    57       IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue,
    58       double originalQuality = Double.NaN) {
     57      IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation,
     58      double qualityForImpactsCalculation = Double.NaN) {
    5959      var regressionModel = (ISymbolicRegressionModel)model;
    6060      var regressionProblemData = (IRegressionProblemData)problemData;
     
    6464
    6565      OnlineCalculatorError errorState;
    66       if (double.IsNaN(originalQuality)) {
    67         var originalValues = regressionModel.GetEstimatedValues(dataset, rows);
    68         originalQuality = OnlinePearsonsRCalculator.Calculate(targetValues, originalValues, out errorState);
    69         if (errorState != OnlineCalculatorError.None) originalQuality = 0.0;
    70       }
     66      if (double.IsNaN(qualityForImpactsCalculation))
     67        qualityForImpactsCalculation = CalculateQualityForImpacts(regressionModel, regressionProblemData, rows);
    7168
    7269      replacementValue = CalculateReplacementValue(regressionModel, node, regressionProblemData, rows);
     
    8380
    8481      var estimatedValues = tempModel.GetEstimatedValues(dataset, rows);
    85       double newQuality = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out errorState);
    86       if (errorState != OnlineCalculatorError.None) newQuality = 0.0;
     82      double r = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out errorState);
     83      if (errorState != OnlineCalculatorError.None) r = 0.0;
     84      newQualityForImpactsCalculation = r * r;
    8785
    88       impactValue = (originalQuality*originalQuality) - (newQuality*newQuality);
     86      impactValue = qualityForImpactsCalculation - newQualityForImpactsCalculation;
     87    }
     88
     89    public static double CalculateQualityForImpacts(ISymbolicRegressionModel model, IRegressionProblemData problemData, IEnumerable<int> rows) {
     90      var estimatedValues = model.GetEstimatedValues(problemData.Dataset, rows); // also bounds the values
     91      var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     92      OnlineCalculatorError errorState;
     93      var r = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out errorState);
     94      var quality = r * r;
     95      if (errorState != OnlineCalculatorError.None) return double.NaN;
     96      return quality;
    8997    }
    9098  }
Note: See TracChangeset for help on using the changeset viewer.