Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisAutoRegressiveModel.cs @ 8430

Last change on this file since 8430 was 8430, checked in by mkommend, 12 years ago

#1081: Intermediate commit of trunk updates - interpreter changes must be redone.

File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Problems.DataAnalysis {
29  [StorableClass]
30  [Item("Autoregressive TimeSeries Model", "A linear autoregressive time series model used to predict future values.")]
31  public class TimeSeriesPrognosisAutoRegressiveModel : NamedItem, ITimeSeriesPrognosisModel {
32    [Storable]
33    public double[] Phi { get; private set; }
34    [Storable]
35    public double Constant { get; private set; }
36    [Storable]
37    public string TargetVariable { get; private set; }
38    [Storable]
39    public int TimeOffset { get; private set; }
40
41    [StorableConstructor]
42    protected TimeSeriesPrognosisAutoRegressiveModel(bool deserializing) : base(deserializing) { }
43    protected TimeSeriesPrognosisAutoRegressiveModel(TimeSeriesPrognosisAutoRegressiveModel original, Cloner cloner)
44      : base(original, cloner) {
45      this.Phi = (double[])original.Phi.Clone();
46      this.Constant = original.Constant;
47      this.TargetVariable = original.TargetVariable;
48      this.TimeOffset = original.TimeOffset;
49    }
50    public override IDeepCloneable Clone(Cloner cloner) {
51      return new TimeSeriesPrognosisAutoRegressiveModel(this, cloner);
52    }
53    public TimeSeriesPrognosisAutoRegressiveModel(double alpha, double beta, string targetVariable)
54      : base() {
55      //Alpha = alpha;
56      //Beta = beta;
57      TargetVariable = targetVariable;
58      TimeOffset = 1;
59    }
60
61    public IEnumerable<IEnumerable<double>> GetPrognosedValues(Dataset dataset, IEnumerable<int> rows, IEnumerable<int> horizons) {
62      var rowsEnumerator = rows.GetEnumerator();
63      var horizonsEnumerator = horizons.GetEnumerator();
64      // produce a n-step forecast for all rows
65      while (rowsEnumerator.MoveNext() & horizonsEnumerator.MoveNext()) {
66        int row = rowsEnumerator.Current;
67        int horizon = horizonsEnumerator.Current;
68        double[] prognosis = new double[horizon];
69
70        prognosis[0] = dataset.GetDoubleValue(TargetVariable, row - TimeOffset);
71        for (int i = 1; i < horizon; i++) {
72          //prognosis[i] = Beta * prognosis[i - 1] + Alpha;
73        }
74        yield return prognosis;
75      }
76
77      if (rowsEnumerator.MoveNext() || horizonsEnumerator.MoveNext())
78        throw new ArgumentException("Number of elements in rows and horizon enumerations doesn't match.");
79    }
80
81    public ITimeSeriesPrognosisSolution CreateTimeSeriesPrognosisSolution(ITimeSeriesPrognosisProblemData problemData) {
82      return new TimeSeriesPrognosisSolution(this, problemData);
83    }
84
85  }
86}
Note: See TracBrowser for help on using the repository browser.