Accord.Tests.Math.GoldfarbIdnaniTest.RunTest3 C# (CSharp) Method

RunTest3() private method

private RunTest3 ( ) : void
return void
        public void RunTest3()
        {
            // Tested against R's QuadProg package
            /* solve.QP(matrix(c(10, -3,  1, -3, 11, -2, 1, -2, 12), 3, 3), c(1,5,3),
                     t(matrix( c(-4, 2, 1, -3, 1, -2, 0, -1, 2), 3,3)), c(-8,4,-1)) */

            double[,] D =
            {
                { 10, -3,  1 },
                { -3, 11, -2 },
                {  1, -2, 12 },
            };

            double[] d = { 1, 5, 3 };

            double[,] A = 
            {
                { -4,  2,  1 },
                { -3,  1, -2 },
                {  0, -1,  2 },
            };


            double[] b = { -8, 4, -1 };

            GoldfarbIdnani target = new GoldfarbIdnani(D, d.Multiply(-1), A.Transpose(), b);

            Assert.IsTrue(target.Minimize());
            double actual = target.Value;

            Assert.AreEqual(6.8, actual, 1e-5);
            Assert.IsFalse(double.IsNaN(actual));

            Assert.AreEqual(4, target.Iterations);
            Assert.AreEqual(0, target.Deletions);

            Assert.AreEqual(+1.4, target.Solution[0], 1e-6);
            Assert.AreEqual(+0.8, target.Solution[1], 1e-6);
            Assert.AreEqual(-0.4, target.Solution[2], 1e-6);

            Assert.AreEqual(2.5333333, target.Lagrangian[0], 1e-6);
            Assert.AreEqual(9.7333333, target.Lagrangian[1], 1e-6);
            Assert.AreEqual(0.8666667, target.Lagrangian[2], 1e-6);

            Assert.AreEqual(1, target.ActiveConstraints[0]);
            Assert.AreEqual(0, target.ActiveConstraints[1]);
            Assert.AreEqual(2, target.ActiveConstraints[2]);

            foreach (double v in target.Lagrangian)
                Assert.IsFalse(double.IsNaN(v));

            foreach (double v in target.Solution)
                Assert.IsFalse(double.IsNaN(v));
        }