Changeset 8486 for branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis
- Timestamp:
- 08/14/12 13:59:47 (12 years ago)
- Location:
- branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveEvaluator.cs
r7989 r8486 23 23 using System; 24 24 using System.Collections.Generic; 25 using System.Linq; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 61 62 [ThreadStatic] 62 63 private static double[] cache; 63 protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, IOnlineCalculator calculator, int maxRows) { 64 protected static void CalculateWithScaling(IEnumerable<double> targetValues, IEnumerable<double> estimatedValues, 65 double lowerEstimationLimit, double upperEstimationLimit, 66 IOnlineCalculator calculator, int maxRows) { 64 67 if (cache == null || cache.GetLength(0) < maxRows) { 65 68 cache = new double[maxRows]; … … 76 79 double target = targetValuesEnumerator.Current; 77 80 double estimated = estimatedValuesEnumerator.Current; 81 cache[i] = estimated; 78 82 linearScalingCalculator.Add(estimated, target); 79 cache[i] = estimated;80 83 i++; 81 84 } … … 85 88 //calculate the quality by using the passed online calculator 86 89 targetValuesEnumerator = targetValues.GetEnumerator(); 87 i = 0; 88 while (targetValuesEnumerator.MoveNext()) { 89 double target = targetValuesEnumerator.Current; 90 double estimated = cache[i] * beta + alpha; 91 calculator.Add(target, estimated); 92 i++; 90 var scaledBoundedEstimatedValuesEnumerator = Enumerable.Range(0, i).Select(x => cache[x] * beta + alpha) 91 .LimitToRange(lowerEstimationLimit, upperEstimationLimit).GetEnumerator(); 92 93 while (targetValuesEnumerator.MoveNext() & scaledBoundedEstimatedValuesEnumerator.MoveNext()) { 94 calculator.Add(targetValuesEnumerator.Current, scaledBoundedEstimatedValuesEnumerator.Current); 93 95 } 94 96 } -
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator.cs
r8458 r8486 35 35 [StorableConstructor] 36 36 protected SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator(bool deserializing) : base(deserializing) { } 37 protected SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator(SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator original, Cloner cloner) 38 : base(original, cloner) { 39 } 37 protected SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator(SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator original, Cloner cloner) : base(original, cloner) { } 40 38 public override IDeepCloneable Clone(Cloner cloner) { 41 39 return new SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator(this, cloner); … … 65 63 IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows.Zip(horizions, Enumerable.Range).SelectMany(r => r)); 66 64 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows, horizions).SelectMany(x => x); 67 IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);68 65 OnlineCalculatorError errorState; 69 66 … … 71 68 if (applyLinearScaling && horizon == 1) { //perform normal evaluation and afterwards scale the solution and calculate the fitness value 72 69 var mseCalculator = new OnlineMeanSquaredErrorCalculator(); 73 CalculateWithScaling(targetValues, boundedEstimatedValues, mseCalculator, problemData.Dataset.Rows * horizon);70 CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, mseCalculator, problemData.Dataset.Rows * horizon); 74 71 errorState = mseCalculator.ErrorState; 75 72 mse = mseCalculator.MeanSquaredError; … … 79 76 var scaledSolution = model.SymbolicExpressionTree; 80 77 estimatedValues = interpreter.GetSymbolicExpressionTreeValues(scaledSolution, problemData.Dataset, rows, horizions).SelectMany(x => x); 81 boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);78 var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 82 79 mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 83 } else 80 } else { 81 var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 84 82 mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState); 83 } 85 84 86 85 if (errorState != OnlineCalculatorError.None) return Double.NaN; 87 86 else return mse; 88 89 87 } 90 88
Note: See TracChangeset
for help on using the changeset viewer.