Example #1
0
        public void DetectModelChange()
        {
            // change underlying model and see if it adapts
            var model    = new ARModel(0, new double[] { 0.5 });
            var detector = new TournamentArtifactDetector(3, 1000, 1, 1);
            var r        = new Random(12345);
            var last     = 10 * r.NextDouble();

            // extra 2 to ensure underlying ARArtifactDetector is primed
            for (int i = 0; i < 1002; i++)
            {
                Assert.False(detector.Detect(last));
                last = model.Predict(last) + 10 * r.NextDouble();
            }

            model = new ARModel(100, new double[] { 0.5 });
            for (int i = 0; i < 1000; i++)
            {
                detector.Detect(last);
                last = model.Predict(last) + 10 * r.NextDouble();
            }

            for (int i = 0; i < 100; i++)
            {
                Assert.False(detector.Detect(last));
                last = model.Predict(last) + 10 * r.NextDouble();
            }
        }
Example #2
0
        public void ARModelPredict()
        {
            var ar1 = new ARModel(0, new double[] { 0.5 });
            var X   = new double[] {
                1,
                1,
                1.0 * 0.5,
                1.0 * 0.5 * 0.5,
                1.0 * 0.5 * 0.5 * 0.5,
                1.0 * 0.5 * 0.5 * 0.5 * 0.5,
            };

            for (int i = 0; i < X.Length - 1; i++)
            {
                Assert.AreEqual(X[i + 1], ar1.Predict(X[i]));
            }

            var ar2 = new ARModel(0, new double[] { 0.3, 0.3 });

            X = new double[] {
                1,
                1,
                1,
                0.6,
                0.48,
                0.324,
                0.2412,
                0.16956,
            };

            for (int i = 0; i < X.Length - 1; i++)
            {
                IsWithinThreshold(X[i + 1], ar2.Predict(X[i]));
            }
        }
Example #3
0
        public void DetectNormal()
        {
            var model    = new ARModel(0, new double[] { 0.5 });
            var detector = new TournamentArtifactDetector(1, 1000, 1, 100);
            var r        = new Random(12345);
            var last     = r.NextDouble();

            // prime detector
            for (int i = 0; i < 1005; i++)
            {
                detector.Detect(last);
                last = model.Predict(last) + r.NextDouble();
            }

            //last = model.Predict(last) + r.NextDouble();
            for (int i = 0; i < 10; i++)
            {
                Assert.False(detector.Detect(last));
                last = model.Predict(last) + r.NextDouble();
            }
        }
Example #4
0
        public void DetectNormal()
        {
            var generator  = new ARModel(0, new double[] { 1 });
            var arDetector = new ARArtifactDetector(generator);

            double last = 1.0;

            for (int i = 0; i < 1000; i++)
            {
                var next = generator.Predict(last);
                Assert.False(arDetector.Detect(next));
                last = next;
            }
        }
Example #5
0
        public void DetectArtifact()
        {
            var model    = new ARModel(0, new double[] { 0.5 });
            var detector = new TournamentArtifactDetector(1, 1000, 1, 1);
            var r        = new Random(12345);
            var last     = 10 * r.NextDouble();

            // extra 2 to ensure underlying ARArtifactDetector is primed
            for (int i = 0; i < 1002; i++)
            {
                Assert.False(detector.Detect(last));
                last = model.Predict(last) + 10 * r.NextDouble();
            }

            // high-amplitude artifact for 100 samples
            for (int i = 0; i < 100; i++)
            {
                Assert.True(detector.Detect(last + 1000));
            }
        }