예제 #1
0
        public bool Import(string pathFile)
        {
            InitTraining();
            XmlDocument input = new XmlDocument();

            try
            {
                input.Load(pathFile);
                XmlNode root = input.FirstChild;
                //Get number of input, hidden, output nodes
                this._regularDifferencingLevel = Int32.Parse(root.SelectSingleNode("descendant::RegularDifferencing").InnerText);
                this._seasonDifferencingLevel  = Int32.Parse(root.SelectSingleNode("descendant::SeasonDifferencing").InnerText);
                this._seasonPartern            = Int32.Parse(root.SelectSingleNode("descendant::SeasonPartern").InnerText);
                this._pRegular = Int32.Parse(root.SelectSingleNode("descendant::ARRegular").InnerText);
                this._qRegular = Int32.Parse(root.SelectSingleNode("descendant::MARegular").InnerText);
                this._pSeason  = Int32.Parse(root.SelectSingleNode("descendant::ARSeason").InnerText);
                this._qSeason  = Int32.Parse(root.SelectSingleNode("descendant::MASeason").InnerText);

                string   arimaCoef     = root.SelectSingleNode("descendant::ARIMACoef").InnerText;
                string[] listArimaCoef = arimaCoef.Split('|');
                _listArimaCoef = new List <double>();
                foreach (string coef in listArimaCoef)
                {
                    double temp = Double.Parse(coef);
                    _listArimaCoef.Add(temp);
                }

                Statistic.ComputeDifference(ref _processARIMASeries, ref _startIndex, _regularDifferencingLevel, _seasonDifferencingLevel, _seasonPartern);
                //ComputTrainingError(_processARIMASeries, _startIndex, _regularDifferencingLevel, _seasonDifferencingLevel, _pRegular, _qRegular, _seasonPartern, _pSeason, _qSeason, _listArimaCoef, out _errorARIMASeries);
            }
            catch
            {
            }
            return(true);
        }
예제 #2
0
        public void ManualTraining(int pRegular, int regularDifferencing, int qRegular, int pSeason, int seassonDifferencing, int qSeason, int seasonPartern)
        {
            InitTraining();
            this._regularDifferencingLevel = regularDifferencing;
            this._pRegular = pRegular;
            this._qRegular = qRegular;
            this._pSeason  = pSeason;
            this._qSeason  = qSeason;
            this._seasonDifferencingLevel = seassonDifferencing;
            this._seasonPartern           = seasonPartern;

            Statistic.ComputeDifference(ref _processARIMASeries, ref _startIndex, _regularDifferencingLevel, _seasonDifferencingLevel, _seasonPartern);
            EstimateARIMACoef(_processARIMASeries, _startIndex, _pRegular, _qRegular, _seasonPartern, _pSeason, _qSeason, out _listArimaCoef);

            List <double> trainingResultSeries = new List <double>();

            ComputeTrainingResultData(_processARIMASeries, 0, _regularDifferencingLevel, _seasonDifferencingLevel, _pRegular, _qRegular, _seasonPartern, _pSeason, _qSeason, _listArimaCoef, out trainingResultSeries);
            List <double> currentARIMASeries = _processARIMASeries.FindAll(item => true);
            int           startIndexTraining = _startIndex;

            RevertDiffTestSeries(ref currentARIMASeries, ref trainingResultSeries, ref startIndexTraining, _regularDifferencingLevel, _seasonDifferencingLevel, _seasonPartern);
            _errorARIMASeries = new List <double>();
            for (int i = 0; i < _originARIMASeries.Count; i++)
            {
                _errorARIMASeries.Add(_originARIMASeries[i] - trainingResultSeries[i]);
            }
            //ComputTrainingError(_processARIMASeries, _startIndex, _regularDifferencingLevel, _seasonDifferencingLevel, _pRegular, _qRegular, _seasonPartern, _pSeason, _qSeason, _listArimaCoef, out _errorARIMASeries);
        }
