Exemple #1
0
        /// <summary>
        /// Test with a linear series differenced
        /// </summary>
        /// <remarks> This series continually extends its range.
        /// D1fferencing produces more accurate results.
        /// This is also an interesting test because all the differences are the same.
        /// It thus represents an extreme set of cirumstances that must be handled.</remarks>
        public void TestPredictLinearDifferenced()
        {
            double[] linear = new double[1000];
            linear[0] = 0.1;
            for (int n = 1; n < 1000; n++)
            {
                linear[n] = linear[n - 1] + 1.0;
            }
            ChaosAnalysis analysis = new ChaosAnalysis();

            analysis.differencing = true;
            TimeSpan sampleTime = new TimeSpan(0, 0, 1);

            analysis.LoadSampledData(linear, DateTime.Now, sampleTime);
            Assert.IsTrue(analysis.CalculateMeasures(true, false, true));
            linear[0] = linear[linear.Length - 1];
            double error = 0.0;

            for (int n = 1; n < 1000; n++)
            {
                linear[n] = linear[n - 1] + 1.0;
                double[] result = analysis.Predict(1, analysis.latest);
                analysis.AddDataPointRelative(linear[n], sampleTime);
                //we're predicting the difference, so relative to last
                double diff = linear[n] - (result[0] + linear[n - 1]);
                error += diff * diff;
            }
            error = Math.Sqrt(error / 1000);
            Assert.AreEqual(0.0, error, 0.01);
        }
Exemple #2
0
        public void TestPredictLogisticWithPredictNext()
        {
            double[] logistic = new double[1000];
            logistic[0] = 0.1;
            for (int n = 1; n < 1000; n++)
            {
                logistic[n] = 4.0 * logistic[n - 1] * (1.0 - logistic[n - 1]);
            }
            ChaosAnalysis analysis   = new ChaosAnalysis();
            TimeSpan      sampleTime = new TimeSpan(0, 0, 1);

            analysis.LoadSampledData(logistic, DateTime.Now, sampleTime);
            Assert.IsTrue(analysis.CalculateMeasures(true, false, true));
            logistic[0] = logistic[logistic.Length - 1];
            double error = 0.0;

            for (int n = 1; n < 1000; n++)
            {
                logistic[n] = 4.0 * logistic[n - 1] * (1.0 - logistic[n - 1]);
                double[] result;
                if (n == 1)
                {
                    result = analysis.Predict(1, analysis.latest);
                }
                else
                {
                    result = analysis.PredictNext(1, analysis.latest);
                }
                analysis.AddDataPointRelative(logistic[n], sampleTime);
                double diff = logistic[n] - result[0];
                error += diff * diff;
            }
            error = Math.Sqrt(error / 1000);
            Assert.AreEqual(0.00403954, error, 0.001);
        }