Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/05/11 08:22:36 (13 years ago)
Author:
gkronber
Message:

#1081 implemented multi-variate symbolic expression tree interpreter for time series prognosis.

Location:
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveEvaluator.cs

    r6802 r7120  
    2222
    2323using HeuristicLab.Common;
     24using HeuristicLab.Core;
     25using HeuristicLab.Data;
     26using HeuristicLab.Parameters;
    2427using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2528namespace HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis {
    2629  public abstract class SymbolicTimeSeriesPrognosisSingleObjectiveEvaluator : SymbolicDataAnalysisSingleObjectiveEvaluator<ITimeSeriesPrognosisProblemData>, ISymbolicTimeSeriesPrognosisSingleObjectiveEvaluator {
     30    private const string HorizonParameterName = "Horizon";
     31
     32    public IValueLookupParameter<IntValue> HorizonParameter {
     33      get { return (IValueLookupParameter<IntValue>)Parameters[HorizonParameterName]; }
     34    }
     35
    2736    [StorableConstructor]
    2837    protected SymbolicTimeSeriesPrognosisSingleObjectiveEvaluator(bool deserializing) : base(deserializing) { }
     
    3140    }
    3241
    33     protected SymbolicTimeSeriesPrognosisSingleObjectiveEvaluator() : base() { }
     42    protected SymbolicTimeSeriesPrognosisSingleObjectiveEvaluator()
     43      : base() {
     44      Parameters.Add(new ValueLookupParameter<IntValue>(HorizonParameterName, "The time interval for which the prognosis should be calculated.", new IntValue(1)));
     45    }
    3446  }
    3547}
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveMeanSquaredErrorEvaluator.cs

    r7100 r7120  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
     24using System.Linq;
    2325using HeuristicLab.Common;
    2426using HeuristicLab.Core;
     
    4850      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4951
    50       double quality = Calculate(SymbolicTimeSeriesPrognosisInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows);
     52      double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue,
     53        solution,
     54        EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper,
     55        ProblemDataParameter.ActualValue,
     56        rows, HorizonParameter.ActualValue.Value);
    5157      QualityParameter.ActualValue = new DoubleValue(quality);
    5258
     
    5460    }
    5561
    56     public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, ITimeSeriesPrognosisProblemData problemData, IEnumerable<int> rows) {
    57       IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    58       OnlineMeanAndVarianceCalculator meanCalculator = new OnlineMeanAndVarianceCalculator();
     62    public static double Calculate(ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, ITimeSeriesPrognosisProblemData problemData, IEnumerable<int> rows, int horizon) {
     63      var allPredictedContinuations = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, problemData.TargetVariables.ToArray(), rows, horizon);
     64      var meanCalculator = new OnlineMeanAndVarianceCalculator();
     65      var allPredictedContinuationsEnumerator = allPredictedContinuations.GetEnumerator();
    5966      foreach (var targetVariable in problemData.TargetVariables) {
    60         IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(targetVariable, rows);
    61         IEnumerable<double> boundedEstimationValues = estimatedValues.LimitToRange(lowerEstimationLimit,
    62                                                                                    upperEstimationLimit);
    63         OnlineCalculatorError errorState;
    64         meanCalculator.Add(OnlineMeanSquaredErrorCalculator.Calculate(originalValues, boundedEstimationValues, out errorState));
    65         if (errorState != OnlineCalculatorError.None) return double.NaN;
     67        if (!allPredictedContinuationsEnumerator.MoveNext()) throw new InvalidOperationException();
     68        var actualContinuations = from r in rows
     69                                  select problemData.Dataset.GetDoubleValues(targetVariable, Enumerable.Range(r, horizon));
     70        var actualContinuationsEnumerator = actualContinuations.GetEnumerator();
     71        var predictedContinuationsEnumerator = allPredictedContinuationsEnumerator.Current.GetEnumerator();
     72        while (actualContinuationsEnumerator.MoveNext() & predictedContinuationsEnumerator.MoveNext()) {
     73          OnlineCalculatorError errorState;
     74          meanCalculator.Add(OnlineMeanSquaredErrorCalculator.Calculate(predictedContinuationsEnumerator.Current.LimitToRange(lowerEstimationLimit, upperEstimationLimit),
     75                                                                        actualContinuationsEnumerator.Current, out errorState));
     76          if (errorState != OnlineCalculatorError.None) return double.NaN;
     77        }
    6678      }
    6779      return meanCalculator.Mean;
     
    6981
    7082    public override double Evaluate(IExecutionContext context, ISymbolicExpressionTree tree, ITimeSeriesPrognosisProblemData problemData, IEnumerable<int> rows) {
    71       SymbolicTimeSeriesPrognosisInterpreterParameter.ExecutionContext = context;
     83      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
    7284      EstimationLimitsParameter.ExecutionContext = context;
     85      HorizonParameter.ExecutionContext = context;
    7386
    74       double mse = Calculate(SymbolicTimeSeriesPrognosisInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows);
     87      double mse = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, HorizonParameter.ActualValue.Value);
    7588
    76 
    77       SymbolicTimeSeriesPrognosisInterpreterParameter.ExecutionContext = null;
     89      HorizonParameter.ExecutionContext = null;
     90      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    7891      EstimationLimitsParameter.ExecutionContext = null;
    7992
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectivePearsonRSquaredEvaluator.cs

    r7100 r7120  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
     24using System.Linq;
    2325using HeuristicLab.Common;
    2426using HeuristicLab.Core;
     
    4850      IEnumerable<int> rows = GenerateRowsToEvaluate();
    4951
    50       double quality = Calculate(SymbolicTimeSeriesPrognosisInterpreterParameter.ActualValue, solution, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, ProblemDataParameter.ActualValue, rows);
     52      double quality = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, solution,
     53        EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper,
     54        ProblemDataParameter.ActualValue,
     55        rows, HorizonParameter.ActualValue.Value);
    5156      QualityParameter.ActualValue = new DoubleValue(quality);
    5257
     
    5459    }
    5560
    56     public static double Calculate(ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, ITimeSeriesPrognosisProblemData problemData, IEnumerable<int> rows) {
    57       IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
     61    public static double Calculate(ISymbolicTimeSeriesPrognosisExpressionTreeInterpreter interpreter, ISymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, ITimeSeriesPrognosisProblemData problemData, IEnumerable<int> rows, int horizon) {
     62      var allPredictedContinuations =
     63        interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, problemData.TargetVariables.ToArray(),
     64                                                    rows, horizon).ToArray();
     65
    5866      var meanCalculator = new OnlineMeanAndVarianceCalculator();
     67      int i = 0;
    5968      foreach (var targetVariable in problemData.TargetVariables) {
    60         IEnumerable<double> originalValues = problemData.Dataset.GetDoubleValues(targetVariable, rows);
     69        var actualContinuations = from r in rows
     70                                  select problemData.Dataset.GetDoubleValues(targetVariable, Enumerable.Range(r, horizon));
     71        var startValues = problemData.Dataset.GetDoubleValues(targetVariable, rows.Select(r => r - 1));
    6172        OnlineCalculatorError errorState;
    62         meanCalculator.Add(OnlinePearsonsRSquaredCalculator.Calculate(estimatedValues, originalValues, out errorState));
    63         if (errorState != OnlineCalculatorError.None) return 0.0;
     73        meanCalculator.Add(OnlineTheilsUStatisticCalculator.Calculate(
     74          startValues,
     75          allPredictedContinuations.Select(v => v.ElementAt(i)),
     76          actualContinuations, out errorState));
     77        if (errorState != OnlineCalculatorError.None) return double.NaN;
     78        i++;
    6479      }
    6580      return meanCalculator.Mean;
     
    6782
    6883    public override double Evaluate(IExecutionContext context, ISymbolicExpressionTree tree, ITimeSeriesPrognosisProblemData problemData, IEnumerable<int> rows) {
    69       SymbolicTimeSeriesPrognosisInterpreterParameter.ExecutionContext = context;
     84      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = context;
    7085      EstimationLimitsParameter.ExecutionContext = context;
     86      HorizonParameter.ExecutionContext = context;
    7187
    72       double r2 = Calculate(SymbolicTimeSeriesPrognosisInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows);
     88      double r2 = Calculate(SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, tree, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper, problemData, rows, HorizonParameter.ActualValue.Value);
    7389
    74       SymbolicTimeSeriesPrognosisInterpreterParameter.ExecutionContext = null;
     90      HorizonParameter.ExecutionContext = null;
     91      SymbolicDataAnalysisTreeInterpreterParameter.ExecutionContext = null;
    7592      EstimationLimitsParameter.ExecutionContext = null;
    7693
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveProblem.cs

    r7100 r7120  
    3131  [Creatable("Problems")]
    3232  public class SymbolicTimeSeriesPrognosisSingleObjectiveProblem : SymbolicDataAnalysisSingleObjectiveProblem<ITimeSeriesPrognosisProblemData, ISymbolicTimeSeriesPrognosisSingleObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, ITimeSeriesPrognosisProblem {
    33     private const double PunishmentFactor = 10;
    3433    private const int InitialMaximumTreeDepth = 8;
    3534    private const int InitialMaximumTreeLength = 25;
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SingleObjective/SymbolicTimeSeriesPrognosisSingleObjectiveTrainingBestSolutionAnalyzer.cs

    r7100 r7120  
    2020#endregion
    2121
     22using System.Linq;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    3435  [StorableClass]
    3536  public sealed class SymbolicTimeSeriesPrognosisSingleObjectiveTrainingBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer<ISymbolicTimeSeriesPrognosisSolution>,
    36   ISymbolicTimeSeriesPrognosisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator {
     37  ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator {
    3738    private const string ProblemDataParameterName = "ProblemData";
    38     private const string SymbolicTimeSeriesPrognosisInterpreterParameterName = "SymbolicTimeSeriesPrognosisInterpreter";
     39    private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter";
    3940    private const string EstimationLimitsParameterName = "EstimationLimits";
    4041    private const string ApplyLinearScalingParameterName = "ApplyLinearScaling";
     
    4344      get { return (ILookupParameter<ITimeSeriesPrognosisProblemData>)Parameters[ProblemDataParameterName]; }
    4445    }
    45     public ILookupParameter<ISymbolicTimeSeriesPrognosisInterpreter> SymbolicTimeSeriesPrognosisInterpreterParameter {
    46       get { return (ILookupParameter<ISymbolicTimeSeriesPrognosisInterpreter>)Parameters[SymbolicTimeSeriesPrognosisInterpreterParameterName]; }
     46    public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {
     47      get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; }
    4748    }
    4849    public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter {
     
    6667      : base() {
    6768      Parameters.Add(new LookupParameter<ITimeSeriesPrognosisProblemData>(ProblemDataParameterName, "The problem data for the symbolic regression solution."));
    68       Parameters.Add(new LookupParameter<ISymbolicTimeSeriesPrognosisInterpreter>(SymbolicTimeSeriesPrognosisInterpreterParameterName, "The symbolic time series prognosis interpreter for the symbolic expression tree."));
     69      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic time series prognosis interpreter for the symbolic expression tree."));
    6970      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic regression model."));
    7071      Parameters.Add(new ValueParameter<BoolValue>(ApplyLinearScalingParameterName, "Flag that indicates if the produced symbolic regression solution should be linearly scaled.", new BoolValue(true)));
     
    7576
    7677    protected override ISymbolicTimeSeriesPrognosisSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) {
    77       var model = new SymbolicTimeSeriesPrognosisModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicTimeSeriesPrognosisInterpreterParameter.ActualValue);
     78      var model = new SymbolicTimeSeriesPrognosisModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, ProblemDataParameter.ActualValue.TargetVariables.ToArray());
    7879      if (ApplyLinearScaling.Value)
    7980        SymbolicTimeSeriesPrognosisModel.Scale(model, ProblemDataParameter.ActualValue);
Note: See TracChangeset for help on using the changeset viewer.