Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/14/12 13:59:47 (12 years ago)
Author:
mkommend
Message:

#1081: Corrected evaluators and time series models.

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  
    2323using System;
    2424using System.Collections.Generic;
     25using System.Linq;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
     
    6162    [ThreadStatic]
    6263    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) {
    6467      if (cache == null || cache.GetLength(0) < maxRows) {
    6568        cache = new double[maxRows];
     
    7679        double target = targetValuesEnumerator.Current;
    7780        double estimated = estimatedValuesEnumerator.Current;
     81        cache[i] = estimated;
    7882        linearScalingCalculator.Add(estimated, target);
    79         cache[i] = estimated;
    8083        i++;
    8184      }
     
    8588      //calculate the quality by using the passed online calculator
    8689      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);
    9395      }
    9496    }
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator.cs

    r8458 r8486  
    3535    [StorableConstructor]
    3636    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) { }
    4038    public override IDeepCloneable Clone(Cloner cloner) {
    4139      return new SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator(this, cloner);
     
    6563      IEnumerable<double> targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows.Zip(horizions, Enumerable.Range).SelectMany(r => r));
    6664      IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows, horizions).SelectMany(x => x);
    67       IEnumerable<double> boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    6865      OnlineCalculatorError errorState;
    6966
     
    7168      if (applyLinearScaling && horizon == 1) { //perform normal evaluation and afterwards scale the solution and calculate the fitness value       
    7269        var mseCalculator = new OnlineMeanSquaredErrorCalculator();
    73         CalculateWithScaling(targetValues, boundedEstimatedValues, mseCalculator, problemData.Dataset.Rows * horizon);
     70        CalculateWithScaling(targetValues, estimatedValues, lowerEstimationLimit, upperEstimationLimit, mseCalculator, problemData.Dataset.Rows * horizon);
    7471        errorState = mseCalculator.ErrorState;
    7572        mse = mseCalculator.MeanSquaredError;
     
    7976        var scaledSolution = model.SymbolicExpressionTree;
    8077        estimatedValues = interpreter.GetSymbolicExpressionTreeValues(scaledSolution, problemData.Dataset, rows, horizions).SelectMany(x => x);
    81         boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
     78        var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    8279        mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
    83       } else
     80      } else {
     81        var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    8482        mse = OnlineMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
     83      }
    8584
    8685      if (errorState != OnlineCalculatorError.None) return Double.NaN;
    8786      else return mse;
    88 
    8987    }
    9088
Note: See TracChangeset for help on using the changeset viewer.