public bool Forecast(int periodicityHint, List<double> data, int holdout, int range, string mode, double minValue, double maxValue, out IList<double> parameters, out IList<IScalarDistribution> forecast, out IList<double> residuals) { bool retval = false; parameters = null; forecast = null; residuals = null; int c_maxIter = 2; int fcastRange = 12; AAdArapidEventDetector modelBuilder = new AAdArapidEventDetector(periodicityHint); IList<EventImpactTrace> detectionHistory = null; bool fOK = modelBuilder.EventDetectionLoop(data, 0, c_maxIter, false, out detectionHistory); HoltWintersMultithreadedDimensionalityReduction forecaster = new HoltWintersMultithreadedDimensionalityReduction(periodicityHint); retval = forecaster.SingleThreadForecast(data, 0, fcastRange, "NONPARAMETRIC", 0.0, double.MaxValue, out parameters, out forecast, out residuals); return retval; }
static void Main(string[] args) { string filename = Environment.GetEnvironmentVariable("TSF_NET_DIR") + "Sample_Periodic\\NorwichTemp2.csv"; Dictionary<string, List<double>> inputData = ParseCSVRows(filename); ExcelApplicationWrapper excelApp = new ExcelApplicationWrapper(); excelApp.OpenExcel(); foreach (string q1 in inputData.Keys) { string strTab = q1 + ", trends"; if (strTab.Length > 30) { strTab = strTab.Substring(0, 30); } int c_maxIter = 2; List<DateTime> timeline = null; List<double> data = inputData[q1]; //Done extracting and aggregating data for query q1 int periodicityHint = 12; //Step1. Detect deviant patterns and outlying spikes //A slower much more precise model builder commented out here //AAdAdrWithShocks modelBuilder = new AAdAdrWithShocks(periodicityHint, 0.1, (List<int>) null, null); //modelBuilder.InterferenceLag = 12; AAdArapidEventDetector modelBuilder = new AAdArapidEventDetector(periodicityHint); IList<EventImpactTrace> detectionHistory = null; bool fOK = modelBuilder.EventDetectionLoop(data, 0, c_maxIter, false, out detectionHistory); int fcastRange = 12; IList<IScalarDistribution> fullForecast = null; HoltWintersMultithreadedDimensionalityReduction forecaster = new HoltWintersMultithreadedDimensionalityReduction(periodicityHint); IList<double> paramtrs = null; IList<double> residuals = null; try { //Example of "full service" forecast, with expected values and predict distributions forecaster.SingleThreadForecast(data, 0, fcastRange, "NONPARAMETRIC", 0.0, double.MaxValue, out paramtrs, out fullForecast, out residuals); } catch (Exception outerException) { } //Preparing for ... and using Excel middleware to generate Excel chart programmatically Dictionary<Timestamp, double> dictSigmas = null; Dictionary<Timestamp, double> dictMeans = null; List<Timestamp> timeIndex = null; MakeForecastOnlyDictionaries (data.Count, fullForecast, out timeIndex, out dictMeans, out dictSigmas); //Cosmetics tweak dictMeans.Add(new Timestamp(data.Count - 1), data.Last()); AddExcelChart(excelApp, detectionHistory.Last(), q1, MakeDataDictionary(timeIndex, data), dictMeans, dictSigmas); } //excelApp.CloseExcel(); //Uncomment to get the workbook closed automatically }