Changeset 8113 for trunk/sources
- Timestamp:
- 06/26/12 08:27:57 (12 years ago)
- Location:
- trunk/sources
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveEvaluator.cs
r7677 r8113 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 59 60 private static double[] cache; 60 61 61 protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, IOnlineCalculator calculator, int maxRows) { 62 protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, 63 double lowerEstimationLimit, double upperEstimationLimit, 64 IOnlineCalculator calculator, int maxRows) { 62 65 if (cache == null || cache.GetLength(0) < maxRows) { 63 66 cache = new double[maxRows]; … … 83 86 //calculate the quality by using the passed online calculator 84 87 targetValuesEnumerator = targetValues.GetEnumerator(); 85 i = 0;86 while (targetValuesEnumerator.MoveNext()) {87 double target = targetValuesEnumerator.Current;88 double estimated = cache[i] * beta + alpha;89 calculator.Add(target, estimated);90 i++;88 var scaledBoundedEstimatedValuesEnumerator = (from r in Enumerable.Range(0, i) 89 select cache[r] * beta + alpha) 90 .LimitToRange(lowerEstimationLimit, upperEstimationLimit) 91 .GetEnumerator(); 92 while (targetValuesEnumerator.MoveNext() & scaledBoundedEstimatedValuesEnumerator.MoveNext()) { 93 calculator.Add(targetValuesEnumerator.Current, scaledBoundedEstimatedValuesEnumerator.Current); 91 94 } 92 95 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator.cs
r7677 r8113 56 56 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 57 57 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 58 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);59 58 OnlineCalculatorError errorState; 60 59 … … 62 61 if (applyLinearScaling) { 63 62 var maeCalculator = new OnlineMaxAbsoluteErrorCalculator(); 64 CalculateWithScaling(targetValues, boundedEstimatedValues, maeCalculator, problemData.Dataset.Rows);63 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, maeCalculator, problemData.Dataset.Rows); 65 64 errorState = maeCalculator.ErrorState; 66 65 mse = maeCalculator.MaxAbsoluteError; 67 } else 66 } else { 67 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 68 68 mse = OnlineMaxAbsoluteErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 69 69 } 70 70 if (errorState != OnlineCalculatorError.None) return Double.NaN; 71 71 else return mse; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator.cs
r7677 r8113 56 56 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 57 57 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 58 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);59 58 OnlineCalculatorError errorState; 60 59 … … 62 61 if (applyLinearScaling) { 63 62 var maeCalculator = new OnlineMeanAbsoluteErrorCalculator(); 64 CalculateWithScaling(targetValues, boundedEstimatedValues, maeCalculator, problemData.Dataset.Rows);63 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, maeCalculator, problemData.Dataset.Rows); 65 64 errorState = maeCalculator.ErrorState; 66 65 mse = maeCalculator.MeanAbsoluteError; 67 } else 66 } else { 67 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, 68 upperEstimationLimit); 68 69 mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 69 70 } 70 71 if (errorState != OnlineCalculatorError.None) return Double.NaN; 71 72 else return mse; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs
r7677 r8113 56 56 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 57 57 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 58 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);59 58 OnlineCalculatorError errorState; 60 59 … … 62 61 if (applyLinearScaling) { 63 62 var mseCalculator = new OnlineMeanSquaredErrorCalculator(); 64 CalculateWithScaling(targetValues, boundedEstimatedValues, mseCalculator, problemData.Dataset.Rows);63 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, mseCalculator, problemData.Dataset.Rows); 65 64 errorState = mseCalculator.ErrorState; 66 65 mse = mseCalculator.MeanSquaredError; 67 } else 66 } else { 67 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 68 68 mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 69 69 } 70 70 if (errorState != OnlineCalculatorError.None) return Double.NaN; 71 71 else return mse; -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IOnlineCalculator.cs
r7259 r8113 24 24 namespace HeuristicLab.Problems.DataAnalysis { 25 25 [Flags] 26 public enum OnlineCalculatorError { 26 public enum OnlineCalculatorError { 27 27 /// <summary> 28 28 /// No error occurred 29 29 /// </summary> 30 None = 0, 30 None = 0, 31 31 /// <summary> 32 32 /// An invalid value has been added (often +/- Infinity and NaN are invalid values) 33 33 /// </summary> 34 InvalidValueAdded = 1, 34 InvalidValueAdded = 1, 35 35 /// <summary> 36 36 /// The number of elements added to the evaluator is not sufficient to calculate the result value -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineLinearScalingParameterCalculator.cs
r7259 r8113 55 55 } 56 56 57 private int cnt;58 57 private OnlineMeanAndVarianceCalculator targetMeanCalculator; 59 58 private OnlineMeanAndVarianceCalculator originalMeanAndVarianceCalculator; … … 68 67 69 68 public void Reset() { 70 cnt = 0;71 69 targetMeanCalculator.Reset(); 72 70 originalMeanAndVarianceCalculator.Reset(); … … 85 83 originalTargetCovarianceCalculator.Add(original, target); 86 84 87 cnt++;88 85 } 89 86
Note: See TracChangeset
for help on using the changeset viewer.