Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/04/17 17:52:44 (8 years ago)
Author:
gkronber
Message:

#2650: merged the factors branch into trunk

Location:
trunk/sources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources

  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification

  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationSolutionImpactValuesCalculator.cs

    r14185 r14826  
    4040    protected SymbolicClassificationSolutionImpactValuesCalculator(bool deserializing) : base(deserializing) { }
    4141
    42     public override double CalculateReplacementValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows) {
    43       var classificationModel = (ISymbolicClassificationModel)model;
    44       var classificationProblemData = (IClassificationProblemData)problemData;
    45 
    46       return CalculateReplacementValue(node, classificationModel.SymbolicExpressionTree, classificationModel.Interpreter, classificationProblemData.Dataset, rows);
    47     }
    48 
    49     public override double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double qualityForImpactsCalculation = double.NaN) {
    50       double impactValue, replacementValue;
    51       double newQualityForImpactsCalculation;
    52       CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, out newQualityForImpactsCalculation, qualityForImpactsCalculation);
    53       return impactValue;
    54     }
    55 
    56     public override void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node,
    57       IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation,
     42    public override void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model,
     43      ISymbolicExpressionTreeNode node,
     44      IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue,
     45      out double newQualityForImpactsCalculation,
    5846      double qualityForImpactsCalculation = Double.NaN) {
    5947      var classificationModel = (ISymbolicClassificationModel)model;
     
    6351        qualityForImpactsCalculation = CalculateQualityForImpacts(classificationModel, classificationProblemData, rows);
    6452
    65       replacementValue = CalculateReplacementValue(classificationModel, node, classificationProblemData, rows);
    66       var constantNode = new ConstantTreeNode(new Constant()) { Value = replacementValue };
    6753
    6854      var cloner = new Cloner();
     
    7258      var tempModelParentNode = tempModelNode.Parent;
    7359      int i = tempModelParentNode.IndexOfSubtree(tempModelNode);
    74       tempModelParentNode.RemoveSubtree(i);
    75       tempModelParentNode.InsertSubtree(i, constantNode);
     60      double bestReplacementValue = 0.0;
     61      double bestImpactValue = double.PositiveInfinity;
     62      newQualityForImpactsCalculation = qualityForImpactsCalculation; // initialize
     63      // try the potentially reasonable replacement values and use the best one
     64      foreach (var repValue in CalculateReplacementValues(node, classificationModel.SymbolicExpressionTree, classificationModel.Interpreter, classificationProblemData.Dataset, classificationProblemData.TrainingIndices)) {
     65        tempModelParentNode.RemoveSubtree(i);
    7666
    77       OnlineCalculatorError errorState;
    78       var dataset = classificationProblemData.Dataset;
    79       var targetClassValues = dataset.GetDoubleValues(classificationProblemData.TargetVariable, rows);
    80       var estimatedClassValues = tempModel.GetEstimatedClassValues(dataset, rows);
    81       newQualityForImpactsCalculation = OnlineAccuracyCalculator.Calculate(targetClassValues, estimatedClassValues, out errorState);
    82       if (errorState != OnlineCalculatorError.None) newQualityForImpactsCalculation = 0.0;
     67        var constantNode = new ConstantTreeNode(new Constant()) { Value = repValue };
     68        tempModelParentNode.InsertSubtree(i, constantNode);
    8369
    84       impactValue = qualityForImpactsCalculation - newQualityForImpactsCalculation;
     70        var dataset = classificationProblemData.Dataset;
     71        var targetClassValues = dataset.GetDoubleValues(classificationProblemData.TargetVariable, rows);
     72        var estimatedClassValues = tempModel.GetEstimatedClassValues(dataset, rows);
     73        OnlineCalculatorError errorState;
     74        newQualityForImpactsCalculation = OnlineAccuracyCalculator.Calculate(targetClassValues, estimatedClassValues,
     75          out errorState);
     76        if (errorState != OnlineCalculatorError.None) newQualityForImpactsCalculation = 0.0;
     77
     78        impactValue = qualityForImpactsCalculation - newQualityForImpactsCalculation;
     79
     80        if (impactValue < bestImpactValue) {
     81          bestImpactValue = impactValue;
     82          bestReplacementValue = repValue;
     83        }
     84      }
     85      replacementValue = bestReplacementValue;
     86      impactValue = bestImpactValue;
    8587    }
    8688
Note: See TracChangeset for help on using the changeset viewer.