Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/06/17 13:38:16 (7 years ago)
Author:
pfleck
Message:

#1666: Merged 15371-15372,15390,15400,15402 to stable

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSolutionImpactValuesCalculator.cs

    r15131 r15406  
    3232  public abstract class SymbolicDataAnalysisSolutionImpactValuesCalculator : Item, ISymbolicDataAnalysisSolutionImpactValuesCalculator {
    3333    protected SymbolicDataAnalysisSolutionImpactValuesCalculator() { }
    34 
    3534    protected SymbolicDataAnalysisSolutionImpactValuesCalculator(SymbolicDataAnalysisSolutionImpactValuesCalculator original, Cloner cloner)
    3635      : base(original, cloner) { }
    3736    [StorableConstructor]
    3837    protected SymbolicDataAnalysisSolutionImpactValuesCalculator(bool deserializing) : base(deserializing) { }
    39     public abstract void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation, double qualityForImpactsCalculation = double.NaN);
     38
     39    public virtual void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows,
     40        out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation,
     41        double qualityForImpactsCalculation = double.NaN) {
     42      if (double.IsNaN(qualityForImpactsCalculation))
     43        qualityForImpactsCalculation = CalculateQualityForImpacts(model, problemData, rows);
     44
     45      var cloner = new Cloner();
     46      var tempModel = cloner.Clone(model);
     47      var tempModelNode = (ISymbolicExpressionTreeNode)cloner.GetClone(node);
     48
     49      var tempModelParentNode = tempModelNode.Parent;
     50      int i = tempModelParentNode.IndexOfSubtree(tempModelNode);
     51
     52      double bestReplacementValue = 0.0;
     53      double bestImpactValue = double.PositiveInfinity;
     54      newQualityForImpactsCalculation = qualityForImpactsCalculation; // initialize
     55      // try the potentially reasonable replacement values and use the best one
     56      foreach (var repValue in CalculateReplacementValues(node, model.SymbolicExpressionTree, model.Interpreter, problemData.Dataset, problemData.TrainingIndices)) {
     57        tempModelParentNode.RemoveSubtree(i);
     58
     59        var constantNode = new ConstantTreeNode(new Constant()) { Value = repValue };
     60        tempModelParentNode.InsertSubtree(i, constantNode);
     61
     62        newQualityForImpactsCalculation = CalculateQualityForImpacts(tempModel, problemData, rows);
     63
     64        impactValue = qualityForImpactsCalculation - newQualityForImpactsCalculation;
     65        if (impactValue < bestImpactValue) {
     66          bestImpactValue = impactValue;
     67          bestReplacementValue = repValue;
     68        }
     69      }
     70
     71      replacementValue = bestReplacementValue;
     72      impactValue = bestImpactValue;
     73    }
     74
     75    protected abstract double CalculateQualityForImpacts(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData, IEnumerable<int> rows);
    4076
    4177    protected IEnumerable<double> CalculateReplacementValues(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
Note: See TracChangeset for help on using the changeset viewer.