Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/10/12 15:58:36 (12 years ago)
Author:
mkommend
Message:

#1081: Adapated calculation of results for horizons larger than 1.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisAutoRegressiveModel.cs

    r8458 r8468  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Core;
     
    3736    [Storable]
    3837    public string TargetVariable { get; private set; }
    39     [Storable]
    40     public int TimeOffset { get; private set; }
     38
     39    public int TimeOffset { get { return Phi.Length; } }
    4140
    4241    [StorableConstructor]
     
    4746      this.Constant = original.Constant;
    4847      this.TargetVariable = original.TargetVariable;
    49       this.TimeOffset = original.TimeOffset;
    5048    }
    5149    public override IDeepCloneable Clone(Cloner cloner) {
    5250      return new TimeSeriesPrognosisAutoRegressiveModel(this, cloner);
    5351    }
    54     public TimeSeriesPrognosisAutoRegressiveModel(double alpha, double beta, string targetVariable)
     52    public TimeSeriesPrognosisAutoRegressiveModel(string targetVariable, double[] phi, double constant)
    5553      : base() {
    56       //Alpha = alpha;
    57       //Beta = beta;
     54      Phi = (double[])phi.Clone();
     55      Constant = constant;
    5856      TargetVariable = targetVariable;
    59       TimeOffset = 1;
    6057    }
    6158
     
    6360      var rowsEnumerator = rows.GetEnumerator();
    6461      var horizonsEnumerator = horizons.GetEnumerator();
    65       var targetVariables = dataset.GetReadOnlyDoubleValues(TargetVariable);
     62      var targetValues = dataset.GetReadOnlyDoubleValues(TargetVariable);
    6663      // produce a n-step forecast for all rows
    6764      while (rowsEnumerator.MoveNext() & horizonsEnumerator.MoveNext()) {
     
    6966        int horizon = horizonsEnumerator.Current;
    7067        double[] prognosis = new double[horizon];
    71         for (int i = 0; i < horizon; i++)
    72           prognosis[i] = targetVariables[row - TimeOffset];
     68
     69        for (int h = 0; h < horizon; h++) {
     70          double estimatedValue = 0.0;
     71          for (int i = 1; i < TimeOffset; i++) {
     72            int offset = h - i;
     73            if (offset >= 0) estimatedValue += prognosis[offset] * Phi[i - 1];
     74            else estimatedValue += targetValues[row + offset] * Phi[i - 1];
     75
     76          }
     77          estimatedValue += Constant;
     78          prognosis[h] = estimatedValue;
     79        }
     80
    7381        yield return prognosis;
    7482      }
     
    7987
    8088    public IEnumerable<double> GetEstimatedValues(Dataset dataset, IEnumerable<int> rows) {
    81       return GetPrognosedValues(dataset, rows, rows.Select(r => 1)).SelectMany(e => e);
     89      var targetVariables = dataset.GetReadOnlyDoubleValues(TargetVariable);
     90      foreach (int row in rows) {
     91        double estimatedValue = 0.0;
     92        for (int i = 1; i <= TimeOffset; i++) {
     93          estimatedValue += targetVariables[row - i] * Phi[i - 1];
     94        }
     95        estimatedValue += Constant;
     96        yield return estimatedValue;
     97      }
    8298    }
    8399
Note: See TracChangeset for help on using the changeset viewer.