- Timestamp:
- 11/16/11 15:07:36 (13 years ago)
- Location:
- branches/Benchmarking
- Files:
-
- 22 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/Benchmarking
- Property svn:mergeinfo changed
/trunk (added) merged: 6918-6919,6921-6923,6928-6930,6933,6935,6938-6939,6942,6944,6949-6954,6959,6961-6964,6974-6983,6985-6986,6993-6995,6997-6999
- Property svn:mergeinfo changed
-
branches/Benchmarking/sources
- Property svn:mergeinfo changed
/trunk/sources (added) merged: 6918-6919,6921-6923,6928-6930,6935,6938-6939,6942,6944,6949-6954,6959,6961-6964,6974-6983,6986,6993-6995,6997-6999
- Property svn:mergeinfo changed
-
branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis (added) merged: 6961,6963-6964,6974,6980,6982
- Property svn:mergeinfo changed
-
branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r6913 r7000 143 143 <Compile Include="Interfaces\Regression\IRegressionEnsembleSolution.cs" /> 144 144 <Compile Include="Implementation\Regression\RegressionSolutionBase.cs" /> 145 <Compile Include="Interfaces\TimeSeriesPrognosis\IOnlineTimeSeriesCalculator.cs" /> 145 146 <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisModel.cs" /> 146 147 <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisProblem.cs" /> -
branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs
r6666 r7000 201 201 202 202 public IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(Dataset dataset, IEnumerable<int> rows) { 203 if (!Model.Models.Any()) yield break; 203 204 var estimatedValuesEnumerators = (from model in Model.Models 204 205 select model.GetEstimatedClassValues(dataset, rows).GetEnumerator()) -
branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionBase.cs
r6913 r7000 84 84 85 85 OnlineCalculatorError errorState; 86 double trainingAccuracy = OnlineAccuracyCalculator.Calculate( estimatedTrainingClassValues, originalTrainingClassValues, out errorState);86 double trainingAccuracy = OnlineAccuracyCalculator.Calculate(originalTrainingClassValues, estimatedTrainingClassValues, out errorState); 87 87 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); 89 89 if (errorState != OnlineCalculatorError.None) testAccuracy = double.NaN; 90 90 -
branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolutionBase.cs
r6913 r7000 108 108 109 109 OnlineCalculatorError errorState; 110 double trainingMSE = OnlineMeanSquaredErrorCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);110 double trainingMSE = OnlineMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 111 111 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); 113 113 TestMeanSquaredError = errorState == OnlineCalculatorError.None ? testMSE : double.NaN; 114 114 115 double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);115 double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 116 116 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); 118 118 TestRSquared = errorState == OnlineCalculatorError.None ? testR2 : double.NaN; 119 119 -
branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs
r6666 r7000 64 64 private void AfterDeserialization() { 65 65 foreach (var model in Model.Models) { 66 IRegressionProblemData problemData = (IRegressionProblemData) 66 IRegressionProblemData problemData = (IRegressionProblemData)ProblemData.Clone(); 67 67 problemData.TrainingPartition.Start = trainingPartitions[model].Start; 68 68 problemData.TrainingPartition.End = trainingPartitions[model].End; … … 202 202 203 203 public IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(Dataset dataset, IEnumerable<int> rows) { 204 if (!Model.Models.Any()) yield break; 204 205 var estimatedValuesEnumerators = (from model in Model.Models 205 206 select model.GetEstimatedValues(dataset, rows).GetEnumerator()) -
branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolutionBase.cs
r6740 r7000 147 147 148 148 OnlineCalculatorError errorState; 149 double trainingMSE = OnlineMeanSquaredErrorCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);149 double trainingMSE = OnlineMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 150 150 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); 152 152 TestMeanSquaredError = errorState == OnlineCalculatorError.None ? testMSE : double.NaN; 153 153 154 double trainingMAE = OnlineMeanAbsoluteErrorCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);154 double trainingMAE = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 155 155 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); 157 157 TestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMAE : double.NaN; 158 158 159 double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);159 double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 160 160 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); 162 162 TestRSquared = errorState == OnlineCalculatorError.None ? testR2 : double.NaN; 163 163 164 double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);164 double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 165 165 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); 167 167 TestRelativeError = errorState == OnlineCalculatorError.None ? testRelError : double.NaN; 168 168 169 double trainingNMSE = OnlineNormalizedMeanSquaredErrorCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);169 double trainingNMSE = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 170 170 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); 172 172 TestNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? testNMSE : double.NaN; 173 173 } -
branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionBase.cs
r6802 r7000 40 40 private const string TrainingNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (training)"; 41 41 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)"; 48 48 49 49 public new ITimeSeriesPrognosisModel Model { … … 146 146 Add(new Result(TrainingNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the training partition", new DoubleValue())); 147 147 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 outputof the model on the training partition", new DoubleValue()));151 Add(new Result(TestWeightedDirectionalSymmetryResultName, "The weighted directional symmetry of the outputof the model on the test partition", new DoubleValue()));152 Add(new Result(TrainingTheilsUStatisticResultName, "The Theil's U statistic of the outputof the model on the training partition", new DoubleValue()));153 Add(new Result(TestTheilsUStatisticResultName, "The Theil's U statistic of the outputof 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())); 154 154 } 155 155 … … 166 166 167 167 OnlineCalculatorError errorState; 168 double trainingMse = OnlineMeanSquaredErrorCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);168 double trainingMse = OnlineMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 169 169 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); 171 171 TestMeanSquaredError = errorState == OnlineCalculatorError.None ? testMse : double.NaN; 172 172 173 double trainingMae = OnlineMeanAbsoluteErrorCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);173 double trainingMae = OnlineMeanAbsoluteErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 174 174 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); 176 176 TestMeanAbsoluteError = errorState == OnlineCalculatorError.None ? testMae : double.NaN; 177 177 178 double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);178 double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 179 179 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); 181 181 TestRSquared = errorState == OnlineCalculatorError.None ? testR2 : double.NaN; 182 182 183 double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);183 double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 184 184 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); 186 186 TestRelativeError = errorState == OnlineCalculatorError.None ? testRelError : double.NaN; 187 187 188 double trainingNmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);188 double trainingNmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(originalTrainingValues, estimatedTrainingValues, out errorState); 189 189 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); 191 191 TestNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? testNmse : double.NaN; 192 192 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); 194 210 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); 196 212 TestDirectionalSymmetry = errorState == OnlineCalculatorError.None ? testDirectionalSymmetry : double.NaN; 197 213 198 double trainingWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);214 double trainingWeightedDirectionalSymmetry = OnlineWeightedDirectionalSymmetryCalculator.Calculate(startTrainingValues, actualContinuationsTraining, predictedContinuationsTraining, out errorState); 199 215 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); 201 217 TestWeightedDirectionalSymmetry = errorState == OnlineCalculatorError.None ? testWeightedDirectionalSymmetry : double.NaN; 202 218 203 double trainingTheilsU = OnlineTheilsUStatisticCalculator.Calculate( estimatedTrainingValues, originalTrainingValues, out errorState);219 double trainingTheilsU = OnlineTheilsUStatisticCalculator.Calculate(startTrainingValues, actualContinuationsTraining, predictedContinuationsTraining, out errorState); 204 220 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); 206 222 TestTheilsUStatistic = errorState == OnlineCalculatorError.None ? testTheilsU : double.NaN; 207 208 209 223 } 210 224 } -
branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/NormalizedGiniCalculator.cs
r6913 r7000 28 28 public class NormalizedGiniCalculator { 29 29 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."); 33 35 } 34 double oe = Gini(original , estimated, out errorState);36 double oe = Gini(originalValuesArr, estimatedValuesArr, out errorState); 35 37 if (errorState != OnlineCalculatorError.None) return double.NaN; 36 38 37 return oe / (Gini(original , original, out errorState));39 return oe / (Gini(originalValuesArr, estimatedValuesArr, out errorState)); 38 40 } 39 41 -
branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineAccuracyCalculator.cs
r5945 r7000 68 68 #endregion 69 69 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(); 73 73 OnlineAccuracyCalculator accuracyCalculator = new OnlineAccuracyCalculator(); 74 74 75 75 // 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; 79 79 accuracyCalculator.Add(original, estimated); 80 80 if (accuracyCalculator.ErrorState != OnlineCalculatorError.None) break; … … 83 83 // check if both enumerators are at the end to make sure both enumerations have the same length 84 84 if (accuracyCalculator.ErrorState == OnlineCalculatorError.None && 85 ( secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) {86 throw new ArgumentException("Number of elements in first and second enumerationdoesn't match.");85 (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) { 86 throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match."); 87 87 } else { 88 88 errorState = accuracyCalculator.ErrorState; -
branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineCovarianceCalcualtor.cs
r5945 r7000 26 26 public class OnlineCovarianceCalculator : IOnlineCalculator { 27 27 28 private double originalMean, estimatedMean, Cn;28 private double xMean, yMean, Cn; 29 29 private int n; 30 30 public double Covariance { … … 49 49 n = 0; 50 50 Cn = 0.0; 51 originalMean = 0.0;52 estimatedMean = 0.0;51 xMean = 0.0; 52 yMean = 0.0; 53 53 errorState = OnlineCalculatorError.InsufficientElementsAdded; 54 54 } 55 55 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) { 58 58 errorState = errorState | OnlineCalculatorError.InvalidValueAdded; 59 59 } else { … … 62 62 63 63 // 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; 67 67 68 68 // 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)) 70 70 } 71 71 } … … 79 79 // always move forward both enumerators (do not use short-circuit evaluation!) 80 80 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); 84 84 if (covarianceCalculator.ErrorState != OnlineCalculatorError.None) break; 85 85 } -
branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineDirectionalSymmetryCalculator.cs
r6802 r7000 22 22 using System; 23 23 using System.Collections.Generic; 24 using HeuristicLab.Common; 24 25 25 26 26 27 namespace HeuristicLab.Problems.DataAnalysis { 27 public class OnlineDirectionalSymmetryCalculator : IOnlineCalculator { 28 private double prevEstimated; 29 private double prevOriginal; 28 public class OnlineDirectionalSymmetryCalculator : IOnlineTimeSeriesCalculator { 30 29 private int n; 31 30 private int nCorrect; … … 33 32 public double DirectionalSymmetry { 34 33 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; 37 36 } 38 37 } … … 51 50 } 52 51 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) { 55 54 errorState = errorState | OnlineCalculatorError.InvalidValueAdded; 56 } else if (n == 0) {57 prevOriginal = original;58 prevEstimated = estimated;59 n++;60 55 } 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 } 63 74 } 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 } 68 81 } 69 82 } … … 72 85 n = 0; 73 86 nCorrect = 0; 74 prevOriginal = double.NaN;75 prevEstimated = double.NaN;76 87 errorState = OnlineCalculatorError.InsufficientElementsAdded; 77 88 } 78 89 79 90 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(); 83 95 OnlineDirectionalSymmetryCalculator dsCalculator = new OnlineDirectionalSymmetryCalculator(); 84 96 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); 95 100 if (dsCalculator.ErrorState != OnlineCalculatorError.None) break; 96 101 } 97 102 98 // check if bothenumerators are at the end to make sure both enumerations have the same length103 // check if all enumerators are at the end to make sure both enumerations have the same length 99 104 if (dsCalculator.ErrorState == OnlineCalculatorError.None && 100 (s econdEnumerator.MoveNext() || firstEnumerator.MoveNext())) {101 throw new ArgumentException("Number of elements in first and second enumerationdoesn'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."); 102 107 } else { 103 108 errorState = dsCalculator.ErrorState; -
branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanAbsoluteErrorCalculator.cs
r6643 r7000 65 65 #endregion 66 66 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(); 70 70 OnlineMeanAbsoluteErrorCalculator maeCalculator = new OnlineMeanAbsoluteErrorCalculator(); 71 71 72 72 // 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; 76 76 maeCalculator.Add(original, estimated); 77 77 if (maeCalculator.ErrorState != OnlineCalculatorError.None) break; … … 80 80 // check if both enumerators are at the end to make sure both enumerations have the same length 81 81 if (maeCalculator.ErrorState == OnlineCalculatorError.None && 82 ( secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) {83 throw new ArgumentException("Number of elements in first and second enumerationdoesn't match.");82 (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) { 83 throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match."); 84 84 } else { 85 85 errorState = maeCalculator.ErrorState; -
branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanAbsolutePercentageErrorCalculator.cs
r5945 r7000 67 67 #endregion 68 68 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(); 72 72 OnlineMeanAbsolutePercentageErrorCalculator calculator = new OnlineMeanAbsolutePercentageErrorCalculator(); 73 73 74 74 // 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; 78 78 calculator.Add(original, estimated); 79 79 if (calculator.ErrorState != OnlineCalculatorError.None) break; … … 82 82 // check if both enumerators are at the end to make sure both enumerations have the same length 83 83 if (calculator.ErrorState == OnlineCalculatorError.None && 84 ( secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) {85 throw new ArgumentException("Number of elements in first and second enumerationdoesn't match.");84 (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) { 85 throw new ArgumentException("Number of elements in originalValues and second estimatedValues doesn't match."); 86 86 } else { 87 87 errorState = calculator.ErrorState; -
branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanSquaredErrorCalculator.cs
r5945 r7000 65 65 #endregion 66 66 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(); 70 70 OnlineMeanSquaredErrorCalculator mseCalculator = new OnlineMeanSquaredErrorCalculator(); 71 71 72 72 // 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; 76 76 mseCalculator.Add(original, estimated); 77 77 if (mseCalculator.ErrorState != OnlineCalculatorError.None) break; … … 80 80 // check if both enumerators are at the end to make sure both enumerations have the same length 81 81 if (mseCalculator.ErrorState == OnlineCalculatorError.None && 82 ( secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) {83 throw new ArgumentException("Number of elements in first and second enumerationdoesn't match.");82 (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) { 83 throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match."); 84 84 } else { 85 85 errorState = mseCalculator.ErrorState; -
branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineNormalizedMeanSquaredErrorCalculator.cs
r5962 r7000 63 63 #endregion 64 64 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(); 68 68 OnlineNormalizedMeanSquaredErrorCalculator normalizedMSECalculator = new OnlineNormalizedMeanSquaredErrorCalculator(); 69 69 70 70 //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; 74 74 normalizedMSECalculator.Add(original, estimated); 75 75 } 76 76 77 77 // 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; 81 81 normalizedMSECalculator.Add(original, estimated); 82 82 if (normalizedMSECalculator.ErrorState != OnlineCalculatorError.None) break; … … 85 85 // check if both enumerators are at the end to make sure both enumerations have the same length 86 86 if (normalizedMSECalculator.ErrorState == OnlineCalculatorError.None && 87 ( secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) {88 throw new ArgumentException("Number of elements in first and secondenumeration doesn't match.");87 (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) { 88 throw new ArgumentException("Number of elements in originalValues and estimatedValues enumeration doesn't match."); 89 89 } else { 90 90 errorState = normalizedMSECalculator.ErrorState; -
branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlinePearsonsRSquaredCalculator.cs
r5945 r7000 74 74 // always move forward both enumerators (do not use short-circuit evaluation!) 75 75 while (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) { 76 double original = firstEnumerator.Current; 76 77 double estimated = secondEnumerator.Current; 77 double original = firstEnumerator.Current;78 78 rSquaredCalculator.Add(original, estimated); 79 79 if (rSquaredCalculator.ErrorState != OnlineCalculatorError.None) break; -
branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineTheilsUStatisticCalculator.cs
r6807 r7000 22 22 using System; 23 23 using System.Collections.Generic; 24 using HeuristicLab.Common; 24 25 25 26 namespace HeuristicLab.Problems.DataAnalysis { 26 public class OnlineTheilsUStatisticCalculator : IOnline Calculator {27 public class OnlineTheilsUStatisticCalculator : IOnlineTimeSeriesCalculator { 27 28 private OnlineMeanAndVarianceCalculator squaredErrorMeanCalculator; 28 29 private OnlineMeanAndVarianceCalculator unbiasedEstimatorMeanCalculator; 29 private double prevOriginal;30 private int n;31 30 32 31 public double TheilsUStatistic { … … 52 51 } 53 52 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) { 56 55 errorState = errorState | OnlineCalculatorError.InvalidValueAdded; 57 } else if (n == 0) {58 prevOriginal = original;59 n++;60 56 } 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); 64 68 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 } 70 79 } 71 80 } 72 81 73 74 82 public void Reset() { 75 prevOriginal = double.NaN;76 n = 0;77 83 squaredErrorMeanCalculator.Reset(); 78 84 unbiasedEstimatorMeanCalculator.Reset(); … … 82 88 #endregion 83 89 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(); 87 94 OnlineTheilsUStatisticCalculator calculator = new OnlineTheilsUStatisticCalculator(); 88 95 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); 99 99 if (calculator.ErrorState != OnlineCalculatorError.None) break; 100 100 } 101 101 102 // check if bothenumerators are at the end to make sure both enumerations have the same length102 // check if all enumerators are at the end to make sure both enumerations have the same length 103 103 if (calculator.ErrorState == OnlineCalculatorError.None && 104 ( estimatedValuesEnumerator.MoveNext() || originalValuesEnumerator.MoveNext())) {105 throw new ArgumentException("Number of elements in first and second enumerationdoesn'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."); 106 106 } else { 107 107 errorState = calculator.ErrorState; -
branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineWeightedDirectionalSymmetryCalculator.cs
r6807 r7000 22 22 using System; 23 23 using System.Collections.Generic; 24 using HeuristicLab.Common; 24 25 25 26 26 27 namespace HeuristicLab.Problems.DataAnalysis { 27 public class OnlineWeightedDirectionalSymmetryCalculator : IOnlineCalculator { 28 private double prevEstimated; 29 private double prevOriginal; 28 public class OnlineWeightedDirectionalSymmetryCalculator : IOnlineTimeSeriesCalculator { 30 29 private int n; 31 30 private double correctSum; … … 52 51 } 53 52 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) { 56 55 errorState = errorState | OnlineCalculatorError.InvalidValueAdded; 57 } else if (n == 0) {58 prevOriginal = original;59 prevEstimated = estimated;60 n++;61 56 } 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; 65 79 } else { 66 incorrectSum += err;80 errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded); // n >= 1 67 81 } 68 n++;69 errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded); // n >= 170 prevOriginal = original;71 prevEstimated = estimated;72 82 } 73 83 } … … 77 87 correctSum = 0; 78 88 incorrectSum = 0; 79 prevOriginal = double.NaN;80 prevEstimated = double.NaN;81 89 errorState = OnlineCalculatorError.InsufficientElementsAdded; 82 90 } 83 91 84 92 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(); 94 98 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; 101 103 } 102 104 103 // check if bothenumerators are at the end to make sure both enumerations have the same length104 if ( dsCalculator.ErrorState == OnlineCalculatorError.None &&105 (s econdEnumerator.MoveNext() || firstEnumerator.MoveNext())) {106 throw new ArgumentException("Number of elements in first and second enumerationdoesn'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."); 107 109 } else { 108 errorState = dsCalculator.ErrorState;109 return dsCalculator.WeightedDirectionalSymmetry;110 errorState = calculator.ErrorState; 111 return calculator.WeightedDirectionalSymmetry; 110 112 } 111 113 } -
branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis/3.4/TableFileParser.cs
r6776 r7000 156 156 } else if (OccurrencesOf(charCounts, ',') > 10) { 157 157 // 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++; 162 165 } 163 } 164 if (countCommaNonDigitPairs > 10) { 166 if (nCommas > 2) tokensWithMultipleCommas++; 167 } 168 if (tokensWithMultipleCommas > 1) { 165 169 // English format (only integer values) with ',' as separator 166 170 numberFormat = NumberFormatInfo.InvariantInfo;
Note: See TracChangeset
for help on using the changeset viewer.