Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/10/17 17:16:07 (7 years ago)
Author:
pfleck
Message:

#1666

  • Moved CalculateImpactAndReplacementValues into base-class.
  • Use SymRegImpactCalculator for SymTimeSeriesPrognosis.
  • Unified CalculateImpactAndReplacementValues for all SimplifierViews.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/SimplifierViewsProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolutionImpactValuesCalculator.cs

    r14826 r15321  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    2423using HeuristicLab.Common;
    2524using HeuristicLab.Core;
    26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2725using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2826
     
    3230  public class SymbolicRegressionSolutionImpactValuesCalculator : SymbolicDataAnalysisSolutionImpactValuesCalculator {
    3331    public SymbolicRegressionSolutionImpactValuesCalculator() { }
    34 
    3532    protected SymbolicRegressionSolutionImpactValuesCalculator(SymbolicRegressionSolutionImpactValuesCalculator original, Cloner cloner)
    3633      : base(original, cloner) { }
     
    3835      return new SymbolicRegressionSolutionImpactValuesCalculator(this, cloner);
    3936    }
    40 
    4137    [StorableConstructor]
    4238    protected SymbolicRegressionSolutionImpactValuesCalculator(bool deserializing) : base(deserializing) { }
    4339
    44     public override void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node,
    45       IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation,
    46       double qualityForImpactsCalculation = double.NaN) {
     40    protected override double CalculateQualityForImpacts(ISymbolicDataAnalysisModel model, IDataAnalysisProblemData problemData, IEnumerable<int> rows) {
    4741      var regressionModel = (ISymbolicRegressionModel)model;
    4842      var regressionProblemData = (IRegressionProblemData)problemData;
    49 
    50       var dataset = regressionProblemData.Dataset;
    51       var targetValues = dataset.GetDoubleValues(regressionProblemData.TargetVariable, rows);
    52 
    53       if (double.IsNaN(qualityForImpactsCalculation))
    54         qualityForImpactsCalculation = CalculateQualityForImpacts(regressionModel, regressionProblemData, rows);
    55 
    56       var cloner = new Cloner();
    57       var tempModel = cloner.Clone(regressionModel);
    58       var tempModelNode = (ISymbolicExpressionTreeNode)cloner.GetClone(node);
    59 
    60       var tempModelParentNode = tempModelNode.Parent;
    61       int i = tempModelParentNode.IndexOfSubtree(tempModelNode);
    62 
    63       double bestReplacementValue = 0.0;
    64       double bestImpactValue = double.PositiveInfinity;
    65       newQualityForImpactsCalculation = qualityForImpactsCalculation; // initialize
    66       // try the potentially reasonable replacement values and use the best one
    67       foreach (var repValue in CalculateReplacementValues(node, regressionModel.SymbolicExpressionTree, regressionModel.Interpreter, regressionProblemData.Dataset, regressionProblemData.TrainingIndices)) {
    68 
    69         tempModelParentNode.RemoveSubtree(i);
    70 
    71         var constantNode = new ConstantTreeNode(new Constant()) { Value = repValue };
    72 
    73         tempModelParentNode.InsertSubtree(i, constantNode);
    74 
    75         var estimatedValues = tempModel.GetEstimatedValues(dataset, rows);
    76         OnlineCalculatorError errorState;
    77         double r = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out errorState);
    78         if (errorState != OnlineCalculatorError.None) r = 0.0;
    79         newQualityForImpactsCalculation = r * r;
    80 
    81         impactValue = qualityForImpactsCalculation - newQualityForImpactsCalculation;
    82         if (impactValue < bestImpactValue) {
    83           bestImpactValue = impactValue;
    84           bestReplacementValue = repValue;
    85         }
    86       }
    87       replacementValue = bestReplacementValue;
    88       impactValue = bestImpactValue;
    89     }
    90 
    91     public static double CalculateQualityForImpacts(ISymbolicRegressionModel model, IRegressionProblemData problemData, IEnumerable<int> rows) {
    92       var estimatedValues = model.GetEstimatedValues(problemData.Dataset, rows); // also bounds the values
    93       var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     43      var estimatedValues = regressionModel.GetEstimatedValues(problemData.Dataset, rows); // also bounds the values
     44      var targetValues = problemData.Dataset.GetDoubleValues(regressionProblemData.TargetVariable, rows);
    9445      OnlineCalculatorError errorState;
    9546      var r = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out errorState);
Note: See TracChangeset for help on using the changeset viewer.