///<summary> /// This function computes predictive means (one-step, two-step, ...) /// along with the predictive mean-squared error. It /// assumes that data is regularly spaced in time. ///</summary> ///<param name="startData">existing data that we assume comes from the model</param> ///<param name="futureTimes">times in the future</param> ///<returns></returns> private TimeSeriesBase <DistributionSummary> GetForecasts(TimeSeries startData, IList <DateTime> futureTimes) { // now do forecasting, using the standard Durbin-Levison Algorithm int nobs = startData.Count; int horizon = futureTimes.Count; // Numerically stable approach: use innovations algorithm if possible double[] nus; double[] forecs; ComputeSpecialResiduals(startData, out nus, horizon, out forecs); //// now compute MSEs of 1...horizon step predictors //// compute psis in causal expansion, //// by phi(B) (1-B)^d psi(B) = theta(B) and match coefficients // Vector psis = ComputePsiCoefficients(horizon); var psis = Vector <double> .Build.Dense(horizon + 1); // Use approximation (B&D eqn (5.3.24)) as before to get predictive variances var localFmse = Vector <double> .Build.Dense(horizon); localFmse[0] = 1.0; for (int i = 1; i < horizon; ++i) { localFmse[i] = localFmse[i - 1] + psis[i] * psis[i]; } localFmse = localFmse * Sigma * Sigma; var predictors = new TimeSeriesBase <DistributionSummary>(); for (int i = 0; i < horizon; ++i) { var dn = new DistributionSummary(); dn.Mean = forecs[i]; dn.Variance = localFmse[i]; // dn.FillGaussianQuantiles(0.04); predictors.Add(futureTimes[i], dn, false); } return(predictors); }
public override object BuildForecasts(object otherData, object inputs) { var futureTimes = inputs as List <DateTime>; if (futureTimes == null) { return(null); // need future times to forecast } var startData = otherData as TimeSeries; if (startData == null) { return(null); // need data to forecast } // Now we can forecast: // for ARMA models, we don't do any kind of analysis of the future times, we just // assume they are the next discrete time points in a typical ARMA model with // times t=1,2,3,...,n. So all we care about is the number of inputs. TimeSeriesBase <DistributionSummary> preds = GetForecasts(startData, futureTimes); return(preds); }