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

    r12012 r12720  
    4747    }
    4848
    49     public override double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double originalQuality = double.NaN) {
     49    public override double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double qualityForImpactsCalculation = double.NaN) {
    5050      double impactValue, replacementValue;
    51       CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, originalQuality);
     51      double newQualityForImpactsCalculation;
     52      CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, out newQualityForImpactsCalculation, qualityForImpactsCalculation);
    5253      return impactValue;
    5354    }
    5455
    5556    public override void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node,
    56       IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue,
    57       double originalQuality = Double.NaN) {
     57      IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation,
     58      double qualityForImpactsCalculation = Double.NaN) {
    5859      var classificationModel = (ISymbolicClassificationModel)model;
    5960      var classificationProblemData = (IClassificationProblemData)problemData;
    6061
    61       var dataset = classificationProblemData.Dataset;
    62       var targetClassValues = dataset.GetDoubleValues(classificationProblemData.TargetVariable, rows);
    63 
    64       OnlineCalculatorError errorState;
    65       if (double.IsNaN(originalQuality)) {
    66         var originalClassValues = classificationModel.GetEstimatedClassValues(dataset, rows);
    67         originalQuality = OnlineAccuracyCalculator.Calculate(targetClassValues, originalClassValues, out errorState);
    68         if (errorState != OnlineCalculatorError.None) originalQuality = 0.0;
    69       }
     62      if (double.IsNaN(qualityForImpactsCalculation))
     63        qualityForImpactsCalculation = CalculateQualityForImpacts(classificationModel, classificationProblemData, rows);
    7064
    7165      replacementValue = CalculateReplacementValue(classificationModel, node, classificationProblemData, rows);
     
    8175      tempModelParentNode.InsertSubtree(i, constantNode);
    8276
     77      OnlineCalculatorError errorState;
     78      var dataset = classificationProblemData.Dataset;
     79      var targetClassValues = dataset.GetDoubleValues(classificationProblemData.TargetVariable, rows);
    8380      var estimatedClassValues = tempModel.GetEstimatedClassValues(dataset, rows);
    84       double newQuality = OnlineAccuracyCalculator.Calculate(targetClassValues, estimatedClassValues, out errorState);
    85       if (errorState != OnlineCalculatorError.None) newQuality = 0.0;
     81      newQualityForImpactsCalculation = OnlineAccuracyCalculator.Calculate(targetClassValues, estimatedClassValues, out errorState);
     82      if (errorState != OnlineCalculatorError.None) newQualityForImpactsCalculation = 0.0;
    8683
    87       impactValue = originalQuality - newQuality;
     84      impactValue = qualityForImpactsCalculation - newQualityForImpactsCalculation;
     85    }
     86
     87    public static double CalculateQualityForImpacts(ISymbolicClassificationModel model, IClassificationProblemData problemData, IEnumerable<int> rows) {
     88      OnlineCalculatorError errorState;
     89      var dataset = problemData.Dataset;
     90      var targetClassValues = dataset.GetDoubleValues(problemData.TargetVariable, rows);
     91      var originalClassValues = model.GetEstimatedClassValues(dataset, rows);
     92      var qualityForImpactsCalculation = OnlineAccuracyCalculator.Calculate(targetClassValues, originalClassValues, out errorState);
     93      if (errorState != OnlineCalculatorError.None) qualityForImpactsCalculation = 0.0;
     94
     95      return qualityForImpactsCalculation;
    8896    }
    8997  }
Note: See TracChangeset for help on using the changeset viewer.