private void RemoveNonstationarity(ref List <double> series, ref int startIndex, out int regularDifferencingLevel) { int dataSize = series.Count - startIndex; List <double> listAutocorrelation = new List <double>(); List <double> listConfidenceLimit = new List <double>(); regularDifferencingLevel = 0; while (true) { listAutocorrelation.Clear(); listConfidenceLimit.Clear(); dataSize = series.Count - startIndex; Statistic.ComputeAutocorrelation(series, startIndex, out listAutocorrelation); Statistic.ComputeConfidenceLimit(listAutocorrelation, dataSize, out listConfidenceLimit); //DrawSeriesData(series, startIndex); //DrawAutocorrelation(listAutocorrelation, listConfidenceLimit); DecayPartern decayPartern = ComputeDecayPartern(listAutocorrelation, listConfidenceLimit); if (decayPartern != DecayPartern.SLOW_DECAY) { break; } startIndex += 1; regularDifferencingLevel++; for (int j = series.Count - 1; j >= startIndex; j--) { series[j] = series[j] - series[j - 1]; } } }
private void RemoveSeasonality(ref List <double> processSeries, ref int startIndex, out int seasonPartern, out int seasonDifferencingLevel) { seasonPartern = 0; seasonDifferencingLevel = 0; List <double> listAutocorrelation = new List <double>(); List <double> listConfidenceLimit = new List <double>(); List <int> levelLocation = new List <int>(); while (true) { listAutocorrelation.Clear(); Statistic.ComputeAutocorrelation(processSeries, startIndex, out listAutocorrelation); Statistic.ComputeConfidenceLimit(listAutocorrelation, processSeries.Count - startIndex, out listConfidenceLimit); //DrawSeriesData(series, startIndex); //DrawAutocorrelation(listAutocorrelation, listConfidenceLimit); int newSeasonPartern; EstimateSeasonPartern(listAutocorrelation, listConfidenceLimit, out newSeasonPartern); if (newSeasonPartern == 0 || (seasonPartern != 0 && newSeasonPartern != seasonPartern)) { break; } seasonPartern = newSeasonPartern; seasonDifferencingLevel++; startIndex += seasonPartern; for (int j = processSeries.Count - 1; j >= startIndex; j--) { processSeries[j] = processSeries[j] - processSeries[j - seasonPartern]; } } }
public void DrawAutocorrelation() { List <double> listAutocorrelation; List <double> listConfidenceLimit; Statistic.ComputeAutocorrelation(_processARIMASeries, _startIndex, out listAutocorrelation); Statistic.ComputeConfidenceLimit(listAutocorrelation, _processARIMASeries.Count, out listConfidenceLimit); Statistic.DrawAutocorrelation(listAutocorrelation, listConfidenceLimit); }
private void IdentifyARIMAModel(List <double> series, int startIndex, int seasonPartern, out int pRegular, out int qRegular, out int pSeason, out int qSeason) { pRegular = qRegular = pSeason = qSeason = 0; List <double> listAutocorrelation = new List <double>(); List <double> listConfidenceLimit = new List <double>(); List <double> listPartialAutocorrelation = new List <double>(); List <double> listSeasonAutocorrelation = new List <double>(); List <double> listSeasonConfidenceLimit = new List <double>(); List <double> listSeasonPartialCorrelation = new List <double>(); List <double> listRegularAutocorrelation = new List <double>(); List <double> listRegularConfidenceLimit = new List <double>(); List <double> listRegularPartialCorrelation = new List <double>(); Statistic.ComputeAutocorrelation(series, startIndex, out listAutocorrelation); Statistic.ComputePartialAutocorrelation(listAutocorrelation, out listPartialAutocorrelation); Statistic.ComputeConfidenceLimit(listAutocorrelation, series.Count - startIndex, out listConfidenceLimit); double confidenceLimit = 1.96 / Math.Sqrt(series.Count - startIndex); int regularAutocorrelationLengh = seasonPartern; if (seasonPartern == 0) { regularAutocorrelationLengh = listAutocorrelation.Count; } for (int i = 0; i < regularAutocorrelationLengh; i++) { listRegularAutocorrelation.Add(listAutocorrelation[i]); listRegularConfidenceLimit.Add(listConfidenceLimit[i]); listRegularPartialCorrelation.Add(listPartialAutocorrelation[i]); } //Algorithm.DrawAutocorrelation(listRegularAutocorrelation, listRegularConfidenceLimit); //Algorithm.DrawPartialAutocorrelation(listRegularPartialCorrelation, confidenceLimit); DecayPartern decayACF = ComputeDecayPartern(listRegularAutocorrelation, listRegularConfidenceLimit); DecayPartern decayPACF = ComputeDecayPartern(listRegularPartialCorrelation, confidenceLimit); if (decayACF == DecayPartern.ABRUPT_DECAY) { GetLastSignificant(listRegularAutocorrelation, listRegularConfidenceLimit, out qRegular); } if (decayPACF == DecayPartern.ABRUPT_DECAY) { GetLastSignificant(listRegularPartialCorrelation, confidenceLimit, out pRegular); } if (decayACF != DecayPartern.ABRUPT_DECAY && decayPACF != DecayPartern.ABRUPT_DECAY) { pRegular = qRegular = 2; } pRegular = Math.Min(pRegular, Configuration.MAX_REGULAR_ARMA_ORDER); qRegular = Math.Min(qRegular, Configuration.MAX_REGULAR_ARMA_ORDER); if (seasonPartern == 0) { return; } for (int i = 0; i < Math.Floor(1.0 * listAutocorrelation.Count / seasonPartern); i++) { listSeasonAutocorrelation.Add(listAutocorrelation[i * seasonPartern]); listSeasonConfidenceLimit.Add(listConfidenceLimit[i * seasonPartern]); listSeasonPartialCorrelation.Add(listPartialAutocorrelation[i * seasonPartern]); } //Algorithm.DrawAutocorrelation(listSeasonAutocorrelation, listSeasonConfidenceLimit); //Algorithm.DrawPartialAutocorrelation(listSeasonPartialCorrelation, confidenceLimit); DecayPartern decaySeasonACF = ComputeDecayPartern(listSeasonAutocorrelation, listSeasonConfidenceLimit); DecayPartern decaySeasonPACF = ComputeDecayPartern(listSeasonPartialCorrelation, confidenceLimit); if (decaySeasonACF == DecayPartern.ABRUPT_DECAY) { GetLastSignificant(listSeasonAutocorrelation, listSeasonConfidenceLimit, out qSeason); } if (decaySeasonPACF == DecayPartern.ABRUPT_DECAY) { GetLastSignificant(listSeasonPartialCorrelation, confidenceLimit, out pSeason); } if (decaySeasonACF != DecayPartern.ABRUPT_DECAY && decaySeasonPACF != DecayPartern.ABRUPT_DECAY) { pSeason = qSeason = 1; } pSeason = Math.Min(pSeason, Configuration.MAX_SEASON_ARMA_ORDER); qSeason = Math.Min(qSeason, Configuration.MAX_SEASON_ARMA_ORDER); }