Changeset 7677 for trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs
- Timestamp:
- 03/30/12 22:48:32 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs
r7672 r7677 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Core; … … 34 33 public class SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator : SymbolicRegressionSingleObjectiveEvaluator { 35 34 public override bool Maximization { get { return false; } } 36 [ThreadStatic]37 private static double[] estimatedValuesCache;38 39 35 [StorableConstructor] 40 36 protected SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator(bool deserializing) : base(deserializing) { } … … 59 55 public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, IRegressionProblemData problemData, IEnumerable<int> rows, bool applyLinearScaling) { 60 56 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 61 IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);57 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); 62 58 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 63 59 OnlineCalculatorError errorState; … … 65 61 double mse; 66 62 if (applyLinearScaling) { 67 //int i = 0; 68 //int rowCount = rows.Count(); 69 //if (estimatedValuesCache == null) estimatedValuesCache = new double[problemData.Dataset.Rows]; 70 //foreach (var value in boundedEstimatedValues) { 71 // estimatedValuesCache[i] = value; 72 // i++; 73 //} 74 75 double alpha, beta; 76 OnlineLinearScalingParameterCalculator.Calculate(boundedEstimatedValues, originalValues, out alpha, out beta, out errorState); 77 mse = OnlineMeanSquaredErrorCalculator.Calculate(originalValues, boundedEstimatedValues.Select(value => value * beta + alpha), out errorState); 63 var mseCalculator = new OnlineMeanSquaredErrorCalculator(); 64 CalculateWithScaling(targetValues, boundedEstimatedValues, mseCalculator, problemData.Dataset.Rows); 65 errorState = mseCalculator.ErrorState; 66 mse = mseCalculator.MeanSquaredError; 78 67 } else 79 mse = OnlineMeanSquaredErrorCalculator.Calculate( originalValues, boundedEstimatedValues, out errorState);68 mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 80 69 81 70 if (errorState != OnlineCalculatorError.None) return Double.NaN;
Note: See TracChangeset
for help on using the changeset viewer.