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/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;
Note: See TracChangeset for help on using the changeset viewer.