Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/16/11 15:07:36 (13 years ago)
Author:
ascheibe
Message:

#1659 updated branch from trunk

Location:
branches/Benchmarking
Files:
22 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/Benchmarking

  • branches/Benchmarking/sources

  • branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis

  • branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r6913 r7000  
    143143    <Compile Include="Interfaces\Regression\IRegressionEnsembleSolution.cs" />
    144144    <Compile Include="Implementation\Regression\RegressionSolutionBase.cs" />
     145    <Compile Include="Interfaces\TimeSeriesPrognosis\IOnlineTimeSeriesCalculator.cs" />
    145146    <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisModel.cs" />
    146147    <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisProblem.cs" />
  • branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs

    r6666 r7000  
    201201
    202202    public IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(Dataset dataset, IEnumerable<int> rows) {
     203      if (!Model.Models.Any()) yield break;
    203204      var estimatedValuesEnumerators = (from model in Model.Models
    204205                                        select model.GetEstimatedClassValues(dataset, rows).GetEnumerator())
  • branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionBase.cs

    r6913 r7000  
    8484
    8585      OnlineCalculatorError errorState;
    86       double trainingAccuracy = OnlineAccuracyCalculator.Calculate(estimatedTrainingClassValues, originalTrainingClassValues, out errorState);
     86      double trainingAccuracy = OnlineAccuracyCalculator.Calculate(originalTrainingClassValues, estimatedTrainingClassValues, out errorState);
    8787      if (errorState != OnlineCalculatorError.None) trainingAccuracy = double.NaN;
    88       double testAccuracy = OnlineAccuracyCalculator.Calculate(estimatedTestClassValues, originalTestClassValues, out errorState);
     88      double testAccuracy = OnlineAccuracyCalculator.Calculate(originalTestClassValues, estimatedTestClassValues, out errorState);
    8989      if (errorState != OnlineCalculatorError.None) testAccuracy = double.NaN;
    9090
  • branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolutionBase.cs

    r6913 r7000  
    108108
    109109      OnlineCalculatorError errorState;
    110       double trainingMSE = OnlineMeanSquaredErrorCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     110      double trainingMSE = OnlineMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    111111      TrainingMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingMSE : double.NaN;
    112       double testMSE = OnlineMeanSquaredErrorCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     112      double testMSE = OnlineMeanSquaredErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    113113      TestMeanSquaredError = errorState == OnlineCalculatorError.None ? testMSE : double.NaN;
    114114
    115       double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     115      double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    116116      TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR2 : double.NaN;
    117       double testR2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     117      double testR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    118118      TestRSquared = errorState == OnlineCalculatorError.None ? testR2 : double.NaN;
    119119
  • branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs

    r6666 r7000  
    6464    private void AfterDeserialization() {
    6565      foreach (var model in Model.Models) {
    66         IRegressionProblemData problemData = (IRegressionProblemData) ProblemData.Clone();
     66        IRegressionProblemData problemData = (IRegressionProblemData)ProblemData.Clone();
    6767        problemData.TrainingPartition.Start = trainingPartitions[model].Start;
    6868        problemData.TrainingPartition.End = trainingPartitions[model].End;
     
    202202
    203203    public IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(Dataset dataset, IEnumerable<int> rows) {
     204      if (!Model.Models.Any()) yield break;
    204205      var estimatedValuesEnumerators = (from model in Model.Models
    205206                                        select model.GetEstimatedValues(dataset, rows).GetEnumerator())
  • branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolutionBase.cs

    r6740 r7000  
    147147
    148148      OnlineCalculatorError errorState;
    149       double trainingMSE = OnlineMeanSquaredErrorCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     149      double trainingMSE = OnlineMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    150150      TrainingMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingMSE : double.NaN;
    151       double testMSE = OnlineMeanSquaredErrorCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     151      double testMSE = OnlineMeanSquaredErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    152152      TestMeanSquaredError = errorState == OnlineCalculatorError.None ? testMSE : double.NaN;
    153153
    154       double trainingMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     154      double trainingMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    155155      TrainingMeanAbsoluteError = errorState == OnlineCalculatorError.None ? trainingMAE : double.NaN;
    156       double testMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     156      double testMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    157157      TestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMAE : double.NaN;
    158158
    159       double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     159      double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    160160      TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR2 : double.NaN;
    161       double testR2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     161      double testR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    162162      TestRSquared = errorState == OnlineCalculatorError.None ? testR2 : double.NaN;
    163163
    164       double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     164      double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    165165      TrainingRelativeError = errorState == OnlineCalculatorError.None ? trainingRelError : double.NaN;
    166       double testRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     166      double testRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    167167      TestRelativeError = errorState == OnlineCalculatorError.None ? testRelError : double.NaN;
    168168
    169       double trainingNMSE = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     169      double trainingNMSE = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    170170      TrainingNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingNMSE : double.NaN;
    171       double testNMSE = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     171      double testNMSE = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    172172      TestNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? testNMSE : double.NaN;
    173173    }
  • branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionBase.cs

    r6802 r7000  
    4040    private const string TrainingNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (training)";
    4141    private const string TestNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (test)";
    42     private const string TrainingDirectionalSymmetryResultName = "Directional symmetry (training)";
    43     private const string TestDirectionalSymmetryResultName = "Directional symmetry (test)";
    44     private const string TrainingWeightedDirectionalSymmetryResultName = "Weighted directional symmetry (training)";
    45     private const string TestWeightedDirectionalSymmetryResultName = "Weighted directional symmetry (test)";
    46     private const string TrainingTheilsUStatisticResultName = "Theil's U (training)";
    47     private const string TestTheilsUStatisticResultName = "Theil's U (test)";
     42    private const string TrainingDirectionalSymmetryResultName = "Average directional symmetry (training)";
     43    private const string TestDirectionalSymmetryResultName = "Average directional symmetry (test)";
     44    private const string TrainingWeightedDirectionalSymmetryResultName = "Average weighted directional symmetry (training)";
     45    private const string TestWeightedDirectionalSymmetryResultName = "Average weighted directional symmetry (test)";
     46    private const string TrainingTheilsUStatisticResultName = "Average Theil's U (training)";
     47    private const string TestTheilsUStatisticResultName = "Average Theil's U (test)";
    4848
    4949    public new ITimeSeriesPrognosisModel Model {
     
    146146      Add(new Result(TrainingNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the training partition", new DoubleValue()));
    147147      Add(new Result(TestNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the test partition", new DoubleValue()));
    148       Add(new Result(TrainingDirectionalSymmetryResultName, "The directional symmetry of the output of the model on the training partition", new DoubleValue()));
    149       Add(new Result(TestDirectionalSymmetryResultName, "The directional symmetry of the output of the model on the test partition", new DoubleValue()));
    150       Add(new Result(TrainingWeightedDirectionalSymmetryResultName, "The weighted directional symmetry of the output of the model on the training partition", new DoubleValue()));
    151       Add(new Result(TestWeightedDirectionalSymmetryResultName, "The weighted directional symmetry of the output of the model on the test partition", new DoubleValue()));
    152       Add(new Result(TrainingTheilsUStatisticResultName, "The Theil's U statistic of the output of the model on the training partition", new DoubleValue()));
    153       Add(new Result(TestTheilsUStatisticResultName, "The Theil's U statistic of the output of the model on the test partition", new DoubleValue()));
     148      Add(new Result(TrainingDirectionalSymmetryResultName, "The average directional symmetry of the forecasts of the model on the training partition", new PercentValue()));
     149      Add(new Result(TestDirectionalSymmetryResultName, "The average directional symmetry of the forecasts of the model on the test partition", new PercentValue()));
     150      Add(new Result(TrainingWeightedDirectionalSymmetryResultName, "The average weighted directional symmetry of the forecasts of the model on the training partition", new DoubleValue()));
     151      Add(new Result(TestWeightedDirectionalSymmetryResultName, "The average weighted directional symmetry of the forecasts of the model on the test partition", new DoubleValue()));
     152      Add(new Result(TrainingTheilsUStatisticResultName, "The average Theil's U statistic of the forecasts of the model on the training partition", new DoubleValue()));
     153      Add(new Result(TestTheilsUStatisticResultName, "The average Theil's U statistic of the forecasts of the model on the test partition", new DoubleValue()));
    154154    }
    155155
     
    166166
    167167      OnlineCalculatorError errorState;
    168       double trainingMse = OnlineMeanSquaredErrorCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     168      double trainingMse = OnlineMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    169169      TrainingMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingMse : double.NaN;
    170       double testMse = OnlineMeanSquaredErrorCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     170      double testMse = OnlineMeanSquaredErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    171171      TestMeanSquaredError = errorState == OnlineCalculatorError.None ? testMse : double.NaN;
    172172
    173       double trainingMae = OnlineMeanAbsoluteErrorCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     173      double trainingMae = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    174174      TrainingMeanAbsoluteError = errorState == OnlineCalculatorError.None ? trainingMae : double.NaN;
    175       double testMae = OnlineMeanAbsoluteErrorCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     175      double testMae = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    176176      TestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMae : double.NaN;
    177177
    178       double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     178      double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    179179      TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR2 : double.NaN;
    180       double testR2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     180      double testR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    181181      TestRSquared = errorState == OnlineCalculatorError.None ? testR2 : double.NaN;
    182182
    183       double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     183      double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    184184      TrainingRelativeError = errorState == OnlineCalculatorError.None ? trainingRelError : double.NaN;
    185       double testRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     185      double testRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    186186      TestRelativeError = errorState == OnlineCalculatorError.None ? testRelError : double.NaN;
    187187
    188       double trainingNmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     188      double trainingNmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState);
    189189      TrainingNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingNmse : double.NaN;
    190       double testNmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     190      double testNmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(originalTestValues, estimatedTestValues, out errorState);
    191191      TestNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? testNmse : double.NaN;
    192192
    193       double trainingDirectionalSymmetry = OnlineDirectionalSymmetryCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     193      var startTrainingValues = originalTrainingValues;
     194      // each continuation is only one element long
     195      var actualContinuationsTraining = from x in originalTrainingValues.Skip(1)
     196                                        select Enumerable.Repeat(x, 1);
     197      // each forecast is only one elemnt long
     198      // disregards the first estimated value (we could include this again by extending the list of original values by one step to the left
     199      // this is the easier way
     200      var predictedContinuationsTraining = from x in estimatedTrainingValues.Skip(1)
     201                                           select Enumerable.Repeat(x, 1);
     202
     203      var startTestValues = originalTestValues;
     204      var actualContinuationsTest = from x in originalTestValues.Skip(1)
     205                                    select Enumerable.Repeat(x, 1);
     206      var predictedContinuationsTest = from x in estimatedTestValues.Skip(1)
     207                                       select Enumerable.Repeat(x, 1);
     208
     209      double trainingDirectionalSymmetry = OnlineDirectionalSymmetryCalculator.Calculate(startTrainingValues, actualContinuationsTraining, predictedContinuationsTraining, out errorState);
    194210      TrainingDirectionalSymmetry = errorState == OnlineCalculatorError.None ? trainingDirectionalSymmetry : double.NaN;
    195       double testDirectionalSymmetry = OnlineDirectionalSymmetryCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     211      double testDirectionalSymmetry = OnlineDirectionalSymmetryCalculator.Calculate(startTestValues, actualContinuationsTest, predictedContinuationsTest, out errorState);
    196212      TestDirectionalSymmetry = errorState == OnlineCalculatorError.None ? testDirectionalSymmetry : double.NaN;
    197213
    198       double trainingWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     214      double trainingWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate(startTrainingValues, actualContinuationsTraining, predictedContinuationsTraining, out errorState);
    199215      TrainingWeightedDirectionalSymmetry = errorState == OnlineCalculatorError.None ? trainingWeightedDirectionalSymmetry : double.NaN;
    200       double testWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     216      double testWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate(startTestValues, actualContinuationsTest, predictedContinuationsTest, out errorState);
    201217      TestWeightedDirectionalSymmetry = errorState == OnlineCalculatorError.None ? testWeightedDirectionalSymmetry : double.NaN;
    202218
    203       double trainingTheilsU = OnlineTheilsUStatisticCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);
     219      double trainingTheilsU = OnlineTheilsUStatisticCalculator.Calculate(startTrainingValues, actualContinuationsTraining, predictedContinuationsTraining, out errorState);
    204220      TrainingTheilsUStatistic = errorState == OnlineCalculatorError.None ? trainingTheilsU : double.NaN;
    205       double testTheilsU = OnlineTheilsUStatisticCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState);
     221      double testTheilsU = OnlineTheilsUStatisticCalculator.Calculate(startTestValues, actualContinuationsTest, predictedContinuationsTest, out errorState);
    206222      TestTheilsUStatistic = errorState == OnlineCalculatorError.None ? testTheilsU : double.NaN;
    207 
    208 
    209223    }
    210224  }
  • branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/NormalizedGiniCalculator.cs

    r6913 r7000  
    2828  public class NormalizedGiniCalculator {
    2929
    30     public static double Calculate(IEnumerable<double> original, IEnumerable<double> estimated, out OnlineCalculatorError errorState) {
    31       if (original.Count() != estimated.Count()) {
    32         throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
     30    public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {
     31      var originalValuesArr = originalValues.ToArray();
     32      var estimatedValuesArr = estimatedValues.ToArray();
     33      if (originalValuesArr.Count() != estimatedValuesArr.Count()) {
     34        throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match.");
    3335      }
    34       double oe = Gini(original, estimated, out errorState);
     36      double oe = Gini(originalValuesArr, estimatedValuesArr, out errorState);
    3537      if (errorState != OnlineCalculatorError.None) return double.NaN;
    3638
    37       return oe / (Gini(original, original, out errorState));
     39      return oe / (Gini(originalValuesArr, estimatedValuesArr, out errorState));
    3840    }
    3941
  • branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineAccuracyCalculator.cs

    r5945 r7000  
    6868    #endregion
    6969
    70     public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineCalculatorError errorState) {
    71       IEnumerator<double> firstEnumerator = first.GetEnumerator();
    72       IEnumerator<double> secondEnumerator = second.GetEnumerator();
     70    public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {
     71      IEnumerator<double> originalEnumerator = originalValues.GetEnumerator();
     72      IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator();
    7373      OnlineAccuracyCalculator accuracyCalculator = new OnlineAccuracyCalculator();
    7474
    7575      // always move forward both enumerators (do not use short-circuit evaluation!)
    76       while (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) {
    77         double estimated = secondEnumerator.Current;
    78         double original = firstEnumerator.Current;
     76      while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
     77        double original = originalEnumerator.Current;
     78        double estimated = estimatedEnumerator.Current;
    7979        accuracyCalculator.Add(original, estimated);
    8080        if (accuracyCalculator.ErrorState != OnlineCalculatorError.None) break;
     
    8383      // check if both enumerators are at the end to make sure both enumerations have the same length
    8484      if (accuracyCalculator.ErrorState == OnlineCalculatorError.None &&
    85           (secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) {
    86         throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
     85          (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) {
     86        throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match.");
    8787      } else {
    8888        errorState = accuracyCalculator.ErrorState;
  • branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineCovarianceCalcualtor.cs

    r5945 r7000  
    2626  public class OnlineCovarianceCalculator : IOnlineCalculator {
    2727
    28     private double originalMean, estimatedMean, Cn;
     28    private double xMean, yMean, Cn;
    2929    private int n;
    3030    public double Covariance {
     
    4949      n = 0;
    5050      Cn = 0.0;
    51       originalMean = 0.0;
    52       estimatedMean = 0.0;
     51      xMean = 0.0;
     52      yMean = 0.0;
    5353      errorState = OnlineCalculatorError.InsufficientElementsAdded;
    5454    }
    5555
    56     public void Add(double original, double estimated) {
    57       if (double.IsNaN(estimated) || double.IsInfinity(estimated) || double.IsNaN(original) || double.IsInfinity(original) || (errorState & OnlineCalculatorError.InvalidValueAdded) > 0) {
     56    public void Add(double x, double y) {
     57      if (double.IsNaN(y) || double.IsInfinity(y) || double.IsNaN(x) || double.IsInfinity(x) || (errorState & OnlineCalculatorError.InvalidValueAdded) > 0) {
    5858        errorState = errorState | OnlineCalculatorError.InvalidValueAdded;
    5959      } else {
     
    6262
    6363        // online calculation of tMean
    64         originalMean = originalMean + (original - originalMean) / n;
    65         double delta = estimated - estimatedMean; // delta = (y - yMean(n-1))
    66         estimatedMean = estimatedMean + delta / n;
     64        xMean = xMean + (x - xMean) / n;
     65        double delta = y - yMean; // delta = (y - yMean(n-1))
     66        yMean = yMean + delta / n;
    6767
    6868        // online calculation of covariance
    69         Cn = Cn + delta * (original - originalMean); // C(n) = C(n-1) + (y - yMean(n-1)) (t - tMean(n))       
     69        Cn = Cn + delta * (x - xMean); // C(n) = C(n-1) + (y - yMean(n-1)) (t - tMean(n))       
    7070      }
    7171    }
     
    7979      // always move forward both enumerators (do not use short-circuit evaluation!)
    8080      while (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) {
    81         double estimated = secondEnumerator.Current;
    82         double original = firstEnumerator.Current;
    83         covarianceCalculator.Add(original, estimated);
     81        double x = secondEnumerator.Current;
     82        double y = firstEnumerator.Current;
     83        covarianceCalculator.Add(x, y);
    8484        if (covarianceCalculator.ErrorState != OnlineCalculatorError.None) break;
    8585      }
  • branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineDirectionalSymmetryCalculator.cs

    r6802 r7000  
    2222using System;
    2323using System.Collections.Generic;
     24using HeuristicLab.Common;
    2425
    2526
    2627namespace HeuristicLab.Problems.DataAnalysis {
    27   public class OnlineDirectionalSymmetryCalculator : IOnlineCalculator {
    28     private double prevEstimated;
    29     private double prevOriginal;
     28  public class OnlineDirectionalSymmetryCalculator : IOnlineTimeSeriesCalculator {
    3029    private int n;
    3130    private int nCorrect;
     
    3332    public double DirectionalSymmetry {
    3433      get {
    35         if (n <= 1) return 0.0;
    36         return (double)nCorrect / (n - 1) * 100.0;
     34        if (n < 1) return 0.0;
     35        return (double)nCorrect / n;
    3736      }
    3837    }
     
    5150    }
    5251
    53     public void Add(double original, double estimated) {
    54       if (double.IsNaN(estimated) || double.IsInfinity(estimated) || double.IsNaN(original) || double.IsInfinity(original) || (errorState & OnlineCalculatorError.InvalidValueAdded) > 0) {
     52    public void Add(double startValue, IEnumerable<double> actualContinuation, IEnumerable<double> predictedContinuation) {
     53      if (double.IsNaN(startValue) || (errorState & OnlineCalculatorError.InvalidValueAdded) > 0) {
    5554        errorState = errorState | OnlineCalculatorError.InvalidValueAdded;
    56       } else if (n == 0) {
    57         prevOriginal = original;
    58         prevEstimated = estimated;
    59         n++;
    6055      } else {
    61         if ((original - prevOriginal) * (estimated - prevEstimated) >= 0.0) {
    62           nCorrect++;
     56        var actualEnumerator = actualContinuation.GetEnumerator();
     57        var predictedEnumerator = predictedContinuation.GetEnumerator();
     58        double prevActual = startValue;
     59        double prevPredicted = startValue;
     60        while (actualEnumerator.MoveNext() & predictedEnumerator.MoveNext() & errorState != OnlineCalculatorError.InvalidValueAdded) {
     61          double actual = actualEnumerator.Current;
     62          double predicted = predictedEnumerator.Current;
     63          if (double.IsNaN(actual) || double.IsNaN(predicted)) {
     64            errorState = errorState | OnlineCalculatorError.InvalidValueAdded;
     65          } else {
     66            // count a prediction correct if the trend (positive/negative/no change) is predicted correctly
     67            if ((actual - prevActual) * (predicted - prevPredicted) > 0.0 ||
     68                (actual - prevActual).IsAlmost(predicted - prevPredicted)
     69              ) {
     70              nCorrect++;
     71            }
     72            n++;
     73          }
    6374        }
    64         n++;
    65         errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded);        // n >= 1
    66         prevOriginal = original;
    67         prevEstimated = estimated;
     75        // check if both enumerators are at the end to make sure both enumerations have the same length
     76        if (actualEnumerator.MoveNext() || predictedEnumerator.MoveNext()) {
     77          errorState = errorState | OnlineCalculatorError.InvalidValueAdded;
     78        } else {
     79          errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded); // n >= 1
     80        }
    6881      }
    6982    }
     
    7285      n = 0;
    7386      nCorrect = 0;
    74       prevOriginal = double.NaN;
    75       prevEstimated = double.NaN;
    7687      errorState = OnlineCalculatorError.InsufficientElementsAdded;
    7788    }
    7889
    7990
    80     public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineCalculatorError errorState) {
    81       IEnumerator<double> firstEnumerator = first.GetEnumerator();
    82       IEnumerator<double> secondEnumerator = second.GetEnumerator();
     91    public static double Calculate(IEnumerable<double> startValues, IEnumerable<IEnumerable<double>> actualContinuations, IEnumerable<IEnumerable<double>> predictedContinuations, out OnlineCalculatorError errorState) {
     92      IEnumerator<double> startValueEnumerator = startValues.GetEnumerator();
     93      IEnumerator<IEnumerable<double>> actualContinuationsEnumerator = actualContinuations.GetEnumerator();
     94      IEnumerator<IEnumerable<double>> predictedContinuationsEnumerator = predictedContinuations.GetEnumerator();
    8395      OnlineDirectionalSymmetryCalculator dsCalculator = new OnlineDirectionalSymmetryCalculator();
    8496
    85       // add first element of time series as a reference point
    86       firstEnumerator.MoveNext();
    87       secondEnumerator.MoveNext();
    88       dsCalculator.Add(firstEnumerator.Current, secondEnumerator.Current);
    89      
    90       // always move forward both enumerators (do not use short-circuit evaluation!)
    91       while (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) {
    92         double estimated = secondEnumerator.Current;
    93         double original = firstEnumerator.Current;
    94         dsCalculator.Add(original, estimated);
     97      // always move forward all enumerators (do not use short-circuit evaluation!)
     98      while (startValueEnumerator.MoveNext() & actualContinuationsEnumerator.MoveNext() & predictedContinuationsEnumerator.MoveNext()) {
     99        dsCalculator.Add(startValueEnumerator.Current, actualContinuationsEnumerator.Current, predictedContinuationsEnumerator.Current);
    95100        if (dsCalculator.ErrorState != OnlineCalculatorError.None) break;
    96101      }
    97102
    98       // check if both enumerators are at the end to make sure both enumerations have the same length
     103      // check if all enumerators are at the end to make sure both enumerations have the same length
    99104      if (dsCalculator.ErrorState == OnlineCalculatorError.None &&
    100           (secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) {
    101         throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
     105          (startValueEnumerator.MoveNext() || actualContinuationsEnumerator.MoveNext() || predictedContinuationsEnumerator.MoveNext())) {
     106        throw new ArgumentException("Number of elements in startValues, actualContinuations and estimatedValues predictedContinuations doesn't match.");
    102107      } else {
    103108        errorState = dsCalculator.ErrorState;
  • branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanAbsoluteErrorCalculator.cs

    r6643 r7000  
    6565    #endregion
    6666
    67     public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineCalculatorError errorState) {
    68       IEnumerator<double> firstEnumerator = first.GetEnumerator();
    69       IEnumerator<double> secondEnumerator = second.GetEnumerator();
     67    public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {
     68      IEnumerator<double> originalEnumerator = originalValues.GetEnumerator();
     69      IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator();
    7070      OnlineMeanAbsoluteErrorCalculator maeCalculator = new OnlineMeanAbsoluteErrorCalculator();
    7171
    7272      // always move forward both enumerators (do not use short-circuit evaluation!)
    73       while (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) {
    74         double estimated = secondEnumerator.Current;
    75         double original = firstEnumerator.Current;
     73      while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
     74        double original = originalEnumerator.Current;
     75        double estimated = estimatedEnumerator.Current;
    7676        maeCalculator.Add(original, estimated);
    7777        if (maeCalculator.ErrorState != OnlineCalculatorError.None) break;
     
    8080      // check if both enumerators are at the end to make sure both enumerations have the same length
    8181      if (maeCalculator.ErrorState == OnlineCalculatorError.None &&
    82          (secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) {
    83         throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
     82         (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) {
     83        throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match.");
    8484      } else {
    8585        errorState = maeCalculator.ErrorState;
  • branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanAbsolutePercentageErrorCalculator.cs

    r5945 r7000  
    6767    #endregion
    6868
    69     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();
     69    public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {
     70      IEnumerator<double> originalEnumerator = originalValues.GetEnumerator();
     71      IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator();
    7272      OnlineMeanAbsolutePercentageErrorCalculator calculator = new OnlineMeanAbsolutePercentageErrorCalculator();
    7373
    7474      // always move forward both enumerators (do not use short-circuit evaluation!)
    75       while (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) {
    76         double estimated = secondEnumerator.Current;
    77         double original = firstEnumerator.Current;
     75      while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
     76        double original = originalEnumerator.Current;
     77        double estimated = estimatedEnumerator.Current;
    7878        calculator.Add(original, estimated);
    7979        if (calculator.ErrorState != OnlineCalculatorError.None) break;
     
    8282      // check if both enumerators are at the end to make sure both enumerations have the same length
    8383      if (calculator.ErrorState == OnlineCalculatorError.None &&
    84             (secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) {
    85         throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
     84            (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) {
     85        throw new ArgumentException("Number of elements in originalValues and second estimatedValues doesn't match.");
    8686      } else {
    8787        errorState = calculator.ErrorState;
  • branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanSquaredErrorCalculator.cs

    r5945 r7000  
    6565    #endregion
    6666
    67     public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineCalculatorError errorState) {
    68       IEnumerator<double> firstEnumerator = first.GetEnumerator();
    69       IEnumerator<double> secondEnumerator = second.GetEnumerator();
     67    public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {
     68      IEnumerator<double> originalEnumerator = originalValues.GetEnumerator();
     69      IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator();
    7070      OnlineMeanSquaredErrorCalculator mseCalculator = new OnlineMeanSquaredErrorCalculator();
    7171
    7272      // always move forward both enumerators (do not use short-circuit evaluation!)
    73       while (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) {
    74         double estimated = secondEnumerator.Current;
    75         double original = firstEnumerator.Current;
     73      while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
     74        double original = originalEnumerator.Current;
     75        double estimated = estimatedEnumerator.Current;
    7676        mseCalculator.Add(original, estimated);
    7777        if (mseCalculator.ErrorState != OnlineCalculatorError.None) break;
     
    8080      // check if both enumerators are at the end to make sure both enumerations have the same length
    8181      if (mseCalculator.ErrorState == OnlineCalculatorError.None &&
    82          (secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) {
    83         throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
     82         (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) {
     83        throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match.");
    8484      } else {
    8585        errorState = mseCalculator.ErrorState;
  • branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineNormalizedMeanSquaredErrorCalculator.cs

    r5962 r7000  
    6363    #endregion
    6464
    65     public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineCalculatorError errorState) {
    66       IEnumerator<double> firstEnumerator = first.GetEnumerator();
    67       IEnumerator<double> secondEnumerator = second.GetEnumerator();
     65    public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {
     66      IEnumerator<double> originalEnumerator = originalValues.GetEnumerator();
     67      IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator();
    6868      OnlineNormalizedMeanSquaredErrorCalculator normalizedMSECalculator = new OnlineNormalizedMeanSquaredErrorCalculator();
    6969
    7070      //needed because otherwise the normalizedMSECalculator is in ErrorState.InsufficientValuesAdded
    71       if (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) {
    72         double estimated = secondEnumerator.Current;
    73         double original = firstEnumerator.Current;
     71      if (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
     72        double original = originalEnumerator.Current;
     73        double estimated = estimatedEnumerator.Current;
    7474        normalizedMSECalculator.Add(original, estimated);
    7575      }
    7676
    7777      // always move forward both enumerators (do not use short-circuit evaluation!)
    78       while (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) {
    79         double estimated = secondEnumerator.Current;
    80         double original = firstEnumerator.Current;
     78      while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {
     79        double original = originalEnumerator.Current;
     80        double estimated = estimatedEnumerator.Current;
    8181        normalizedMSECalculator.Add(original, estimated);
    8282        if (normalizedMSECalculator.ErrorState != OnlineCalculatorError.None) break;
     
    8585      // check if both enumerators are at the end to make sure both enumerations have the same length
    8686      if (normalizedMSECalculator.ErrorState == OnlineCalculatorError.None &&
    87            (secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) {
    88         throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
     87           (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) {
     88        throw new ArgumentException("Number of elements in originalValues and estimatedValues enumeration doesn't match.");
    8989      } else {
    9090        errorState = normalizedMSECalculator.ErrorState;
  • branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlinePearsonsRSquaredCalculator.cs

    r5945 r7000  
    7474      // always move forward both enumerators (do not use short-circuit evaluation!)
    7575      while (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) {
     76        double original = firstEnumerator.Current;
    7677        double estimated = secondEnumerator.Current;
    77         double original = firstEnumerator.Current;
    7878        rSquaredCalculator.Add(original, estimated);
    7979        if (rSquaredCalculator.ErrorState != OnlineCalculatorError.None) break;
  • branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineTheilsUStatisticCalculator.cs

    r6807 r7000  
    2222using System;
    2323using System.Collections.Generic;
     24using HeuristicLab.Common;
    2425
    2526namespace HeuristicLab.Problems.DataAnalysis {
    26   public class OnlineTheilsUStatisticCalculator : IOnlineCalculator {
     27  public class OnlineTheilsUStatisticCalculator : IOnlineTimeSeriesCalculator {
    2728    private OnlineMeanAndVarianceCalculator squaredErrorMeanCalculator;
    2829    private OnlineMeanAndVarianceCalculator unbiasedEstimatorMeanCalculator;
    29     private double prevOriginal;
    30     private int n;
    3130
    3231    public double TheilsUStatistic {
     
    5251    }
    5352
    54     public void Add(double original, double estimated) {
    55       if (double.IsNaN(estimated) || double.IsInfinity(estimated) || double.IsNaN(original) || double.IsInfinity(original) || (errorState & OnlineCalculatorError.InvalidValueAdded) > 0) {
     53    public void Add(double startValue, IEnumerable<double> actualContinuation, IEnumerable<double> predictedContinuation) {
     54      if (double.IsNaN(startValue) || (errorState & OnlineCalculatorError.InvalidValueAdded) > 0) {
    5655        errorState = errorState | OnlineCalculatorError.InvalidValueAdded;
    57       } else if (n == 0) {
    58         prevOriginal = original;
    59         n++;
    6056      } else {
    61         // error of predicted change
    62         double errorEstimatedChange = (estimated - original);
    63         squaredErrorMeanCalculator.Add(errorEstimatedChange * errorEstimatedChange);
     57        var actualEnumerator = actualContinuation.GetEnumerator();
     58        var predictedEnumerator = predictedContinuation.GetEnumerator();
     59        while (actualEnumerator.MoveNext() & predictedEnumerator.MoveNext() & ErrorState != OnlineCalculatorError.InvalidValueAdded) {
     60          double actual = actualEnumerator.Current;
     61          double predicted = predictedEnumerator.Current;
     62          if (double.IsNaN(actual) || double.IsNaN(predicted)) {
     63            errorState = errorState | OnlineCalculatorError.InvalidValueAdded;
     64          } else {
     65            // error of predicted change
     66            double errorPredictedChange = (predicted - startValue) - (actual - startValue);
     67            squaredErrorMeanCalculator.Add(errorPredictedChange * errorPredictedChange);
    6468
    65         double errorNoChange = (original - prevOriginal);
    66         unbiasedEstimatorMeanCalculator.Add(errorNoChange * errorNoChange);
    67         errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded);        // n >= 1
    68         prevOriginal = original;
    69         n++;
     69            double errorNoChange = (actual - startValue);
     70            unbiasedEstimatorMeanCalculator.Add(errorNoChange * errorNoChange);
     71          }
     72        }
     73        // check if both enumerators are at the end to make sure both enumerations have the same length
     74        if (actualEnumerator.MoveNext() || predictedEnumerator.MoveNext()) {
     75          errorState = errorState | OnlineCalculatorError.InvalidValueAdded;
     76        } else {
     77          errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded); // n >= 1
     78        }
    7079      }
    7180    }
    7281
    73 
    7482    public void Reset() {
    75       prevOriginal = double.NaN;
    76       n = 0;
    7783      squaredErrorMeanCalculator.Reset();
    7884      unbiasedEstimatorMeanCalculator.Reset();
     
    8288    #endregion
    8389
    84     public static double Calculate(IEnumerable<double> estimatedValues, IEnumerable<double> originalValues, out OnlineCalculatorError errorState) {
    85       IEnumerator<double> originalValuesEnumerator = originalValues.GetEnumerator();
    86       IEnumerator<double> estimatedValuesEnumerator = estimatedValues.GetEnumerator();
     90    public static double Calculate(IEnumerable<double> startValues, IEnumerable<IEnumerable<double>> actualContinuations, IEnumerable<IEnumerable<double>> predictedContinuations, out OnlineCalculatorError errorState) {
     91      IEnumerator<double> startValueEnumerator = startValues.GetEnumerator();
     92      IEnumerator<IEnumerable<double>> actualContinuationsEnumerator = actualContinuations.GetEnumerator();
     93      IEnumerator<IEnumerable<double>> predictedContinuationsEnumerator = predictedContinuations.GetEnumerator();
    8794      OnlineTheilsUStatisticCalculator calculator = new OnlineTheilsUStatisticCalculator();
    8895
    89       // add first element of time series as a reference point
    90       originalValuesEnumerator.MoveNext();
    91       estimatedValuesEnumerator.MoveNext();
    92       calculator.Add(originalValuesEnumerator.Current, estimatedValuesEnumerator.Current);
    93 
    94       // always move forward both enumerators (do not use short-circuit evaluation!)
    95       while (originalValuesEnumerator.MoveNext() & estimatedValuesEnumerator.MoveNext()) {
    96         double estimated = estimatedValuesEnumerator.Current;
    97         double original = originalValuesEnumerator.Current;
    98         calculator.Add(original, estimated);
     96      // always move forward all enumerators (do not use short-circuit evaluation!)
     97      while (startValueEnumerator.MoveNext() & actualContinuationsEnumerator.MoveNext() & predictedContinuationsEnumerator.MoveNext()) {
     98        calculator.Add(startValueEnumerator.Current, actualContinuationsEnumerator.Current, predictedContinuationsEnumerator.Current);
    9999        if (calculator.ErrorState != OnlineCalculatorError.None) break;
    100100      }
    101101
    102       // check if both enumerators are at the end to make sure both enumerations have the same length
     102      // check if all enumerators are at the end to make sure both enumerations have the same length
    103103      if (calculator.ErrorState == OnlineCalculatorError.None &&
    104           (estimatedValuesEnumerator.MoveNext() || originalValuesEnumerator.MoveNext())) {
    105         throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
     104          (startValueEnumerator.MoveNext() || actualContinuationsEnumerator.MoveNext() || predictedContinuationsEnumerator.MoveNext())) {
     105        throw new ArgumentException("Number of elements in startValues, actualContinuations and estimatedValues predictedContinuations doesn't match.");
    106106      } else {
    107107        errorState = calculator.ErrorState;
  • branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineWeightedDirectionalSymmetryCalculator.cs

    r6807 r7000  
    2222using System;
    2323using System.Collections.Generic;
     24using HeuristicLab.Common;
    2425
    2526
    2627namespace HeuristicLab.Problems.DataAnalysis {
    27   public class OnlineWeightedDirectionalSymmetryCalculator : IOnlineCalculator {
    28     private double prevEstimated;
    29     private double prevOriginal;
     28  public class OnlineWeightedDirectionalSymmetryCalculator : IOnlineTimeSeriesCalculator {
    3029    private int n;
    3130    private double correctSum;
     
    5251    }
    5352
    54     public void Add(double original, double estimated) {
    55       if (double.IsNaN(estimated) || double.IsInfinity(estimated) || double.IsNaN(original) || double.IsInfinity(original) || (errorState & OnlineCalculatorError.InvalidValueAdded) > 0) {
     53    public void Add(double startValue, IEnumerable<double> actualContinuation, IEnumerable<double> predictedContinuation) {
     54      if (double.IsNaN(startValue) || (errorState & OnlineCalculatorError.InvalidValueAdded) > 0) {
    5655        errorState = errorState | OnlineCalculatorError.InvalidValueAdded;
    57       } else if (n == 0) {
    58         prevOriginal = original;
    59         prevEstimated = estimated;
    60         n++;
    6156      } else {
    62         double err = Math.Abs(original - estimated);
    63         if ((original - prevOriginal) * (estimated - prevEstimated) >= 0.0) {
    64           correctSum += err;
     57        var actualEnumerator = actualContinuation.GetEnumerator();
     58        var predictedEnumerator = predictedContinuation.GetEnumerator();
     59        while (actualEnumerator.MoveNext() & predictedEnumerator.MoveNext() & errorState != OnlineCalculatorError.InvalidValueAdded) {
     60          double actual = actualEnumerator.Current;
     61          double predicted = predictedEnumerator.Current;
     62          if (double.IsNaN(actual) || double.IsNaN(predicted)) {
     63            errorState = errorState | OnlineCalculatorError.InvalidValueAdded;
     64          } else {
     65            double err = Math.Abs(actual - predicted);
     66            // count as correct only if the trend (positive/negative/no change) is predicted correctly
     67            if ((actual - startValue) * (predicted - startValue) > 0.0 ||
     68              (actual - startValue).IsAlmost(predicted - startValue)) {
     69              correctSum += err;
     70            } else {
     71              incorrectSum += err;
     72            }
     73            n++;
     74          }
     75        }
     76        // check if both enumerators are at the end to make sure both enumerations have the same length
     77        if (actualEnumerator.MoveNext() || predictedEnumerator.MoveNext()) {
     78          errorState = errorState | OnlineCalculatorError.InvalidValueAdded;
    6579        } else {
    66           incorrectSum += err;
     80          errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded); // n >= 1
    6781        }
    68         n++;
    69         errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded);        // n >= 1
    70         prevOriginal = original;
    71         prevEstimated = estimated;
    7282      }
    7383    }
     
    7787      correctSum = 0;
    7888      incorrectSum = 0;
    79       prevOriginal = double.NaN;
    80       prevEstimated = double.NaN;
    8189      errorState = OnlineCalculatorError.InsufficientElementsAdded;
    8290    }
    8391
    8492
    85     public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineCalculatorError errorState) {
    86       IEnumerator<double> firstEnumerator = first.GetEnumerator();
    87       IEnumerator<double> secondEnumerator = second.GetEnumerator();
    88       OnlineWeightedDirectionalSymmetryCalculator dsCalculator = new OnlineWeightedDirectionalSymmetryCalculator();
    89      
    90       // add first element of time series as a reference point
    91       firstEnumerator.MoveNext();
    92       secondEnumerator.MoveNext();
    93       dsCalculator.Add(firstEnumerator.Current, secondEnumerator.Current);
     93    public static double Calculate(IEnumerable<double> startValues, IEnumerable<IEnumerable<double>> actualContinuations, IEnumerable<IEnumerable<double>> predictedContinuations, out OnlineCalculatorError errorState) {
     94      IEnumerator<double> startValueEnumerator = startValues.GetEnumerator();
     95      IEnumerator<IEnumerable<double>> actualContinuationsEnumerator = actualContinuations.GetEnumerator();
     96      IEnumerator<IEnumerable<double>> predictedContinuationsEnumerator = predictedContinuations.GetEnumerator();
     97      OnlineWeightedDirectionalSymmetryCalculator calculator = new OnlineWeightedDirectionalSymmetryCalculator();
    9498
    95       // always move forward both enumerators (do not use short-circuit evaluation!)
    96       while (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) {
    97         double estimated = secondEnumerator.Current;
    98         double original = firstEnumerator.Current;
    99         dsCalculator.Add(original, estimated);
    100         if (dsCalculator.ErrorState != OnlineCalculatorError.None) break;
     99      // always move forward all enumerators (do not use short-circuit evaluation!)
     100      while (startValueEnumerator.MoveNext() & actualContinuationsEnumerator.MoveNext() & predictedContinuationsEnumerator.MoveNext()) {
     101        calculator.Add(startValueEnumerator.Current, actualContinuationsEnumerator.Current, predictedContinuationsEnumerator.Current);
     102        if (calculator.ErrorState != OnlineCalculatorError.None) break;
    101103      }
    102104
    103       // check if both enumerators are at the end to make sure both enumerations have the same length
    104       if (dsCalculator.ErrorState == OnlineCalculatorError.None &&
    105           (secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) {
    106         throw new ArgumentException("Number of elements in first and second enumeration doesn't match.");
     105      // check if all enumerators are at the end to make sure both enumerations have the same length
     106      if (calculator.ErrorState == OnlineCalculatorError.None &&
     107          (startValueEnumerator.MoveNext() || actualContinuationsEnumerator.MoveNext() || predictedContinuationsEnumerator.MoveNext())) {
     108        throw new ArgumentException("Number of elements in startValues, actualContinuations and estimatedValues predictedContinuations doesn't match.");
    107109      } else {
    108         errorState = dsCalculator.ErrorState;
    109         return dsCalculator.WeightedDirectionalSymmetry;
     110        errorState = calculator.ErrorState;
     111        return calculator.WeightedDirectionalSymmetry;
    110112      }
    111113    }
  • branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/TableFileParser.cs

    r6776 r7000  
    156156        } else if (OccurrencesOf(charCounts, ',') > 10) {
    157157          // no points and many commas
    158           int countCommaNonDigitPairs = 0;
    159           for (int i = 0; i < charsRead - 1; i++) {
    160             if (buffer[i] == ',' && !Char.IsDigit(buffer[i + 1])) {
    161               countCommaNonDigitPairs++;
     158          // count the number of tokens (chains of only digits and commas) that contain multiple comma characters
     159          int tokensWithMultipleCommas = 0;
     160          for (int i = 0; i < charsRead; i++) {
     161            int nCommas = 0;
     162            while (i < charsRead && (buffer[i] == ',' || Char.IsDigit(buffer[i]))) {
     163              if (buffer[i] == ',') nCommas++;
     164              i++;
    162165            }
    163           }
    164           if (countCommaNonDigitPairs > 10) {
     166            if (nCommas > 2) tokensWithMultipleCommas++;
     167          }
     168          if (tokensWithMultipleCommas > 1) {
    165169            // English format (only integer values) with ',' as separator
    166170            numberFormat = NumberFormatInfo.InvariantInfo;
Note: See TracChangeset for help on using the changeset viewer.