Changeset 6964 for trunk/sources
- Timestamp:
- 11/08/11 12:16:27 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/NormalizedGiniCalculator.cs
r6913 r6964 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 -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineAccuracyCalculator.cs
r6961 r6964 84 84 if (accuracyCalculator.ErrorState == OnlineCalculatorError.None && 85 85 (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) { 86 throw new ArgumentException("Number of elements in first and second enumerationdoesn't match.");86 throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match."); 87 87 } else { 88 88 errorState = accuracyCalculator.ErrorState; -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineCovarianceCalcualtor.cs
r5945 r6964 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 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineDirectionalSymmetryCalculator.cs
r6802 r6964 78 78 79 79 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();80 public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) { 81 IEnumerator<double> originalEnumerator = originalValues.GetEnumerator(); 82 IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator(); 83 83 OnlineDirectionalSymmetryCalculator dsCalculator = new OnlineDirectionalSymmetryCalculator(); 84 84 85 85 // add first element of time series as a reference point 86 firstEnumerator.MoveNext();87 secondEnumerator.MoveNext();88 dsCalculator.Add( firstEnumerator.Current, secondEnumerator.Current);86 originalEnumerator.MoveNext(); 87 estimatedEnumerator.MoveNext(); 88 dsCalculator.Add(originalEnumerator.Current, estimatedEnumerator.Current); 89 89 90 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;91 while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) { 92 double original = originalEnumerator.Current; 93 double estimated = estimatedEnumerator.Current; 94 94 dsCalculator.Add(original, estimated); 95 95 if (dsCalculator.ErrorState != OnlineCalculatorError.None) break; … … 98 98 // check if both enumerators are at the end to make sure both enumerations have the same length 99 99 if (dsCalculator.ErrorState == OnlineCalculatorError.None && 100 ( secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) {101 throw new ArgumentException("Number of elements in first and second enumerationdoesn't match.");100 (originalEnumerator.MoveNext() || estimatedEnumerator.MoveNext())) { 101 throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match."); 102 102 } else { 103 103 errorState = dsCalculator.ErrorState; -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanAbsoluteErrorCalculator.cs
r6961 r6964 81 81 if (maeCalculator.ErrorState == OnlineCalculatorError.None && 82 82 (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) { 83 throw new ArgumentException("Number of elements in first and second enumerationdoesn't match.");83 throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match."); 84 84 } else { 85 85 errorState = maeCalculator.ErrorState; -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanAbsolutePercentageErrorCalculator.cs
r6961 r6964 83 83 if (calculator.ErrorState == OnlineCalculatorError.None && 84 84 (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) { 85 throw new ArgumentException("Number of elements in first and second enumerationdoesn't match.");85 throw new ArgumentException("Number of elements in originalValues and second estimatedValues doesn't match."); 86 86 } else { 87 87 errorState = calculator.ErrorState; -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanSquaredErrorCalculator.cs
r6961 r6964 81 81 if (mseCalculator.ErrorState == OnlineCalculatorError.None && 82 82 (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) { 83 throw new ArgumentException("Number of elements in first and second enumerationdoesn't match.");83 throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match."); 84 84 } else { 85 85 errorState = mseCalculator.ErrorState; -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineNormalizedMeanSquaredErrorCalculator.cs
r6961 r6964 77 77 // always move forward both enumerators (do not use short-circuit evaluation!) 78 78 while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) { 79 double original = originalEnumerator.Current; 79 80 double estimated = estimatedEnumerator.Current; 80 double original = originalEnumerator.Current;81 81 normalizedMSECalculator.Add(original, estimated); 82 82 if (normalizedMSECalculator.ErrorState != OnlineCalculatorError.None) break; … … 86 86 if (normalizedMSECalculator.ErrorState == OnlineCalculatorError.None && 87 87 (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) { 88 throw new ArgumentException("Number of elements in first and secondenumeration doesn't match.");88 throw new ArgumentException("Number of elements in originalValues and estimatedValues enumeration doesn't match."); 89 89 } else { 90 90 errorState = normalizedMSECalculator.ErrorState; -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineTheilsUStatisticCalculator.cs
r6961 r6964 103 103 if (calculator.ErrorState == OnlineCalculatorError.None && 104 104 (estimatedValuesEnumerator.MoveNext() || originalValuesEnumerator.MoveNext())) { 105 throw new ArgumentException("Number of elements in first and second enumerationdoesn't match.");105 throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match."); 106 106 } else { 107 107 errorState = calculator.ErrorState; -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineWeightedDirectionalSymmetryCalculator.cs
r6807 r6964 83 83 84 84 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();85 public static double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) { 86 IEnumerator<double> originalEnumerator = originalValues.GetEnumerator(); 87 IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator(); 88 88 OnlineWeightedDirectionalSymmetryCalculator dsCalculator = new OnlineWeightedDirectionalSymmetryCalculator(); 89 89 90 90 // add first element of time series as a reference point 91 firstEnumerator.MoveNext();92 secondEnumerator.MoveNext();93 dsCalculator.Add( firstEnumerator.Current, secondEnumerator.Current);91 originalEnumerator.MoveNext(); 92 estimatedEnumerator.MoveNext(); 93 dsCalculator.Add(originalEnumerator.Current, estimatedEnumerator.Current); 94 94 95 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;96 while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) { 97 double original = originalEnumerator.Current; 98 double estimated = estimatedEnumerator.Current; 99 99 dsCalculator.Add(original, estimated); 100 100 if (dsCalculator.ErrorState != OnlineCalculatorError.None) break; … … 103 103 // check if both enumerators are at the end to make sure both enumerations have the same length 104 104 if (dsCalculator.ErrorState == OnlineCalculatorError.None && 105 ( secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) {106 throw new ArgumentException("Number of elements in first and second enumerationdoesn't match.");105 (originalEnumerator.MoveNext() || estimatedEnumerator.MoveNext())) { 106 throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match."); 107 107 } else { 108 108 errorState = dsCalculator.ErrorState;
Note: See TracChangeset
for help on using the changeset viewer.