Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12669


Ignore:
Timestamp:
07/08/15 09:52:09 (9 years ago)
Author:
gkronber
Message:

#2392: merged r12492 and r12641 from trunk to stable

Location:
stable
Files:
20 edited
1 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.DataAnalysis

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs

    r12009 r12669  
    5757      OnlineCalculatorError errorState;
    5858
    59       double r2;
     59      double r;
    6060      if (applyLinearScaling) {
    61         var r2Calculator = new OnlinePearsonsRSquaredCalculator();
    62         CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, r2Calculator, problemData.Dataset.Rows);
    63         errorState = r2Calculator.ErrorState;
    64         r2 = r2Calculator.RSquared;
     61        var rCalculator = new OnlinePearsonsRCalculator();
     62        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, rCalculator, problemData.Dataset.Rows);
     63        errorState = rCalculator.ErrorState;
     64        r = rCalculator.R;
    6565      } else {
    6666        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    67         r2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
     67        r = OnlinePearsonsRCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    6868      }
    6969
    70       if (errorState != OnlineCalculatorError.None) r2 = double.NaN;
    71       return new double[2] { r2, solution.Length };
     70      if (errorState != OnlineCalculatorError.None) r = double.NaN;
     71      return new double[2] { r*r, solution.Length };
    7272
    7373    }
  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectivePearsonRSquaredEvaluator.cs

    r12009 r12669  
    5757      OnlineCalculatorError errorState;
    5858
    59       double r2;
     59      double r;
    6060      if (applyLinearScaling) {
    61         var r2Calculator = new OnlinePearsonsRSquaredCalculator();
    62         CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, r2Calculator, problemData.Dataset.Rows);
    63         errorState = r2Calculator.ErrorState;
    64         r2 = r2Calculator.RSquared;
     61        var rCalculator = new OnlinePearsonsRCalculator();
     62        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, rCalculator, problemData.Dataset.Rows);
     63        errorState = rCalculator.ErrorState;
     64        r = rCalculator.R;
    6565      } else {
    6666        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    67         r2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
     67        r = OnlinePearsonsRCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    6868      }
    6969      if (errorState != OnlineCalculatorError.None) return double.NaN;
    70       return r2;
     70      return r*r;
    7171    }
    7272
  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression

  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs

    r12009 r12669  
    5757      OnlineCalculatorError errorState;
    5858
    59       double r2;
     59      double r;
    6060      if (applyLinearScaling) {
    61         var r2Calculator = new OnlinePearsonsRSquaredCalculator();
    62         CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, r2Calculator, problemData.Dataset.Rows);
    63         errorState = r2Calculator.ErrorState;
    64         r2 = r2Calculator.RSquared;
     61        var rCalculator = new OnlinePearsonsRCalculator();
     62        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, rCalculator, problemData.Dataset.Rows);
     63        errorState = rCalculator.ErrorState;
     64        r = rCalculator.R;
    6565      } else {
    6666        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    67         r2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
     67        r = OnlinePearsonsRCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    6868      }
    6969
    70       if (errorState != OnlineCalculatorError.None) r2 = double.NaN;
    71       return new double[2] { r2, solution.Length };
     70      if (errorState != OnlineCalculatorError.None) r = double.NaN;
     71      return new double[2] { r*r, solution.Length };
    7272    }
    7373
  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs

    r12009 r12669  
    5959      OnlineCalculatorError errorState;
    6060
    61       double r2;
     61      double r;
    6262      if (applyLinearScaling) {
    63         var r2Calculator = new OnlinePearsonsRSquaredCalculator();
    64         CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, r2Calculator, problemData.Dataset.Rows);
    65         errorState = r2Calculator.ErrorState;
    66         r2 = r2Calculator.RSquared;
     63        var rCalculator = new OnlinePearsonsRCalculator();
     64        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, rCalculator, problemData.Dataset.Rows);
     65        errorState = rCalculator.ErrorState;
     66        r = rCalculator.R;
    6767      } else {
    6868        IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    69         r2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
     69        r = OnlinePearsonsRCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    7070      }
    7171      if (errorState != OnlineCalculatorError.None) return double.NaN;
    72       return r2;
     72      return r*r;
    7373    }
    7474
  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningOperator.cs

    r12009 r12669  
    6060      var targetValues = ProblemData.Dataset.GetDoubleValues(regressionProblemData.TargetVariable, trainingIndices);
    6161      OnlineCalculatorError errorState;
    62       var quality = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, estimatedValues, out errorState);
     62      var quality = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out errorState);
    6363      if (errorState != OnlineCalculatorError.None) return double.NaN;
    64       return quality;
     64      return quality*quality;
    6565    }
    6666  }
  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolutionImpactValuesCalculator.cs

    r12009 r12669  
    6666      if (double.IsNaN(originalQuality)) {
    6767        var originalValues = regressionModel.GetEstimatedValues(dataset, rows);
    68         originalQuality = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, originalValues, out errorState);
     68        originalQuality = OnlinePearsonsRCalculator.Calculate(targetValues, originalValues, out errorState);
    6969        if (errorState != OnlineCalculatorError.None) originalQuality = 0.0;
    7070      }
     
    8383
    8484      var estimatedValues = tempModel.GetEstimatedValues(dataset, rows);
    85       double newQuality = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, estimatedValues, out errorState);
     85      double newQuality = OnlinePearsonsRCalculator.Calculate(targetValues, estimatedValues, out errorState);
    8686      if (errorState != OnlineCalculatorError.None) newQuality = 0.0;
    8787
    88       impactValue = originalQuality - newQuality;
     88      impactValue = (originalQuality*originalQuality) - (newQuality*newQuality);
    8989    }
    9090  }
  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis.Views/3.4/InteractiveSymbolicTimeSeriesPrognosisSolutionSimplifierView.cs

    r12009 r12669  
    6060      List<ISymbolicExpressionTreeNode> nodes = tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPostfix().ToList();
    6161      OnlineCalculatorError errorState;
    62       double originalR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, originalOutput, out errorState);
    63       if (errorState != OnlineCalculatorError.None) originalR2 = 0.0;
     62      double originalR = OnlinePearsonsRCalculator.Calculate(targetValues, originalOutput, out errorState);
     63      if (errorState != OnlineCalculatorError.None) originalR = 0.0;
    6464
    6565      foreach (ISymbolicExpressionTreeNode node in nodes) {
     
    6969        SwitchNode(parent, node, replacementNode);
    7070        var newOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows);
    71         double newR2 = OnlinePearsonsRSquaredCalculator.Calculate(targetValues, newOutput, out errorState);
    72         if (errorState != OnlineCalculatorError.None) newR2 = 0.0;
     71        double newR = OnlinePearsonsRCalculator.Calculate(targetValues, newOutput, out errorState);
     72        if (errorState != OnlineCalculatorError.None) newR = 0.0;
    7373
    7474        // impact = 0 if no change
    7575        // impact < 0 if new solution is better
    7676        // impact > 0 if new solution is worse
    77         double impact = originalR2 - newR2;
     77        double impact = (originalR*originalR) - (newR*newR);
    7878        impactAndReplacementValues[node] = new Tuple<double, double>(impact, constantNode.Value);
    7979        SwitchNode(parent, replacementNode, node);
  • stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreePhenotypicSimilarityCalculator.cs

    r12281 r12669  
    6565
    6666      OnlineCalculatorError error;
    67       var r2 = OnlinePearsonsRSquaredCalculator.Calculate(v1, v2, out error);
     67      var r = OnlinePearsonsRCalculator.Calculate(v1, v2, out error);
    6868
    69       if (r2 > 1.0)
    70         r2 = 1.0;
     69      if (r > 1.0)
     70        r = 1.0;
    7171
    72       return error == OnlineCalculatorError.None ? r2 : 0;
     72      return error == OnlineCalculatorError.None ? r*r : 0;
    7373    }
    7474
     
    8787
    8888      OnlineCalculatorError error;
    89       var r2 = OnlinePearsonsRSquaredCalculator.Calculate(leftValues, rightValues, out error);
     89      var r = OnlinePearsonsRCalculator.Calculate(leftValues, rightValues, out error);
    9090
    91       if (r2 > 1.0)
    92         r2 = 1.0; // sometimes due to fp errors it can happen that the r2 is over 1 (like 1.0000000009)
     91      if (r > 1.0)
     92        r = 1.0; // sometimes due to fp errors it can happen that the correlation is over 1 (like 1.0000000009)
    9393
    94       return error == OnlineCalculatorError.None ? r2 : 0;
     94      return error == OnlineCalculatorError.None ? r*r : 0;
    9595    }
    9696  }
  • stable/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r11920 r12669  
    222222    <Compile Include="OnlineCalculators\OnlineMeanSquaredErrorCalculator.cs" />
    223223    <Compile Include="OnlineCalculators\OnlineNormalizedMeanSquaredErrorCalculator.cs" />
     224    <Compile Include="OnlineCalculators\OnlinePearsonsRCalculator.cs" />
    224225    <Compile Include="OnlineCalculators\OnlinePearsonsRSquaredCalculator.cs" />
    225226    <Compile Include="Implementation\Regression\RegressionSolution.cs" />
  • stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolutionBase.cs

    r12009 r12669  
    105105      TestMeanSquaredError = errorState == OnlineCalculatorError.None ? testMSE : double.NaN;
    106106
    107       double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    108       TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR2 : double.NaN;
    109       double testR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    110       TestRSquared = errorState == OnlineCalculatorError.None ? testR2 : double.NaN;
     107      double trainingR = OnlinePearsonsRCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
     108      TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR*trainingR : double.NaN;
     109      double testR = OnlinePearsonsRCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
     110      TestRSquared = errorState == OnlineCalculatorError.None ? testR*testR : double.NaN;
    111111
    112112      double trainingNormalizedGini = NormalizedGiniCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
  • stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolutionBase.cs

    r12636 r12669  
    229229      TestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMAE : double.NaN;
    230230
    231       double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    232       TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR2 : double.NaN;
    233       double testR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    234       TestRSquared = errorState == OnlineCalculatorError.None ? testR2 : double.NaN;
     231      double trainingR = OnlinePearsonsRCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
     232      TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR*trainingR : double.NaN;
     233      double testR = OnlinePearsonsRCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
     234      TestRSquared = errorState == OnlineCalculatorError.None ? testR*testR : double.NaN;
    235235
    236236      double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
  • stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisResults.cs

    r12009 r12669  
    394394      double trainingMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    395395      PrognosisTrainingMeanAbsoluteError = errorState == OnlineCalculatorError.None ? trainingMAE : double.NaN;
    396       double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    397       PrognosisTrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR2 : double.NaN;
     396      double trainingR = OnlinePearsonsRCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
     397      PrognosisTrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR*trainingR : double.NaN;
    398398      double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    399399      PrognosisTrainingRelativeError = errorState == OnlineCalculatorError.None ? trainingRelError : double.NaN;
     
    430430      double testMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    431431      PrognosisTestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMAE : double.NaN;
    432       double testR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    433       PrognosisTestRSquared = errorState == OnlineCalculatorError.None ? testR2 : double.NaN;
     432      double testR = OnlinePearsonsRCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
     433      PrognosisTestRSquared = errorState == OnlineCalculatorError.None ? testR*testR : double.NaN;
    434434      double testRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    435435      PrognosisTestRelativeError = errorState == OnlineCalculatorError.None ? testRelError : double.NaN;
  • stable/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/PearsonsRDependenceCalculator.cs

    r12009 r12669  
    3333
    3434    public double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {
    35       return Math.Sqrt(OnlinePearsonsRSquaredCalculator.Calculate(originalValues, estimatedValues, out errorState));
     35      return OnlinePearsonsRCalculator.Calculate(originalValues, estimatedValues, out errorState);
    3636    }
    3737  }
  • stable/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/PearsonsRSquaredDependenceCalculator.cs

    r12009 r12669  
    3232
    3333    public double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {
    34       return OnlinePearsonsRSquaredCalculator.Calculate(originalValues, estimatedValues, out errorState);
     34      var r = OnlinePearsonsRCalculator.Calculate(originalValues, estimatedValues, out errorState);
     35      return r * r;
    3536    }
    3637  }
  • stable/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlinePearsonsRSquaredCalculator.cs

    r12009 r12669  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis {
     27  [Obsolete("Use OnlinePearsonsRCalculator directly")]
    2728  public class OnlinePearsonsRSquaredCalculator : IOnlineCalculator {
    28     private OnlineCovarianceCalculator covCalculator = new OnlineCovarianceCalculator();
    29     private OnlineMeanAndVarianceCalculator sxCalculator = new OnlineMeanAndVarianceCalculator();
    30     private OnlineMeanAndVarianceCalculator syCalculator = new OnlineMeanAndVarianceCalculator();
     29    private readonly OnlinePearsonsRCalculator rCalculator = new OnlinePearsonsRCalculator();
    3130
    3231    public double RSquared {
    3332      get {
    34         double xVar = sxCalculator.PopulationVariance;
    35         double yVar = syCalculator.PopulationVariance;
    36         if (xVar.IsAlmost(0.0) || yVar.IsAlmost(0.0)) {
    37           return 0.0;
    38         } else {
    39           double r = covCalculator.Covariance / (Math.Sqrt(xVar) * Math.Sqrt(yVar));
    40           return r * r;
    41         }
     33        if (rCalculator.ErrorState != OnlineCalculatorError.None) return 0.0;
     34        else return rCalculator.R * rCalculator.R;
    4235      }
    4336    }
     
    4740    #region IOnlineCalculator Members
    4841    public OnlineCalculatorError ErrorState {
    49       get { return covCalculator.ErrorState | sxCalculator.PopulationVarianceErrorState | syCalculator.PopulationVarianceErrorState; }
     42      get { return rCalculator.ErrorState; }
    5043    }
    5144    public double Value {
     
    5346    }
    5447    public void Reset() {
    55       covCalculator.Reset();
    56       sxCalculator.Reset();
    57       syCalculator.Reset();
     48      rCalculator.Reset();
    5849    }
    5950
    6051    public void Add(double x, double y) {
    61       // no need to check validity of values explicitly here as it is checked in all three evaluators
    62       covCalculator.Add(x, y);
    63       sxCalculator.Add(x);
    64       syCalculator.Add(y);
     52      rCalculator.Add(x, y);
    6553    }
    6654
     
    6856
    6957    public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineCalculatorError errorState) {
    70       IEnumerator<double> firstEnumerator = first.GetEnumerator();
    71       IEnumerator<double> secondEnumerator = second.GetEnumerator();
    72       OnlinePearsonsRSquaredCalculator rSquaredCalculator = new OnlinePearsonsRSquaredCalculator();
    73 
    74       // always move forward both enumerators (do not use short-circuit evaluation!)
    75       while (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) {
    76         double original = firstEnumerator.Current;
    77         double estimated = secondEnumerator.Current;
    78         rSquaredCalculator.Add(original, estimated);
    79         if (rSquaredCalculator.ErrorState != OnlineCalculatorError.None) break;
    80       }
    81 
    82       // check if both enumerators are at the end to make sure both enumerations have the same length
    83       if (rSquaredCalculator.ErrorState == OnlineCalculatorError.None &&
    84            (secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) {
    85         throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
    86       } else {
    87         errorState = rSquaredCalculator.ErrorState;
    88         return rSquaredCalculator.RSquared;
    89       }
     58      var r = OnlinePearsonsRCalculator.Calculate(first, second, out errorState);
     59      return r * r;
    9060    }
    9161  }
Note: See TracChangeset for help on using the changeset viewer.