Changeset 8468 for branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisAutoRegressiveModel.cs
- Timestamp:
- 08/10/12 15:58:36 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisAutoRegressiveModel.cs
r8458 r8468 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Core; … … 37 36 [Storable] 38 37 public string TargetVariable { get; private set; } 39 [Storable] 40 public int TimeOffset { get ; private set;}38 39 public int TimeOffset { get { return Phi.Length; } } 41 40 42 41 [StorableConstructor] … … 47 46 this.Constant = original.Constant; 48 47 this.TargetVariable = original.TargetVariable; 49 this.TimeOffset = original.TimeOffset;50 48 } 51 49 public override IDeepCloneable Clone(Cloner cloner) { 52 50 return new TimeSeriesPrognosisAutoRegressiveModel(this, cloner); 53 51 } 54 public TimeSeriesPrognosisAutoRegressiveModel( double alpha, double beta, string targetVariable)52 public TimeSeriesPrognosisAutoRegressiveModel(string targetVariable, double[] phi, double constant) 55 53 : base() { 56 //Alpha = alpha;57 //Beta = beta;54 Phi = (double[])phi.Clone(); 55 Constant = constant; 58 56 TargetVariable = targetVariable; 59 TimeOffset = 1;60 57 } 61 58 … … 63 60 var rowsEnumerator = rows.GetEnumerator(); 64 61 var horizonsEnumerator = horizons.GetEnumerator(); 65 var targetVa riables = dataset.GetReadOnlyDoubleValues(TargetVariable);62 var targetValues = dataset.GetReadOnlyDoubleValues(TargetVariable); 66 63 // produce a n-step forecast for all rows 67 64 while (rowsEnumerator.MoveNext() & horizonsEnumerator.MoveNext()) { … … 69 66 int horizon = horizonsEnumerator.Current; 70 67 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 73 81 yield return prognosis; 74 82 } … … 79 87 80 88 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 } 82 98 } 83 99
Note: See TracChangeset
for help on using the changeset viewer.