Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/10/15 15:41:09 (9 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.

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPruningAnalyzer.cs

    r12358 r12720  
    4545
    4646    public SymbolicClassificationPruningAnalyzer() {
    47       Parameters.Add(new ValueParameter<SymbolicDataAnalysisExpressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicClassificationPruningOperator(new SymbolicClassificationSolutionImpactValuesCalculator())));
     47      Parameters.Add(new ValueParameter<SymbolicClassificationPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicClassificationPruningOperator(new SymbolicClassificationSolutionImpactValuesCalculator())));
    4848    }
    4949  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPruningOperator.cs

    r12461 r12720  
    3535  public class SymbolicClassificationPruningOperator : SymbolicDataAnalysisExpressionPruningOperator {
    3636    private const string ModelCreatorParameterName = "ModelCreator";
     37    private const string EvaluatorParameterName = "Evaluator";
    3738
    3839    #region parameter properties
    3940    public ILookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter {
    4041      get { return (ILookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; }
     42    }
     43
     44    public ILookupParameter<ISymbolicClassificationSingleObjectiveEvaluator> EvaluatorParameter {
     45      get {
     46        return (ILookupParameter<ISymbolicClassificationSingleObjectiveEvaluator>)Parameters[EvaluatorParameterName];
     47      }
    4148    }
    4249    #endregion
     
    5158      : base(impactValuesCalculator) {
    5259      Parameters.Add(new LookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName));
     60      Parameters.Add(new LookupParameter<ISymbolicClassificationSingleObjectiveEvaluator>(EvaluatorParameterName));
    5361    }
    5462
     
    6270
    6371    protected override double Evaluate(IDataAnalysisModel model) {
    64       var classificationModel = (IClassificationModel)model;
     72      var evaluator = EvaluatorParameter.ActualValue;
     73      var classificationModel = (ISymbolicClassificationModel)model;
    6574      var classificationProblemData = (IClassificationProblemData)ProblemDataParameter.ActualValue;
    6675      var rows = Enumerable.Range(FitnessCalculationPartitionParameter.ActualValue.Start, FitnessCalculationPartitionParameter.ActualValue.Size);
    67 
    68       return Evaluate(classificationModel, classificationProblemData, rows);
    69     }
    70 
    71     private static double Evaluate(IClassificationModel model, IClassificationProblemData problemData, IEnumerable<int> rows) {
    72       var estimatedValues = model.GetEstimatedClassValues(problemData.Dataset, rows);
    73       var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
    74       OnlineCalculatorError errorState;
    75       var quality = OnlineAccuracyCalculator.Calculate(targetValues, estimatedValues, out errorState);
    76       if (errorState != OnlineCalculatorError.None) return double.NaN;
    77       return quality;
     76      return evaluator.Evaluate(this.ExecutionContext, classificationModel.SymbolicExpressionTree, classificationProblemData, rows);
    7877    }
    7978
     
    8685
    8786      var nodes = clonedTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList();
    88       double quality = Evaluate(model, problemData, rows);
     87      double qualityForImpactsCalculation = double.NaN;
    8988
    9089      for (int i = 0; i < nodes.Count; ++i) {
     
    9291        if (node is ConstantTreeNode) continue;
    9392
    94         double impactValue, replacementValue;
    95         impactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, quality);
     93        double impactValue, replacementValue, newQualityForImpactsCalculation;
     94        impactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, out newQualityForImpactsCalculation, qualityForImpactsCalculation);
    9695
    9796        if (pruneOnlyZeroImpactNodes && !impactValue.IsAlmost(0.0)) continue;
     
    104103        i += node.GetLength() - 1; // skip subtrees under the node that was folded
    105104
    106         quality -= impactValue;
     105        qualityForImpactsCalculation = newQualityForImpactsCalculation;
    107106      }
    108107      return model.SymbolicExpressionTree;
  • 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.