Exemple #1
0
        public void ShouldExtrapolateTwoPeriodsBackwardAndTwoPeriodsForward()
        {
            int period = 24;

            double[] data = new double[2 * period];
            double   dx   = 2 * Math.PI / period;

            for (int i = 0; i < data.Length; ++i)
            {
                int amplitude = 10 - i / period;
                data[i] = amplitude * Math.Sin(i * dx);
            }

            double[] extendedData = new double[6 * period];

            var sssmoother = new CyclicSubSeriesSmoother(7, 1, 1, data.Length, period, 2, 2);

            sssmoother.Smooth(data, extendedData, null);

            for (int i = 0; i < extendedData.Length; ++i)
            {
                int    amplitude = 12 - i / period; // Two extra for the extrapolation before.
                double value     = amplitude * Math.Sin(i * dx);
                Assert.AreEqual(extendedData[i], value, 1.0e-11, $"Test point {i}");
            }
        }
Exemple #2
0
        public void TrendingSinusoidExtrapolationTest()
        {
            int period = 24;

            double[] data = new double[2 * period];
            double   dx   = 2 * Math.PI / period;

            for (int i = 0; i < data.Length; ++i)
            {
                int amplitude = 10 - i / period;
                data[i] = amplitude * Math.Sin(i * dx);
            }

            double[] extendedData = new double[4 * period];

            var sssmoother = new CyclicSubSeriesSmoother(7, 1, 1, data.Length, period, 1, 1);

            sssmoother.Smooth(data, extendedData, null);

            for (int i = 0; i < extendedData.Length; ++i)
            {
                int    amplitude = 11 - i / period; // An extra for the extrapolation before.
                double value     = amplitude * Math.Sin(i * dx);
                Assert.AreEqual(extendedData[i], value, 1.0e-11, $"Test point {i}");
            }
        }
        /// <summary>
        /// Initialises a new instance.
        /// </summary>
        /// <param name="data">The data to be decomposed.</param>
        /// <param name="periodicity">The periodicity of the data.</param>
        /// <param name="cntInner">The number of inner iterations.</param>
        /// <param name="cntOuter">The number of outer &quot;robustness&quot;
        /// iterations.</param>
        /// <param name="seasonalSettings">The settings for the LOESS smoother
        /// for the cyclic sub-series.</param>
        /// <param name="trendSettings">The settings for the LOESS smoother for
        /// the trend component.</param>
        /// <param name="lowpassSettings">The settings for the LOESS smoother
        /// used in de-seasonalising.</param>
        public SeasonalTrendLoess(IList <double> data, int periodicity, int cntInner,
                                  int cntOuter, LoessSettings seasonalSettings,
                                  LoessSettings trendSettings, LoessSettings lowpassSettings)
        {
            _data = data;
            int size = data.Count;

            _periodLength         = periodicity;
            _seasonalSettings     = seasonalSettings;
            _trendSettings        = trendSettings;
            _lowpassSettings      = lowpassSettings;
            _innerIterations      = cntInner;
            _outerIterations      = cntOuter;
            _loessSmootherFactory = new LoessSmootherBuilder()
                                    .SetSettings(trendSettings);
            _lowpassLoessFactory = new LoessSmootherBuilder()
                                   .SetSettings(lowpassSettings);
            _cyclicSubSeriesSmoother = new CyclicSubSeriesSmoother(
                seasonalSettings, size, periodicity, 1, 1);
            _detrend          = new double[size];
            _extendedSeasonal = new double[size + 2 * _periodLength];
        }