Accord.Tests.MachineLearning.SequentialMinimalOptimizationTest.learn_sparse_kernel C# (CSharp) Method

learn_sparse_kernel() private method

private learn_sparse_kernel ( ) : void
return void
        public void learn_sparse_kernel()
        {
            #region doc_xor_sparse
            // As an example, we will try to learn a decision machine 
            // that can replicate the "exclusive-or" logical function:

            Sparse<double>[] inputs =
            {
                Sparse.FromDense(new double[] { 0, 0 }), // the XOR function takes two booleans
                Sparse.FromDense(new double[] { 0, 1 }), // and computes their exclusive or: the
                Sparse.FromDense(new double[] { 1, 0 }), // output is true only if the two booleans
                Sparse.FromDense(new double[] { 1, 1 })  // are different
            };

            int[] xor = // this is the output of the xor function
            {
                0, // 0 xor 0 = 0 (inputs are equal)
                1, // 0 xor 1 = 1 (inputs are different)
                1, // 1 xor 0 = 1 (inputs are different)
                0, // 1 xor 1 = 0 (inputs are equal)
            };

            // Now, we can create the sequential minimal optimization teacher
            var learn = new SequentialMinimalOptimization<Gaussian, Sparse<double>>()
            {
                UseComplexityHeuristic = true,
                UseKernelEstimation = true
            };

            // And then we can obtain a trained SVM by calling its Learn method
            var svm = learn.Learn(inputs, xor);

            // Finally, we can obtain the decisions predicted by the machine:
            bool[] prediction = svm.Decide(inputs);
            #endregion

            Assert.AreEqual(prediction, Classes.Decide(xor));
        }