Accord.Tests.MachineLearning.DynamicalTimeWarpingTest.DynamicalTimeWarpingConstructorTest C# (CSharp) Method

DynamicalTimeWarpingConstructorTest() private method

private DynamicalTimeWarpingConstructorTest ( ) : void
return void
        public void DynamicalTimeWarpingConstructorTest()
        {
            double[][] sequences = 
            {
                new double[] // -1
                {
                    0, 0, 0,
                    1, 1, 1,
                    2, 2, 2,
                },

                new double[] // -1
                {
                     0, 1, 0,
                     0, 2, 0,
                     0, 3, 0
                },

                new double[] // +1
                {
                     1, 1, 0,
                     1, 2, 0,
                     2, 1, 0,
                },

                new double[] // +1
                {
                     0, 0, 1, 
                     0, 0, 2, 
                     0, 1, 3,
                },
            };

            int[] outputs = { -1, -1, +1, +1 };


            // Set the parameters of the kernel
            double alpha = 0.85;
            int innerVectorLength = 3;


            // Create the kernel. Note that the input vector will be given out automatically
            DynamicTimeWarping target = new DynamicTimeWarping(innerVectorLength, alpha);



            // When using variable-length kernels, specify 0 as the input length.
            KernelSupportVectorMachine svm = new KernelSupportVectorMachine(target, 0);

            // Create the Sequential Minimal Optimization as usual
            SequentialMinimalOptimization smo = new SequentialMinimalOptimization(svm, sequences, outputs);
            smo.Complexity = 1.5;
            double error = smo.Run();


            // Computing the training values
            var a0 = svm.Compute(sequences[0]);
            var a1 = svm.Compute(sequences[1]);
            var a2 = svm.Compute(sequences[2]);
            var a3 = svm.Compute(sequences[3]);

            Assert.AreEqual(-1, System.Math.Sign(a0)); 
            Assert.AreEqual(-1, System.Math.Sign(a1));
            Assert.AreEqual(+1, System.Math.Sign(a2));
            Assert.AreEqual(+1, System.Math.Sign(a3));



            // Computing a new testing value
            double[] test =
            {
                1, 0, 1,
                0, 0, 2,
                0, 1, 3,
            };

            var a4 = svm.Compute(test);

            Assert.AreEqual(+1, System.Math.Sign(a4));
        }