Changeset 5894
- Timestamp:
- 03/30/11 18:04:03 (14 years ago)
- Location:
- trunk/sources
- Files:
-
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/InteractiveSymbolicDiscriminantFunctionClassificationSolutionSimplifierView.cs
r5809 r5894 84 84 var classifier = new SymbolicDiscriminantFunctionClassificationModel(tree, interpreter); 85 85 classifier.SetThresholdsAndClassValues(thresholds, classValues); 86 double originalAccuracy = OnlineAccuracyEvaluator.Calculate(targetClassValues, classifier.GetEstimatedClassValues(dataset, rows)); 86 OnlineEvaluatorError errorState; 87 double originalAccuracy = OnlineAccuracyEvaluator.Calculate(targetClassValues, classifier.GetEstimatedClassValues(dataset, rows), out errorState); 88 if (errorState != OnlineEvaluatorError.None) originalAccuracy = 0.0; 87 89 88 90 foreach (ISymbolicExpressionTreeNode node in nodes) { … … 97 99 classifier = new SymbolicDiscriminantFunctionClassificationModel(tree, interpreter); 98 100 classifier.SetThresholdsAndClassValues(thresholds, classValues); 99 double newAccuracy = OnlineAccuracyEvaluator.Calculate(targetClassValues, classifier.GetEstimatedClassValues(dataset, rows)); 101 double newAccuracy = OnlineAccuracyEvaluator.Calculate(targetClassValues, classifier.GetEstimatedClassValues(dataset, rows), out errorState); 102 if (errorState != OnlineEvaluatorError.None) newAccuracy = 0.0; 100 103 101 104 // impact = 0 if no change -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs
r5851 r5894 58 58 IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows); 59 59 IEnumerable<double> boundedEstimationValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 60 double mse = OnlineMeanSquaredErrorEvaluator.Calculate(originalValues, boundedEstimationValues); 60 OnlineEvaluatorError errorState; 61 double mse = OnlineMeanSquaredErrorEvaluator.Calculate(originalValues, boundedEstimationValues, out errorState); 62 if (errorState != OnlineEvaluatorError.None) mse = double.NaN; 61 63 return new double[2] { mse, solution.Length }; 62 64 } … … 72 74 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; 73 75 EstimationLimitsParameter.ExecutionContext = null; 74 EvaluatedNodesParameter.ExecutionContext = null; 76 EvaluatedNodesParameter.ExecutionContext = null; 75 77 76 78 return quality; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs
r5851 r5894 37 37 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 38 38 IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows); 39 double r2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedValues, originalValues); 40 return new double[] { double.IsNaN(r2) ? 0.0 : r2, solution.Length }; 39 OnlineEvaluatorError errorState; 40 double r2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedValues, originalValues, out errorState); 41 if (errorState != OnlineEvaluatorError.None) r2 = 0.0; 42 return new double[] { r2, solution.Length }; 43 41 44 } 42 45 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveBoundedMeanSquaredErrorEvaluator.cs
r5851 r5894 63 63 IEnumerator<double> originalEnumerator = originalValues.GetEnumerator(); 64 64 IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator(); 65 OnlineMeanSquaredErrorEvaluator mseEvaluator = new OnlineMeanSquaredErrorEvaluator();66 65 double errorSum = 0.0; 67 66 int n = 0; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveMeanSquaredErrorEvaluator.cs
r5851 r5894 58 58 IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows); 59 59 IEnumerable<double> boundedEstimationValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 60 return OnlineMeanSquaredErrorEvaluator.Calculate(originalValues, boundedEstimationValues); 60 OnlineEvaluatorError errorState; 61 double mse = OnlineMeanSquaredErrorEvaluator.Calculate(originalValues, boundedEstimationValues, out errorState); 62 if (errorState != OnlineEvaluatorError.None) return double.NaN; 63 else return mse; 61 64 } 62 65 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectivePearsonRSquaredEvaluator.cs
r5851 r5894 58 58 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 59 59 IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows); 60 double r2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedValues, originalValues); 61 return double.IsNaN(r2) ? 0.0 : r2; 60 OnlineEvaluatorError errorState; 61 double r2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedValues, originalValues, out errorState); 62 if (errorState != OnlineEvaluatorError.None) return 0.0; 63 else return r2; 62 64 } 63 65 … … 72 74 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; 73 75 EstimationLimitsParameter.ExecutionContext = null; 74 EvaluatedNodesParameter.ExecutionContext = null; 76 EvaluatedNodesParameter.ExecutionContext = null; 75 77 76 78 return r2; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicDiscriminantFunctionClassificationModel.cs
r5818 r5894 124 124 double alpha; 125 125 double beta; 126 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out alpha, out beta); 126 OnlineEvaluatorError errorState; 127 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out alpha, out beta, out errorState); 128 if (errorState != OnlineEvaluatorError.None) return; 127 129 128 130 ConstantTreeNode alphaTreeNode = null; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs
r5818 r5894 78 78 .ToArray(); 79 79 var targetValues = dataset.GetEnumeratedVariableValues(targetVariable, rows); 80 81 double originalR2 = OnlinePearsonsRSquaredEvaluator.Calculate(targetValues, originalOutput); 80 OnlineEvaluatorError errorState; 81 double originalR2 = OnlinePearsonsRSquaredEvaluator.Calculate(targetValues, originalOutput, out errorState); 82 if (errorState != OnlineEvaluatorError.None) originalR2 = 0.0; 82 83 83 84 foreach (ISymbolicExpressionTreeNode node in nodes) { … … 87 88 SwitchNode(parent, node, replacementNode); 88 89 var newOutput = interpreter.GetSymbolicExpressionTreeValues(tree, dataset, rows); 89 double newR2 = OnlinePearsonsRSquaredEvaluator.Calculate(targetValues, newOutput); 90 double newR2 = OnlinePearsonsRSquaredEvaluator.Calculate(targetValues, newOutput, out errorState); 91 if (errorState != OnlineEvaluatorError.None) newR2 = 0.0; 90 92 91 93 // impact = 0 if no change -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs
r5851 r5894 58 58 IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows); 59 59 IEnumerable<double> boundedEstimationValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 60 double mse = OnlineMeanSquaredErrorEvaluator.Calculate(originalValues, boundedEstimationValues); 60 OnlineEvaluatorError errorState; 61 double mse = OnlineMeanSquaredErrorEvaluator.Calculate(originalValues, boundedEstimationValues, out errorState); 62 if (errorState != OnlineEvaluatorError.None) mse = double.NaN; 61 63 return new double[2] { mse, solution.Length }; 62 64 } … … 72 74 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; 73 75 EstimationLimitsParameter.ExecutionContext = null; 74 EvaluatedNodesParameter.ExecutionContext = null; 76 EvaluatedNodesParameter.ExecutionContext = null; 75 77 76 78 return quality; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs
r5851 r5894 58 58 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 59 59 IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows); 60 double r2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedValues, originalValues); 61 return new double[] { double.IsNaN(r2) ? 0.0 : r2, solution.Length }; 60 OnlineEvaluatorError errorState; 61 double r2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedValues, originalValues, out errorState); 62 if (errorState != OnlineEvaluatorError.None) r2 = 0.0; 63 return new double[] { r2, solution.Length }; 62 64 } 63 65 … … 72 74 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; 73 75 EstimationLimitsParameter.ExecutionContext = null; 74 EvaluatedNodesParameter.ExecutionContext = null; 76 EvaluatedNodesParameter.ExecutionContext = null; 75 77 76 78 return quality; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs
r5851 r5894 60 60 IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows); 61 61 IEnumerable<double> boundedEstimationValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 62 return OnlineMeanSquaredErrorEvaluator.Calculate(originalValues, boundedEstimationValues); 62 OnlineEvaluatorError errorState; 63 double mse = OnlineMeanSquaredErrorEvaluator.Calculate(originalValues, boundedEstimationValues, out errorState); 64 if (errorState != OnlineEvaluatorError.None) return double.NaN; 65 else return mse; 63 66 } 64 67 … … 74 77 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; 75 78 EstimationLimitsParameter.ExecutionContext = null; 76 EvaluatedNodesParameter.ExecutionContext = null; 79 EvaluatedNodesParameter.ExecutionContext = null; 77 80 78 81 return mse; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs
r5851 r5894 60 60 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 61 61 IEnumerable<double> originalValues = problemData.Dataset.GetEnumeratedVariableValues(problemData.TargetVariable, rows); 62 double r2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedValues, originalValues); 63 return double.IsNaN(r2) ? 0.0 : r2; 62 OnlineEvaluatorError errorState; 63 double r2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedValues, originalValues, out errorState); 64 if (errorState != OnlineEvaluatorError.None) return 0.0; 65 else return r2; 64 66 } 65 67 … … 74 76 SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null; 75 77 EstimationLimitsParameter.ExecutionContext = null; 76 EvaluatedNodesParameter.ExecutionContext = null; 78 EvaluatedNodesParameter.ExecutionContext = null; 77 79 78 80 return r2; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionModel.cs
r5818 r5894 75 75 double alpha; 76 76 double beta; 77 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out alpha, out beta); 77 OnlineEvaluatorError errorState; 78 OnlineLinearScalingParameterCalculator.Calculate(estimatedValues, targetValues, out alpha, out beta, out errorState); 79 if (errorState != OnlineEvaluatorError.None) return; 78 80 79 81 ConstantTreeNode alphaTreeNode = null; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r5809 r5894 208 208 var variableTreeNode = instr.dynamicNode as VariableTreeNode; 209 209 instr.iArg0 = (ushort)dataset.GetVariableIndex(variableTreeNode.VariableName); 210 code[i] = instr;210 instr.dArg0 = variableTreeNode.Weight; 211 211 } else if (instr.opCode == OpCodes.LagVariable) { 212 212 var variableTreeNode = instr.dynamicNode as LaggedVariableTreeNode; 213 213 instr.iArg0 = (ushort)dataset.GetVariableIndex(variableTreeNode.VariableName); 214 code[i] = instr;214 instr.dArg0 = variableTreeNode.Weight; 215 215 } else if (instr.opCode == OpCodes.VariableCondition) { 216 216 var variableConditionTreeNode = instr.dynamicNode as VariableConditionTreeNode; 217 217 instr.iArg0 = (ushort)dataset.GetVariableIndex(variableConditionTreeNode.VariableName); 218 instr.dArg0 = variableConditionTreeNode.Threshold; 219 } else if (instr.opCode == OpCodes.Constant) { 220 var constTreeNode = instr.dynamicNode as ConstantTreeNode; 221 instr.dArg0 = constTreeNode.Value; 218 222 } 219 223 } … … 408 412 } 409 413 case OpCodes.Variable: { 410 var variableTreeNode = currentInstr.dynamicNode as VariableTreeNode; 411 return dataset[row, currentInstr.iArg0] * variableTreeNode.Weight; 414 return dataset[row, currentInstr.iArg0] * currentInstr.dArg0; 412 415 } 413 416 case OpCodes.LagVariable: { … … 415 418 int actualRow = row + laggedVariableTreeNode.Lag; 416 419 if (actualRow < 0 || actualRow >= dataset.Rows) throw new ArgumentException("Out of range access to dataset row: " + row); 417 return dataset[actualRow, currentInstr.iArg0] * laggedVariableTreeNode.Weight;420 return dataset[actualRow, currentInstr.iArg0] * currentInstr.dArg0; 418 421 } 419 422 case OpCodes.Constant: { 420 var constTreeNode = currentInstr.dynamicNode as ConstantTreeNode; 421 return constTreeNode.Value; 423 return currentInstr.dArg0; 422 424 } 423 425 … … 427 429 var variableConditionTreeNode = (VariableConditionTreeNode)currentInstr.dynamicNode; 428 430 double variableValue = dataset[row, currentInstr.iArg0]; 429 double x = variableValue - variableConditionTreeNode.Threshold;431 double x = variableValue - currentInstr.dArg0; 430 432 double p = 1 / (1 + Math.Exp(-variableConditionTreeNode.Slope * x)); 431 433 -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolution.cs
r5809 r5894 85 85 IEnumerable<double> originalTestClassValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TestIndizes); 86 86 87 double trainingAccuracy = OnlineAccuracyEvaluator.Calculate(estimatedTrainingClassValues, originalTrainingClassValues); 88 double testAccuracy = OnlineAccuracyEvaluator.Calculate(estimatedTestClassValues, originalTestClassValues); 87 OnlineEvaluatorError errorState; 88 double trainingAccuracy = OnlineAccuracyEvaluator.Calculate(estimatedTrainingClassValues, originalTrainingClassValues, out errorState); 89 if (errorState != OnlineEvaluatorError.None) trainingAccuracy = double.NaN; 90 double testAccuracy = OnlineAccuracyEvaluator.Calculate(estimatedTestClassValues, originalTestClassValues, out errorState); 91 if (errorState != OnlineEvaluatorError.None) testAccuracy = double.NaN; 89 92 90 93 TrainingAccuracy = trainingAccuracy; -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolution.cs
r5889 r5894 105 105 IEnumerable<double> originalTestValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TestIndizes); 106 106 107 double trainingMSE = OnlineMeanSquaredErrorEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues); 108 double testMSE = OnlineMeanSquaredErrorEvaluator.Calculate(estimatedTestValues, originalTestValues); 109 double trainingR2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues); 110 double testR2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedTestValues, originalTestValues); 107 OnlineEvaluatorError errorState; 108 double trainingMSE = OnlineMeanSquaredErrorEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState); 109 TrainingMeanSquaredError = errorState == OnlineEvaluatorError.None ? trainingMSE : double.NaN; 110 double testMSE = OnlineMeanSquaredErrorEvaluator.Calculate(estimatedTestValues, originalTestValues, out errorState); 111 TestMeanSquaredError = errorState == OnlineEvaluatorError.None ? testMSE : double.NaN; 111 112 112 TrainingMeanSquaredError = trainingMSE;113 T estMeanSquaredError = testMSE;114 TrainingRSquared = trainingR2;115 TestRSquared = testR2;113 double trainingR2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState); 114 TrainingRSquared = errorState == OnlineEvaluatorError.None ? trainingR2 : double.NaN; 115 double testR2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedTestValues, originalTestValues, out errorState); 116 TestRSquared = errorState == OnlineEvaluatorError.None ? testR2 : double.NaN; 116 117 } 117 118 -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ThresholdCalculators/NormalDistributionCutPointsThresholdCalculator.cs
r5849 r5894 64 64 double classValue = group.Key; 65 65 double mean, variance; 66 OnlineMeanAndVarianceCalculator.Calculate(estimatedClassValues, out mean, out variance); 67 classMean[classValue] = mean; 68 classStdDev[classValue] = Math.Sqrt(variance); 66 OnlineEvaluatorError meanErrorState, varianceErrorState; 67 OnlineMeanAndVarianceCalculator.Calculate(estimatedClassValues, out mean, out variance, out meanErrorState, out varianceErrorState); 68 69 if (meanErrorState == OnlineEvaluatorError.None && varianceErrorState == OnlineEvaluatorError.None) { 70 classMean[classValue] = mean; 71 classStdDev[classValue] = Math.Sqrt(variance); 72 } 69 73 } 70 74 double[] originalClasses = classMean.Keys.OrderBy(x => x).ToArray(); -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolution.cs
r5809 r5894 114 114 IEnumerable<double> originalTestValues = ProblemData.Dataset.GetEnumeratedVariableValues(ProblemData.TargetVariable, ProblemData.TestIndizes); 115 115 116 double trainingMSE = OnlineMeanSquaredErrorEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues); 117 double testMSE = OnlineMeanSquaredErrorEvaluator.Calculate(estimatedTestValues, originalTestValues); 118 double trainingR2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues); 119 double testR2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedTestValues, originalTestValues); 120 double trainingRelError = OnlineMeanAbsolutePercentageErrorEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues); 121 double testRelError = OnlineMeanAbsolutePercentageErrorEvaluator.Calculate(estimatedTestValues, originalTestValues); 116 OnlineEvaluatorError errorState; 117 double trainingMSE = OnlineMeanSquaredErrorEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState); 118 TrainingMeanSquaredError = errorState == OnlineEvaluatorError.None ? trainingMSE : double.NaN; 119 double testMSE = OnlineMeanSquaredErrorEvaluator.Calculate(estimatedTestValues, originalTestValues, out errorState); 120 TestMeanSquaredError = errorState == OnlineEvaluatorError.None ? testMSE : double.NaN; 122 121 123 TrainingMeanSquaredError = trainingMSE; 124 TestMeanSquaredError = testMSE; 125 TrainingRSquared = trainingR2; 126 TestRSquared = testR2; 127 TrainingRelativeError = trainingRelError; 128 TestRelativeError = testRelError; 122 double trainingR2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedTrainingValues, originalTrainingValues, out errorState); 123 TrainingRSquared = errorState == OnlineEvaluatorError.None ? trainingR2 : double.NaN; 124 double testR2 = OnlinePearsonsRSquaredEvaluator.Calculate(estimatedTestValues, originalTestValues, out errorState); 125 TestRSquared = errorState == OnlineEvaluatorError.None ? testR2 : double.NaN; 126 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; 129 131 } 130 132 -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IOnlineEvaluator.cs
r5809 r5894 21 21 22 22 23 using System; 23 24 namespace HeuristicLab.Problems.DataAnalysis { 25 [Flags] 26 public enum OnlineEvaluatorError { 27 /// <summary> 28 /// No error occurred 29 /// </summary> 30 None = 0, 31 /// <summary> 32 /// An invalid value has been added (often +/- Infinity and NaN are invalid values) 33 /// </summary> 34 InvalidValueAdded = 1, 35 /// <summary> 36 /// The number of elements added to the evaluator is not sufficient to calculate the result value 37 /// </summary> 38 InsufficientElementsAdded = 2 39 } 24 40 public interface IOnlineEvaluator { 41 OnlineEvaluatorError ErrorState { get; } 25 42 double Value { get; } 26 43 void Reset(); -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineAccuracyEvaluator.cs
r5809 r5894 31 31 public double Accuracy { 32 32 get { 33 if (n < 1) 34 throw new InvalidOperationException("No elements"); 35 else 36 return correctlyClassified / (double)n; 33 return correctlyClassified / (double)n; 37 34 } 38 35 } … … 43 40 44 41 #region IOnlineEvaluator Members 42 private OnlineEvaluatorError errorState; 43 public OnlineEvaluatorError ErrorState { 44 get { return errorState; } 45 } 45 46 public double Value { 46 47 get { return Accuracy; } … … 49 50 n = 0; 50 51 correctlyClassified = 0; 52 errorState = OnlineEvaluatorError.InsufficientElementsAdded; 51 53 } 52 54 53 55 public void Add(double original, double estimated) { 54 if (double.IsNaN(estimated) || double.IsInfinity(estimated) || 55 double.IsNaN(original) || double.IsInfinity(original)) { 56 throw new ArgumentException("Accuracy is not defined for NaN or infinity elements"); 57 } else { 58 if (original.IsAlmost(estimated)) correctlyClassified++; 56 // ignore cases where original is NaN completly 57 if (!double.IsNaN(original)) { 58 // increment number of observed samples 59 59 n++; 60 if (original.IsAlmost(estimated)) { 61 // original = estimated = +Inf counts as correctly classified 62 // original = estimated = -Inf counts as correctly classified 63 correctlyClassified++; 64 } 65 errorState = OnlineEvaluatorError.None; // number of (non-NaN) samples >= 1 60 66 } 61 67 } 62 68 #endregion 63 69 64 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second ) {70 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineEvaluatorError errorState) { 65 71 IEnumerator<double> firstEnumerator = first.GetEnumerator(); 66 72 IEnumerator<double> secondEnumerator = second.GetEnumerator(); … … 78 84 throw new ArgumentException("Number of elements in first and second enumeration doesn't match."); 79 85 } else { 86 errorState = accuracyEvaluator.ErrorState; 80 87 return accuracyEvaluator.Accuracy; 81 88 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineCovarianceEvaluator.cs
r5845 r5894 39 39 40 40 #region IOnlineEvaluator Members 41 private OnlineEvaluatorError errorState; 42 public OnlineEvaluatorError ErrorState { 43 get { return errorState; } 44 } 41 45 public double Value { 42 46 get { return Covariance; } … … 47 51 originalMean = 0.0; 48 52 estimatedMean = 0.0; 53 errorState = OnlineEvaluatorError.InsufficientElementsAdded; 49 54 } 50 55 51 56 public void Add(double original, double estimated) { 52 if (double.IsNaN(estimated) || double.IsInfinity(estimated) || 53 double.IsNaN(original) || double.IsInfinity(original) || 54 double.IsNaN(Cn)) { 55 Cn = double.NaN; 56 } else { 57 if (double.IsNaN(estimated) || double.IsInfinity(estimated) || double.IsNaN(original) || double.IsInfinity(original)) { 58 errorState = errorState | OnlineEvaluatorError.InvalidValueAdded; 59 } else if (!errorState.HasFlag(OnlineEvaluatorError.InvalidValueAdded)) { 57 60 n++; 61 errorState = OnlineEvaluatorError.None; // n >= 1 62 58 63 // online calculation of tMean 59 64 originalMean = originalMean + (original - originalMean) / n; … … 67 72 #endregion 68 73 69 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second ) {74 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineEvaluatorError errorState) { 70 75 IEnumerator<double> firstEnumerator = first.GetEnumerator(); 71 76 IEnumerator<double> secondEnumerator = second.GetEnumerator(); … … 83 88 throw new ArgumentException("Number of elements in first and second enumeration doesn't match."); 84 89 } else { 90 errorState = covarianceEvaluator.ErrorState; 85 91 return covarianceEvaluator.Covariance; 86 92 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineLinearScalingParameterCalculator.cs
r5818 r5894 32 32 public double Alpha { 33 33 get { 34 if (cnt < 2) 35 return 0; 36 else 37 return targetMeanCalculator.Mean - Beta * originalMeanAndVarianceCalculator.Mean; 34 return targetMeanCalculator.Mean - Beta * originalMeanAndVarianceCalculator.Mean; 38 35 } 39 36 } … … 44 41 public double Beta { 45 42 get { 46 if (cnt < 2) 47 return 1; 48 else if (originalMeanAndVarianceCalculator.PopulationVariance.IsAlmost(0.0)) 43 if (originalMeanAndVarianceCalculator.PopulationVariance.IsAlmost(0.0)) 49 44 return 1; 50 45 else 51 46 return originalTargetCovarianceEvaluator.Covariance / originalMeanAndVarianceCalculator.PopulationVariance; 47 } 48 } 49 50 public OnlineEvaluatorError ErrorState { 51 get { 52 return targetMeanCalculator.MeanErrorState | originalMeanAndVarianceCalculator.MeanErrorState | 53 originalMeanAndVarianceCalculator.PopulationVarianceErrorState | originalTargetCovarianceEvaluator.ErrorState; 52 54 } 53 55 } … … 94 96 /// <param name="alpha">Additive constant for the linear scaling</param> 95 97 /// <param name="beta">Multiplicative factor for the linear scaling</param> 96 public static void Calculate(IEnumerable<double> original, IEnumerable<double> target, out double alpha, out double beta) { 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 OnlineEvaluatorError errorState) { 97 100 OnlineLinearScalingParameterCalculator calculator = new OnlineLinearScalingParameterCalculator(); 98 101 IEnumerator<double> originalEnumerator = original.GetEnumerator(); … … 110 113 throw new ArgumentException("Number of elements in original and target enumeration do not match."); 111 114 } else { 115 errorState = calculator.ErrorState; 112 116 alpha = calculator.Alpha; 113 117 beta = calculator.Beta; -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineMeanAbsolutePercentageErrorEvaluator.cs
r5845 r5894 40 40 41 41 #region IOnlineEvaluator Members 42 private OnlineEvaluatorError errorState; 43 public OnlineEvaluatorError ErrorState { 44 get { return errorState; } 45 } 42 46 public double Value { 43 47 get { return MeanAbsolutePercentageError; } … … 46 50 n = 0; 47 51 sre = 0.0; 52 errorState = OnlineEvaluatorError.InsufficientElementsAdded; 48 53 } 49 54 … … 51 56 if (double.IsNaN(estimated) || double.IsInfinity(estimated) || 52 57 double.IsNaN(original) || double.IsInfinity(original) || 53 double.IsNaN(sre)) { 54 sre = double.NaN; 55 } else { 56 if (!original.IsAlmost(0.0)) { 57 sre += Math.Abs((estimated - original) / original); 58 n++; 59 } 58 original.IsAlmost(0.0)) { 59 errorState = errorState | OnlineEvaluatorError.InvalidValueAdded; 60 } else if (!errorState.HasFlag(OnlineEvaluatorError.InvalidValueAdded)) { 61 sre += Math.Abs((estimated - original) / original); 62 n++; 63 errorState = OnlineEvaluatorError.None; // n >= 1 60 64 } 61 65 } … … 63 67 #endregion 64 68 65 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second ) {69 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineEvaluatorError errorState) { 66 70 IEnumerator<double> firstEnumerator = first.GetEnumerator(); 67 71 IEnumerator<double> secondEnumerator = second.GetEnumerator(); … … 79 83 throw new ArgumentException("Number of elements in first and second enumeration doesn't match."); 80 84 } else { 85 errorState = evaluator.ErrorState; 81 86 return evaluator.MeanAbsolutePercentageError; 82 87 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineMeanAndVarianceCalculator.cs
r5845 r5894 29 29 private int n; 30 30 31 private OnlineEvaluatorError varianceErrorState; 32 public OnlineEvaluatorError VarianceErrorState { 33 get { return varianceErrorState; } 34 } 35 31 36 public double Variance { 32 37 get { … … 35 40 } 36 41 42 private OnlineEvaluatorError errorState; 43 public OnlineEvaluatorError PopulationVarianceErrorState { 44 get { return errorState; } 45 } 37 46 public double PopulationVariance { 38 47 get { … … 41 50 } 42 51 52 public OnlineEvaluatorError MeanErrorState { 53 get { return errorState; } 54 } 43 55 public double Mean { 44 56 get { … … 57 69 public void Reset() { 58 70 n = 0; 71 errorState = OnlineEvaluatorError.InsufficientElementsAdded; 72 varianceErrorState = OnlineEvaluatorError.InsufficientElementsAdded; 59 73 } 60 74 61 75 public void Add(double x) { 62 if (double.IsNaN(x) || double.IsInfinity(x) || double.IsNaN(m_newM)) {63 m_newM = double.NaN;64 m_newS = double.NaN;65 } else {76 if (double.IsNaN(x) || double.IsInfinity(x)) { 77 errorState = errorState | OnlineEvaluatorError.InvalidValueAdded; 78 varianceErrorState = errorState | OnlineEvaluatorError.InvalidValueAdded; 79 } else if (!errorState.HasFlag(OnlineEvaluatorError.InvalidValueAdded)) { 66 80 n++; 67 81 // See Knuth TAOCP vol 2, 3rd edition, page 232 … … 69 83 m_oldM = m_newM = x; 70 84 m_oldS = 0.0; 85 errorState = OnlineEvaluatorError.None; // n >= 1 71 86 } else { 87 varianceErrorState = OnlineEvaluatorError.None; // n >= 1 72 88 m_newM = m_oldM + (x - m_oldM) / n; 73 89 m_newS = m_oldS + (x - m_oldM) * (x - m_newM); … … 80 96 } 81 97 82 public static void Calculate(IEnumerable<double> x, out double mean, out double variance ) {98 public static void Calculate(IEnumerable<double> x, out double mean, out double variance, out OnlineEvaluatorError meanErrorState, out OnlineEvaluatorError varianceErrorState) { 83 99 OnlineMeanAndVarianceCalculator meanAndVarianceCalculator = new OnlineMeanAndVarianceCalculator(); 84 100 foreach (double xi in x) { … … 87 103 mean = meanAndVarianceCalculator.Mean; 88 104 variance = meanAndVarianceCalculator.Variance; 105 meanErrorState = meanAndVarianceCalculator.MeanErrorState; 106 varianceErrorState = meanAndVarianceCalculator.VarianceErrorState; 89 107 } 90 108 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineMeanSquaredErrorEvaluator.cs
r5845 r5894 39 39 40 40 #region IOnlineEvaluator Members 41 private OnlineEvaluatorError errorState; 42 public OnlineEvaluatorError ErrorState { 43 get { return errorState; } 44 } 41 45 public double Value { 42 46 get { return MeanSquaredError; } … … 45 49 n = 0; 46 50 sse = 0.0; 51 errorState = OnlineEvaluatorError.InsufficientElementsAdded; 47 52 } 48 53 49 54 public void Add(double original, double estimated) { 50 55 if (double.IsNaN(estimated) || double.IsInfinity(estimated) || 51 double.IsNaN(original) || double.IsInfinity(original) || 52 double.IsNaN(sse)) { 53 sse = double.NaN; 54 } else { 56 double.IsNaN(original) || double.IsInfinity(original)) { 57 errorState = errorState | OnlineEvaluatorError.InvalidValueAdded; 58 } else if (!errorState.HasFlag(OnlineEvaluatorError.InvalidValueAdded)) { 55 59 double error = estimated - original; 56 60 sse += error * error; 57 61 n++; 62 errorState = OnlineEvaluatorError.None; // n >= 1 58 63 } 59 64 } 60 65 #endregion 61 66 62 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second ) {67 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineEvaluatorError errorState) { 63 68 IEnumerator<double> firstEnumerator = first.GetEnumerator(); 64 69 IEnumerator<double> secondEnumerator = second.GetEnumerator(); … … 76 81 throw new ArgumentException("Number of elements in first and second enumeration doesn't match."); 77 82 } else { 83 errorState = mseEvaluator.ErrorState; 78 84 return mseEvaluator.MeanSquaredError; 79 85 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineNormalizedMeanSquaredErrorEvaluator.cs
r5809 r5894 43 43 44 44 #region IOnlineEvaluator Members 45 public OnlineEvaluatorError ErrorState { 46 get { return meanSquaredErrorCalculator.MeanErrorState | originalVarianceCalculator.VarianceErrorState; } 47 } 45 48 public double Value { 46 49 get { return NormalizedMeanSquaredError; } … … 60 63 #endregion 61 64 62 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second ) {65 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineEvaluatorError errorState) { 63 66 IEnumerator<double> firstEnumerator = first.GetEnumerator(); 64 67 IEnumerator<double> secondEnumerator = second.GetEnumerator(); … … 76 79 throw new ArgumentException("Number of elements in first and second enumeration doesn't match."); 77 80 } else { 81 errorState = normalizedMSEEvaluator.ErrorState; 78 82 return normalizedMSEEvaluator.NormalizedMeanSquaredError; 79 83 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlinePearsonsRSquaredEvaluator.cs
r5809 r5894 46 46 47 47 #region IOnlineEvaluator Members 48 public OnlineEvaluatorError ErrorState { 49 get { return covEvaluator.ErrorState | sxEvaluator.PopulationVarianceErrorState | syEvaluator.PopulationVarianceErrorState; } 50 } 48 51 public double Value { 49 52 get { return RSquared; } … … 64 67 #endregion 65 68 66 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second ) {69 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second, out OnlineEvaluatorError errorState) { 67 70 IEnumerator<double> firstEnumerator = first.GetEnumerator(); 68 71 IEnumerator<double> secondEnumerator = second.GetEnumerator(); … … 80 83 throw new ArgumentException("Number of elements in first and second enumeration doesn't match."); 81 84 } else { 85 errorState = rSquaredEvaluator.ErrorState; 82 86 return rSquaredEvaluator.RSquared; 83 87 }
Note: See TracChangeset
for help on using the changeset viewer.