예제 #3
0
        private void ForecastARIMA(List <double> timeSeries, int regularDifferencingLevel, int seasonDifferencingLevel, int pRegular, int qRegular, int seasonPartern, int pSeason, int qSeason, List <double> listArimaCoeff, int nHead, out List <double> forecastSeries)
        {
            List <double> currentSeries      = timeSeries.FindAll(item => true);
            List <double> currentErrors      = new List <double>();
            List <double> currentResults     = new List <double>();
            int           startIndexForecast = 0;

            Statistic.ComputeDifference(ref currentSeries, ref startIndexForecast, _regularDifferencingLevel, _seasonDifferencingLevel, _seasonPartern);

            int begin = ComputeMax(pRegular, qRegular, pSeason * seasonPartern, qSeason * seasonPartern, startIndexForecast);

            for (int i = 0; i < begin; i++)
            {
                currentResults.Add(currentSeries[i]);
                currentErrors.Add(0);
            }
            for (int i = begin; i < currentSeries.Count; i++)
            {
                double temp = listArimaCoeff[0];

                for (int j = 1; j <= pRegular; j++)
                {
                    temp += currentSeries[i - j] * listArimaCoeff[j];
                }

                for (int j = 1; j <= pSeason; j++)
                {
                    temp += currentSeries[i - j * seasonPartern] * listArimaCoeff[pRegular + qRegular + j];
                }

                currentResults.Add(temp);
                currentErrors.Add(timeSeries[i] - currentSeries[i]);
            }

            for (int i = 0; i < nHead; i++)
            {
                double temp = listArimaCoeff[0];

                for (int j = 1; j <= pRegular; j++)
                {
                    temp += currentSeries[timeSeries.Count + i - j] * listArimaCoeff[j];
                }

                for (int j = 1; j <= pSeason; j++)
                {
                    temp += currentSeries[timeSeries.Count + i - j * seasonPartern] * listArimaCoeff[pRegular + qRegular + j];
                }

                currentResults.Add(temp);
                currentSeries.Add(temp);
                currentErrors.Add(timeSeries[i] - currentSeries[i]);
            }
            RevertDiffTestSeries(ref currentSeries, ref currentResults, ref startIndexForecast, regularDifferencingLevel, seasonDifferencingLevel, seasonPartern);
            forecastSeries = new List <double>();
            for (int i = 0; i < nHead; i++)
            {
                forecastSeries.Add(currentSeries[timeSeries.Count + i]);
            }
        }
예제 #4
0
 public void RemoveTrendSeasonality(int regularDifferencingLevel, int seasonDifferencingLevel, int seasonPartern)
 {
     InitTraining();
     _regularDifferencingLevel = regularDifferencingLevel;
     _seasonDifferencingLevel  = seasonDifferencingLevel;
     _seasonPartern            = seasonPartern;
     Statistic.ComputeDifference(ref _processARIMASeries, ref _startIndex, _regularDifferencingLevel, _seasonDifferencingLevel, _seasonPartern);
 }
예제 #5
0
        public void ComputeTestingResult(List <double> testDataSeries, out List <double> testResultSeries)
        {
            List <double> testDataSeriesProcessed = testDataSeries.FindAll(item => true);

            testResultSeries = new List <double>();
            int startIndexTest = 0;

            Statistic.ComputeDifference(ref testDataSeriesProcessed, ref startIndexTest, _regularDifferencingLevel, _seasonDifferencingLevel, _seasonPartern);
            ComputeTrainingResultData(testDataSeriesProcessed, startIndexTest, _regularDifferencingLevel, _seasonDifferencingLevel, _pRegular, _qRegular, _seasonPartern, _pSeason, _qSeason, _listArimaCoef, out testResultSeries);
            RevertDiffTestSeries(ref testDataSeriesProcessed, ref testResultSeries, ref startIndexTest, _regularDifferencingLevel, _seasonDifferencingLevel, _seasonPartern);
        }