Changeset 5942 for trunk/sources/HeuristicLab.Problems.DataAnalysis
- Timestamp:
- 04/04/11 15:38:16 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4
- Files:
-
- 7 edited
- 7 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r5809 r5942 130 130 <Compile Include="Interfaces\Clustering\IClusteringProblemData.cs" /> 131 131 <Compile Include="Interfaces\Clustering\IClusteringSolution.cs" /> 132 <Compile Include="OnlineEvaluators\OnlineAccuracy Evaluator.cs" />132 <Compile Include="OnlineEvaluators\OnlineAccuracyCalculator.cs" /> 133 133 <Compile Include="Implementation\Regression\RegressionProblemData.cs" /> 134 134 <Compile Include="Implementation\DataAnalysisProblemData.cs" /> … … 142 142 <Compile Include="Interfaces\IDataAnalysisProblemData.cs" /> 143 143 <Compile Include="Interfaces\IDataAnalysisSolution.cs" /> 144 <Compile Include="Interfaces\IOnline Evaluator.cs" />144 <Compile Include="Interfaces\IOnlineCalculator.cs" /> 145 145 <Compile Include="Interfaces\Regression\IRegressionModel.cs" /> 146 146 <Compile Include="Interfaces\Regression\IRegressionProblem.cs" /> 147 147 <Compile Include="Interfaces\Regression\IRegressionProblemData.cs" /> 148 148 <Compile Include="Interfaces\Regression\IRegressionSolution.cs" /> 149 <Compile Include="OnlineEvaluators\OnlineCovariance Evaluator.cs" />150 <Compile Include="OnlineEvaluators\OnlineMeanAbsolutePercentageError Evaluator.cs" />149 <Compile Include="OnlineEvaluators\OnlineCovarianceCalcualtor.cs" /> 150 <Compile Include="OnlineEvaluators\OnlineMeanAbsolutePercentageErrorCalculator.cs" /> 151 151 <Compile Include="OnlineEvaluators\OnlineMeanAndVarianceCalculator.cs" /> 152 <Compile Include="OnlineEvaluators\OnlineMeanSquaredError Evaluator.cs" />153 <Compile Include="OnlineEvaluators\OnlineNormalizedMeanSquaredError Evaluator.cs" />154 <Compile Include="OnlineEvaluators\OnlinePearsonsRSquared Evaluator.cs" />152 <Compile Include="OnlineEvaluators\OnlineMeanSquaredErrorCalculator.cs" /> 153 <Compile Include="OnlineEvaluators\OnlineNormalizedMeanSquaredErrorCalculator.cs" /> 154 <Compile Include="OnlineEvaluators\OnlinePearsonsRSquaredCalculator.cs" /> 155 155 <Compile Include="Implementation\Regression\RegressionSolution.cs" /> 156 156 <Compile Include="TableFileParser.cs" /> -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolution.cs
r5894 r5942 85 85 IEnumerable<double> originalTestClassValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TestIndizes); 86 86 87 Online EvaluatorError errorState;88 double trainingAccuracy = OnlineAccuracy Evaluator.Calculate(estimatedTrainingClassValues, originalTrainingClassValues, out errorState);89 if (errorState != Online EvaluatorError.None) trainingAccuracy = double.NaN;90 double testAccuracy = OnlineAccuracy Evaluator.Calculate(estimatedTestClassValues, originalTestClassValues, out errorState);91 if (errorState != Online EvaluatorError.None) testAccuracy = double.NaN;87 OnlineCalculatorError errorState; 88 double trainingAccuracy = OnlineAccuracyCalculator.Calculate(estimatedTrainingClassValues, originalTrainingClassValues, out errorState); 89 if (errorState != OnlineCalculatorError.None) trainingAccuracy = double.NaN; 90 double testAccuracy = OnlineAccuracyCalculator.Calculate(estimatedTestClassValues, originalTestClassValues, out errorState); 91 if (errorState != OnlineCalculatorError.None) testAccuracy = double.NaN; 92 92 93 93 TrainingAccuracy = trainingAccuracy; -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolution.cs
r5894 r5942 105 105 IEnumerable<double> originalTestValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TestIndizes); 106 106 107 Online EvaluatorError errorState;108 double trainingMSE = OnlineMeanSquaredError Evaluator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);109 TrainingMeanSquaredError = errorState == Online EvaluatorError.None ? trainingMSE : double.NaN;110 double testMSE = OnlineMeanSquaredError Evaluator.Calculate(estimatedTestValues, originalTestValues, out errorState);111 TestMeanSquaredError = errorState == Online EvaluatorError.None ? testMSE : double.NaN;107 OnlineCalculatorError errorState; 108 double trainingMSE = OnlineMeanSquaredErrorCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState); 109 TrainingMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingMSE : double.NaN; 110 double testMSE = OnlineMeanSquaredErrorCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState); 111 TestMeanSquaredError = errorState == OnlineCalculatorError.None ? testMSE : double.NaN; 112 112 113 double trainingR2 = OnlinePearsonsRSquared Evaluator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);114 TrainingRSquared = errorState == Online EvaluatorError.None ? trainingR2 : double.NaN;115 double testR2 = OnlinePearsonsRSquared Evaluator.Calculate(estimatedTestValues, originalTestValues, out errorState);116 TestRSquared = errorState == Online EvaluatorError.None ? testR2 : double.NaN;113 double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState); 114 TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR2 : double.NaN; 115 double testR2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState); 116 TestRSquared = errorState == OnlineCalculatorError.None ? testR2 : double.NaN; 117 117 } 118 118 -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ThresholdCalculators/NormalDistributionCutPointsThresholdCalculator.cs
r5894 r5942 64 64 double classValue = group.Key; 65 65 double mean, variance; 66 Online EvaluatorError meanErrorState, varianceErrorState;66 OnlineCalculatorError meanErrorState, varianceErrorState; 67 67 OnlineMeanAndVarianceCalculator.Calculate(estimatedClassValues, out mean, out variance, out meanErrorState, out varianceErrorState); 68 68 69 if (meanErrorState == Online EvaluatorError.None && varianceErrorState == OnlineEvaluatorError.None) {69 if (meanErrorState == OnlineCalculatorError.None && varianceErrorState == OnlineCalculatorError.None) { 70 70 classMean[classValue] = mean; 71 71 classStdDev[classValue] = Math.Sqrt(variance); -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolution.cs
r5894 r5942 40 40 private const string TrainingRelativeErrorResultName = "Average relative error (training)"; 41 41 private const string TestRelativeErrorResultName = "Average relative error (test)"; 42 private const string TrainingNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (training)"; 43 private const string TestNormalizedMeanSquaredErrorResultName = "Normalized mean squared error (test)"; 42 44 43 45 public new IRegressionModel Model { … … 81 83 } 82 84 85 public double TrainingNormalizedMeanSquaredError { 86 get { return ((DoubleValue)this[TrainingNormalizedMeanSquaredErrorResultName].Value).Value; } 87 private set { ((DoubleValue)this[TrainingNormalizedMeanSquaredErrorResultName].Value).Value = value; } 88 } 89 90 public double TestNormalizedMeanSquaredError { 91 get { return ((DoubleValue)this[TestNormalizedMeanSquaredErrorResultName].Value).Value; } 92 private set { ((DoubleValue)this[TestNormalizedMeanSquaredErrorResultName].Value).Value = value; } 93 } 94 83 95 84 96 [StorableConstructor] … … 95 107 Add(new Result(TrainingRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the training partition", new PercentValue())); 96 108 Add(new Result(TestRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the test partition", new PercentValue())); 109 Add(new Result(TrainingNormalizedMeanSquaredErrorResultName, "", new DoubleValue())); 110 Add(new Result(TestNormalizedMeanSquaredErrorResultName, "", new DoubleValue())); 97 111 98 112 RecalculateResults(); … … 114 128 IEnumerable<double> originalTestValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TestIndizes); 115 129 116 Online EvaluatorError errorState;117 double trainingMSE = OnlineMeanSquaredError Evaluator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);118 TrainingMeanSquaredError = errorState == Online EvaluatorError.None ? trainingMSE : double.NaN;119 double testMSE = OnlineMeanSquaredError Evaluator.Calculate(estimatedTestValues, originalTestValues, out errorState);120 TestMeanSquaredError = errorState == Online EvaluatorError.None ? testMSE : double.NaN;130 OnlineCalculatorError errorState; 131 double trainingMSE = OnlineMeanSquaredErrorCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState); 132 TrainingMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingMSE : double.NaN; 133 double testMSE = OnlineMeanSquaredErrorCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState); 134 TestMeanSquaredError = errorState == OnlineCalculatorError.None ? testMSE : double.NaN; 121 135 122 double trainingR2 = OnlinePearsonsRSquared Evaluator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState);123 TrainingRSquared = errorState == Online EvaluatorError.None ? trainingR2 : double.NaN;124 double testR2 = OnlinePearsonsRSquared Evaluator.Calculate(estimatedTestValues, originalTestValues, out errorState);125 TestRSquared = errorState == Online EvaluatorError.None ? testR2 : double.NaN;136 double trainingR2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState); 137 TrainingRSquared = errorState == OnlineCalculatorError.None ? trainingR2 : double.NaN; 138 double testR2 = OnlinePearsonsRSquaredCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState); 139 TestRSquared = errorState == OnlineCalculatorError.None ? testR2 : double.NaN; 126 140 127 double trainingRelError = OnlineMeanAbsolutePercentageErrorEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState); 128 TrainingRelativeError = errorState == OnlineEvaluatorError.None ? trainingRelError : double.NaN; 129 double testRelError = OnlineMeanAbsolutePercentageErrorEvaluator.Calculate(estimatedTestValues, originalTestValues, out errorState); 130 TestRelativeError = errorState == OnlineEvaluatorError.None ? testRelError : double.NaN; 141 double trainingRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState); 142 TrainingRelativeError = errorState == OnlineCalculatorError.None ? trainingRelError : double.NaN; 143 double testRelError = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState); 144 TestRelativeError = errorState == OnlineCalculatorError.None ? testRelError : double.NaN; 145 146 double trainingNMSE = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState); 147 TrainingNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? trainingNMSE : double.NaN; 148 double testNMSE = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(estimatedTestValues, originalTestValues, out errorState); 149 TestNormalizedMeanSquaredError = errorState == OnlineCalculatorError.None ? testNMSE : double.NaN; 131 150 } 132 151 -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IOnlineCalculator.cs
r5941 r5942 24 24 namespace HeuristicLab.Problems.DataAnalysis { 25 25 [Flags] 26 public enum Online EvaluatorError {26 public enum OnlineCalculatorError { 27 27 /// <summary> 28 28 /// No error occurred … … 38 38 InsufficientElementsAdded = 2 39 39 } 40 public interface IOnline Evaluator {41 Online EvaluatorError ErrorState { get; }40 public interface IOnlineCalculator { 41 OnlineCalculatorError ErrorState { get; } 42 42 double Value { get; } 43 43 void Reset(); -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineAccuracyCalculator.cs
r5941 r5942 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; 24 using System.Collections.Generic;25 25 26 26 namespace HeuristicLab.Problems.DataAnalysis { 27 public class OnlineAccuracy Evaluator : IOnlineEvaluator {27 public class OnlineAccuracyCalculator : IOnlineCalculator { 28 28 29 29 private int correctlyClassified; … … 35 35 } 36 36 37 public OnlineAccuracy Evaluator() {37 public OnlineAccuracyCalculator() { 38 38 Reset(); 39 39 } 40 40 41 #region IOnline Evaluator Members42 private Online EvaluatorError errorState;43 public Online EvaluatorError ErrorState {41 #region IOnlineCalculator Members 42 private OnlineCalculatorError errorState; 43 public OnlineCalculatorError ErrorState { 44 44 get { return errorState; } 45 45 } … … 50 50 n = 0; 51 51 correctlyClassified = 0; 52 errorState = Online EvaluatorError.InsufficientElementsAdded;52 errorState = OnlineCalculatorError.InsufficientElementsAdded; 53 53 } 54 54 … … 63 63 correctlyClassified++; 64 64 } 65 errorState = Online EvaluatorError.None; // number of (non-NaN) samples >= 165 errorState = OnlineCalculatorError.None; // number of (non-NaN) samples >= 1 66 66 } 67 67 } 68 68 #endregion 69 69 70 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out Online EvaluatorError errorState) {70 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineCalculatorError errorState) { 71 71 IEnumerator<double> firstEnumerator = first.GetEnumerator(); 72 72 IEnumerator<double> secondEnumerator = second.GetEnumerator(); 73 OnlineAccuracy Evaluator accuracyEvaluator = new OnlineAccuracyEvaluator();73 OnlineAccuracyCalculator accuracyCalculator = new OnlineAccuracyCalculator(); 74 74 75 75 // always move forward both enumerators (do not use short-circuit evaluation!) … … 77 77 double estimated = secondEnumerator.Current; 78 78 double original = firstEnumerator.Current; 79 accuracy Evaluator.Add(original, estimated);79 accuracyCalculator.Add(original, estimated); 80 80 } 81 81 … … 84 84 throw new ArgumentException("Number of elements in first and second enumeration doesn't match."); 85 85 } else { 86 errorState = accuracy Evaluator.ErrorState;87 return accuracy Evaluator.Accuracy;86 errorState = accuracyCalculator.ErrorState; 87 return accuracyCalculator.Accuracy; 88 88 } 89 89 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineCovarianceCalcualtor.cs
r5941 r5942 24 24 25 25 namespace HeuristicLab.Problems.DataAnalysis { 26 public class OnlineCovariance Evaluator : IOnlineEvaluator {26 public class OnlineCovarianceCalculator : IOnlineCalculator { 27 27 28 28 private double originalMean, estimatedMean, Cn; … … 34 34 } 35 35 36 public OnlineCovariance Evaluator() {36 public OnlineCovarianceCalculator() { 37 37 Reset(); 38 38 } 39 39 40 #region IOnline Evaluator Members41 private Online EvaluatorError errorState;42 public Online EvaluatorError ErrorState {40 #region IOnlineCalculator Members 41 private OnlineCalculatorError errorState; 42 public OnlineCalculatorError ErrorState { 43 43 get { return errorState; } 44 44 } … … 51 51 originalMean = 0.0; 52 52 estimatedMean = 0.0; 53 errorState = Online EvaluatorError.InsufficientElementsAdded;53 errorState = OnlineCalculatorError.InsufficientElementsAdded; 54 54 } 55 55 56 56 public void Add(double original, double estimated) { 57 if (double.IsNaN(estimated) || double.IsInfinity(estimated) || double.IsNaN(original) || double.IsInfinity(original) || (errorState & Online EvaluatorError.InvalidValueAdded) > 0) {58 errorState = errorState | Online EvaluatorError.InvalidValueAdded;57 if (double.IsNaN(estimated) || double.IsInfinity(estimated) || double.IsNaN(original) || double.IsInfinity(original) || (errorState & OnlineCalculatorError.InvalidValueAdded) > 0) { 58 errorState = errorState | OnlineCalculatorError.InvalidValueAdded; 59 59 } else { 60 60 n++; 61 errorState = errorState & (~Online EvaluatorError.InsufficientElementsAdded); // n >= 161 errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded); // n >= 1 62 62 63 63 // online calculation of tMean … … 72 72 #endregion 73 73 74 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out Online EvaluatorError errorState) {74 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineCalculatorError errorState) { 75 75 IEnumerator<double> firstEnumerator = first.GetEnumerator(); 76 76 IEnumerator<double> secondEnumerator = second.GetEnumerator(); 77 OnlineCovariance Evaluator covarianceEvaluator = new OnlineCovarianceEvaluator();77 OnlineCovarianceCalculator covarianceCalculator = new OnlineCovarianceCalculator(); 78 78 79 79 // always move forward both enumerators (do not use short-circuit evaluation!) … … 81 81 double estimated = secondEnumerator.Current; 82 82 double original = firstEnumerator.Current; 83 covariance Evaluator.Add(original, estimated);83 covarianceCalculator.Add(original, estimated); 84 84 } 85 85 … … 88 88 throw new ArgumentException("Number of elements in first and second enumeration doesn't match."); 89 89 } else { 90 errorState = covariance Evaluator.ErrorState;91 return covariance Evaluator.Covariance;90 errorState = covarianceCalculator.ErrorState; 91 return covarianceCalculator.Covariance; 92 92 } 93 93 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineLinearScalingParameterCalculator.cs
r5894 r5942 44 44 return 1; 45 45 else 46 return originalTargetCovariance Evaluator.Covariance / originalMeanAndVarianceCalculator.PopulationVariance;46 return originalTargetCovarianceCalculator.Covariance / originalMeanAndVarianceCalculator.PopulationVariance; 47 47 } 48 48 } 49 49 50 public Online EvaluatorError ErrorState {50 public OnlineCalculatorError ErrorState { 51 51 get { 52 52 return targetMeanCalculator.MeanErrorState | originalMeanAndVarianceCalculator.MeanErrorState | 53 originalMeanAndVarianceCalculator.PopulationVarianceErrorState | originalTargetCovariance Evaluator.ErrorState;53 originalMeanAndVarianceCalculator.PopulationVarianceErrorState | originalTargetCovarianceCalculator.ErrorState; 54 54 } 55 55 } … … 58 58 private OnlineMeanAndVarianceCalculator targetMeanCalculator; 59 59 private OnlineMeanAndVarianceCalculator originalMeanAndVarianceCalculator; 60 private OnlineCovariance Evaluator originalTargetCovarianceEvaluator;60 private OnlineCovarianceCalculator originalTargetCovarianceCalculator; 61 61 62 62 public OnlineLinearScalingParameterCalculator() { 63 63 targetMeanCalculator = new OnlineMeanAndVarianceCalculator(); 64 64 originalMeanAndVarianceCalculator = new OnlineMeanAndVarianceCalculator(); 65 originalTargetCovariance Evaluator = new OnlineCovarianceEvaluator();65 originalTargetCovarianceCalculator = new OnlineCovarianceCalculator(); 66 66 Reset(); 67 67 } … … 71 71 targetMeanCalculator.Reset(); 72 72 originalMeanAndVarianceCalculator.Reset(); 73 originalTargetCovariance Evaluator.Reset();73 originalTargetCovarianceCalculator.Reset(); 74 74 } 75 75 … … 83 83 targetMeanCalculator.Add(target); 84 84 originalMeanAndVarianceCalculator.Add(original); 85 originalTargetCovariance Evaluator.Add(original, target);85 originalTargetCovarianceCalculator.Add(original, target); 86 86 87 87 cnt++; … … 97 97 /// <param name="beta">Multiplicative factor for the linear scaling</param> 98 98 /// <param name="errorState">Flag that indicates if errors occurred in the calculation of the linea scaling parameters.</param> 99 public static void Calculate(IEnumerable<double> original, IEnumerable<double> target, out double alpha, out double beta, out Online EvaluatorError errorState) {99 public static void Calculate(IEnumerable<double> original, IEnumerable<double> target, out double alpha, out double beta, out OnlineCalculatorError errorState) { 100 100 OnlineLinearScalingParameterCalculator calculator = new OnlineLinearScalingParameterCalculator(); 101 101 IEnumerator<double> originalEnumerator = original.GetEnumerator(); -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineMeanAbsolutePercentageErrorCalculator.cs
r5941 r5942 25 25 26 26 namespace HeuristicLab.Problems.DataAnalysis { 27 public class OnlineMeanAbsolutePercentageError Evaluator : IOnlineEvaluator {27 public class OnlineMeanAbsolutePercentageErrorCalculator : IOnlineCalculator { 28 28 29 29 private double sre; … … 35 35 } 36 36 37 public OnlineMeanAbsolutePercentageError Evaluator() {37 public OnlineMeanAbsolutePercentageErrorCalculator() { 38 38 Reset(); 39 39 } 40 40 41 #region IOnline Evaluator Members42 private Online EvaluatorError errorState;43 public Online EvaluatorError ErrorState {41 #region IOnlineCalculator Members 42 private OnlineCalculatorError errorState; 43 public OnlineCalculatorError ErrorState { 44 44 get { return errorState; } 45 45 } … … 50 50 n = 0; 51 51 sre = 0.0; 52 errorState = Online EvaluatorError.InsufficientElementsAdded;52 errorState = OnlineCalculatorError.InsufficientElementsAdded; 53 53 } 54 54 … … 57 57 double.IsNaN(original) || double.IsInfinity(original) || 58 58 original.IsAlmost(0.0)) { 59 errorState = errorState | Online EvaluatorError.InvalidValueAdded;59 errorState = errorState | OnlineCalculatorError.InvalidValueAdded; 60 60 } else { 61 61 sre += Math.Abs((estimated - original) / original); 62 62 n++; 63 errorState = errorState & (~Online EvaluatorError.InsufficientElementsAdded); // n >= 163 errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded); // n >= 1 64 64 } 65 65 } … … 67 67 #endregion 68 68 69 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out Online EvaluatorError errorState) {69 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineCalculatorError errorState) { 70 70 IEnumerator<double> firstEnumerator = first.GetEnumerator(); 71 71 IEnumerator<double> secondEnumerator = second.GetEnumerator(); 72 OnlineMeanAbsolutePercentageError Evaluator evaluator = new OnlineMeanAbsolutePercentageErrorEvaluator();72 OnlineMeanAbsolutePercentageErrorCalculator calculator = new OnlineMeanAbsolutePercentageErrorCalculator(); 73 73 74 74 // always move forward both enumerators (do not use short-circuit evaluation!) … … 76 76 double estimated = secondEnumerator.Current; 77 77 double original = firstEnumerator.Current; 78 evaluator.Add(original, estimated);78 calculator.Add(original, estimated); 79 79 } 80 80 … … 83 83 throw new ArgumentException("Number of elements in first and second enumeration doesn't match."); 84 84 } else { 85 errorState = evaluator.ErrorState;86 return evaluator.MeanAbsolutePercentageError;85 errorState = calculator.ErrorState; 86 return calculator.MeanAbsolutePercentageError; 87 87 } 88 88 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineMeanAndVarianceCalculator.cs
r5904 r5942 29 29 private int n; 30 30 31 private Online EvaluatorError varianceErrorState;32 public Online EvaluatorError VarianceErrorState {31 private OnlineCalculatorError varianceErrorState; 32 public OnlineCalculatorError VarianceErrorState { 33 33 get { return varianceErrorState; } 34 34 } … … 40 40 } 41 41 42 private Online EvaluatorError errorState;43 public Online EvaluatorError PopulationVarianceErrorState {42 private OnlineCalculatorError errorState; 43 public OnlineCalculatorError PopulationVarianceErrorState { 44 44 get { return errorState; } 45 45 } … … 50 50 } 51 51 52 public Online EvaluatorError MeanErrorState {52 public OnlineCalculatorError MeanErrorState { 53 53 get { return errorState; } 54 54 } … … 69 69 public void Reset() { 70 70 n = 0; 71 errorState = Online EvaluatorError.InsufficientElementsAdded;72 varianceErrorState = Online EvaluatorError.InsufficientElementsAdded;71 errorState = OnlineCalculatorError.InsufficientElementsAdded; 72 varianceErrorState = OnlineCalculatorError.InsufficientElementsAdded; 73 73 } 74 74 75 75 public void Add(double x) { 76 if (double.IsNaN(x) || double.IsInfinity(x) || (errorState & Online EvaluatorError.InvalidValueAdded) > 0) {77 errorState = errorState | Online EvaluatorError.InvalidValueAdded;78 varianceErrorState = errorState | Online EvaluatorError.InvalidValueAdded;76 if (double.IsNaN(x) || double.IsInfinity(x) || (errorState & OnlineCalculatorError.InvalidValueAdded) > 0) { 77 errorState = errorState | OnlineCalculatorError.InvalidValueAdded; 78 varianceErrorState = errorState | OnlineCalculatorError.InvalidValueAdded; 79 79 } else { 80 80 n++; … … 83 83 m_oldM = m_newM = x; 84 84 m_oldS = 0.0; 85 errorState = errorState & (~Online EvaluatorError.InsufficientElementsAdded); // n >= 185 errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded); // n >= 1 86 86 } else { 87 varianceErrorState = varianceErrorState & (~Online EvaluatorError.InsufficientElementsAdded); // n >= 287 varianceErrorState = varianceErrorState & (~OnlineCalculatorError.InsufficientElementsAdded); // n >= 2 88 88 m_newM = m_oldM + (x - m_oldM) / n; 89 89 m_newS = m_oldS + (x - m_oldM) * (x - m_newM); … … 96 96 } 97 97 98 public static void Calculate(IEnumerable<double> x, out double mean, out double variance, out Online EvaluatorError meanErrorState, out OnlineEvaluatorError varianceErrorState) {98 public static void Calculate(IEnumerable<double> x, out double mean, out double variance, out OnlineCalculatorError meanErrorState, out OnlineCalculatorError varianceErrorState) { 99 99 OnlineMeanAndVarianceCalculator meanAndVarianceCalculator = new OnlineMeanAndVarianceCalculator(); 100 100 foreach (double xi in x) { -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineMeanSquaredErrorCalculator.cs
r5941 r5942 24 24 25 25 namespace HeuristicLab.Problems.DataAnalysis { 26 public class OnlineMeanSquaredError Evaluator : IOnlineEvaluator {26 public class OnlineMeanSquaredErrorCalculator : IOnlineCalculator { 27 27 28 28 private double sse; … … 34 34 } 35 35 36 public OnlineMeanSquaredError Evaluator() {36 public OnlineMeanSquaredErrorCalculator() { 37 37 Reset(); 38 38 } 39 39 40 #region IOnline Evaluator Members41 private Online EvaluatorError errorState;42 public Online EvaluatorError ErrorState {40 #region IOnlineCalculator Members 41 private OnlineCalculatorError errorState; 42 public OnlineCalculatorError ErrorState { 43 43 get { return errorState; } 44 44 } … … 49 49 n = 0; 50 50 sse = 0.0; 51 errorState = Online EvaluatorError.InsufficientElementsAdded;51 errorState = OnlineCalculatorError.InsufficientElementsAdded; 52 52 } 53 53 54 54 public void Add(double original, double estimated) { 55 55 if (double.IsNaN(estimated) || double.IsInfinity(estimated) || 56 double.IsNaN(original) || double.IsInfinity(original) || (errorState & Online EvaluatorError.InvalidValueAdded) > 0) {57 errorState = errorState | Online EvaluatorError.InvalidValueAdded;56 double.IsNaN(original) || double.IsInfinity(original) || (errorState & OnlineCalculatorError.InvalidValueAdded) > 0) { 57 errorState = errorState | OnlineCalculatorError.InvalidValueAdded; 58 58 } else { 59 59 double error = estimated - original; 60 60 sse += error * error; 61 61 n++; 62 errorState = errorState & (~Online EvaluatorError.InsufficientElementsAdded); // n >= 162 errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded); // n >= 1 63 63 } 64 64 } 65 65 #endregion 66 66 67 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out Online EvaluatorError errorState) {67 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineCalculatorError errorState) { 68 68 IEnumerator<double> firstEnumerator = first.GetEnumerator(); 69 69 IEnumerator<double> secondEnumerator = second.GetEnumerator(); 70 OnlineMeanSquaredError Evaluator mseEvaluator = new OnlineMeanSquaredErrorEvaluator();70 OnlineMeanSquaredErrorCalculator mseCalculator = new OnlineMeanSquaredErrorCalculator(); 71 71 72 72 // always move forward both enumerators (do not use short-circuit evaluation!) … … 74 74 double estimated = secondEnumerator.Current; 75 75 double original = firstEnumerator.Current; 76 mse Evaluator.Add(original, estimated);76 mseCalculator.Add(original, estimated); 77 77 } 78 78 … … 81 81 throw new ArgumentException("Number of elements in first and second enumeration doesn't match."); 82 82 } else { 83 errorState = mse Evaluator.ErrorState;84 return mse Evaluator.MeanSquaredError;83 errorState = mseCalculator.ErrorState; 84 return mseCalculator.MeanSquaredError; 85 85 } 86 86 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineNormalizedMeanSquaredErrorCalculator.cs
r5941 r5942 24 24 25 25 namespace HeuristicLab.Problems.DataAnalysis { 26 public class OnlineNormalizedMeanSquaredError Evaluator : IOnlineEvaluator {26 public class OnlineNormalizedMeanSquaredErrorCalculator : IOnlineCalculator { 27 27 private OnlineMeanAndVarianceCalculator meanSquaredErrorCalculator; 28 28 private OnlineMeanAndVarianceCalculator originalVarianceCalculator; … … 36 36 } 37 37 38 public OnlineNormalizedMeanSquaredError Evaluator() {38 public OnlineNormalizedMeanSquaredErrorCalculator() { 39 39 meanSquaredErrorCalculator = new OnlineMeanAndVarianceCalculator(); 40 40 originalVarianceCalculator = new OnlineMeanAndVarianceCalculator(); … … 42 42 } 43 43 44 #region IOnline Evaluator Members45 public Online EvaluatorError ErrorState {44 #region IOnlineCalculator Members 45 public OnlineCalculatorError ErrorState { 46 46 get { return meanSquaredErrorCalculator.MeanErrorState | originalVarianceCalculator.VarianceErrorState; } 47 47 } … … 63 63 #endregion 64 64 65 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out Online EvaluatorError errorState) {65 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineCalculatorError errorState) { 66 66 IEnumerator<double> firstEnumerator = first.GetEnumerator(); 67 67 IEnumerator<double> secondEnumerator = second.GetEnumerator(); 68 OnlineNormalizedMeanSquaredError Evaluator normalizedMSEEvaluator = new OnlineNormalizedMeanSquaredErrorEvaluator();68 OnlineNormalizedMeanSquaredErrorCalculator normalizedMSECalculator = new OnlineNormalizedMeanSquaredErrorCalculator(); 69 69 70 70 // always move forward both enumerators (do not use short-circuit evaluation!) … … 72 72 double estimated = secondEnumerator.Current; 73 73 double original = firstEnumerator.Current; 74 normalizedMSE Evaluator.Add(original, estimated);74 normalizedMSECalculator.Add(original, estimated); 75 75 } 76 76 … … 79 79 throw new ArgumentException("Number of elements in first and second enumeration doesn't match."); 80 80 } else { 81 errorState = normalizedMSE Evaluator.ErrorState;82 return normalizedMSE Evaluator.NormalizedMeanSquaredError;81 errorState = normalizedMSECalculator.ErrorState; 82 return normalizedMSECalculator.NormalizedMeanSquaredError; 83 83 } 84 84 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlinePearsonsRSquaredCalculator.cs
r5941 r5942 25 25 26 26 namespace HeuristicLab.Problems.DataAnalysis { 27 public class OnlinePearsonsRSquared Evaluator : IOnlineEvaluator {28 private OnlineCovariance Evaluator covEvaluator = new OnlineCovarianceEvaluator();29 private OnlineMeanAndVarianceCalculator sx Evaluator = new OnlineMeanAndVarianceCalculator();30 private OnlineMeanAndVarianceCalculator sy Evaluator = new OnlineMeanAndVarianceCalculator();27 public class OnlinePearsonsRSquaredCalculator : IOnlineCalculator { 28 private OnlineCovarianceCalculator covCalculator = new OnlineCovarianceCalculator(); 29 private OnlineMeanAndVarianceCalculator sxCalculator = new OnlineMeanAndVarianceCalculator(); 30 private OnlineMeanAndVarianceCalculator syCalculator = new OnlineMeanAndVarianceCalculator(); 31 31 32 32 public double RSquared { 33 33 get { 34 double xVar = sx Evaluator.PopulationVariance;35 double yVar = sy Evaluator.PopulationVariance;34 double xVar = sxCalculator.PopulationVariance; 35 double yVar = syCalculator.PopulationVariance; 36 36 if (xVar.IsAlmost(0.0) || yVar.IsAlmost(0.0)) { 37 37 return 0.0; 38 38 } else { 39 double r = cov Evaluator.Covariance / (Math.Sqrt(xVar) * Math.Sqrt(yVar));39 double r = covCalculator.Covariance / (Math.Sqrt(xVar) * Math.Sqrt(yVar)); 40 40 return r * r; 41 41 } … … 43 43 } 44 44 45 public OnlinePearsonsRSquared Evaluator() { }45 public OnlinePearsonsRSquaredCalculator() { } 46 46 47 #region IOnline Evaluator Members48 public Online EvaluatorError ErrorState {49 get { return cov Evaluator.ErrorState | sxEvaluator.PopulationVarianceErrorState | syEvaluator.PopulationVarianceErrorState; }47 #region IOnlineCalculator Members 48 public OnlineCalculatorError ErrorState { 49 get { return covCalculator.ErrorState | sxCalculator.PopulationVarianceErrorState | syCalculator.PopulationVarianceErrorState; } 50 50 } 51 51 public double Value { … … 53 53 } 54 54 public void Reset() { 55 cov Evaluator.Reset();56 sx Evaluator.Reset();57 sy Evaluator.Reset();55 covCalculator.Reset(); 56 sxCalculator.Reset(); 57 syCalculator.Reset(); 58 58 } 59 59 60 60 public void Add(double x, double y) { 61 61 // no need to check validity of values explicitly here as it is checked in all three evaluators 62 cov Evaluator.Add(x, y);63 sx Evaluator.Add(x);64 sy Evaluator.Add(y);62 covCalculator.Add(x, y); 63 sxCalculator.Add(x); 64 syCalculator.Add(y); 65 65 } 66 66 67 67 #endregion 68 68 69 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out Online EvaluatorError errorState) {69 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineCalculatorError errorState) { 70 70 IEnumerator<double> firstEnumerator = first.GetEnumerator(); 71 71 IEnumerator<double> secondEnumerator = second.GetEnumerator(); 72 OnlinePearsonsRSquared Evaluator rSquaredEvaluator = new OnlinePearsonsRSquaredEvaluator();72 OnlinePearsonsRSquaredCalculator rSquaredCalculator = new OnlinePearsonsRSquaredCalculator(); 73 73 74 74 // always move forward both enumerators (do not use short-circuit evaluation!) … … 76 76 double estimated = secondEnumerator.Current; 77 77 double original = firstEnumerator.Current; 78 rSquared Evaluator.Add(original, estimated);78 rSquaredCalculator.Add(original, estimated); 79 79 } 80 80 … … 83 83 throw new ArgumentException("Number of elements in first and second enumeration doesn't match."); 84 84 } else { 85 errorState = rSquared Evaluator.ErrorState;86 return rSquared Evaluator.RSquared;85 errorState = rSquaredCalculator.ErrorState; 86 return rSquaredCalculator.RSquared; 87 87 } 88 88 }
Note: See TracChangeset
for help on using the changeset viewer.