Accord.Tests.Statistics.PartialLeastSquaresAnalysisTest.NipalsComputeTest3_new_method C# (CSharp) Method

NipalsComputeTest3_new_method() private method

private NipalsComputeTest3_new_method ( ) : void
return void
        public void NipalsComputeTest3_new_method()
        {
            // Example data from  P. Geladi and B.R. Kowalski, "An example of 2-block
            //   predictive partial least-squares regression with simulated data",
            //   Analytica Chemica Acta, 185(1996) 19--32, as given by Yi Cao in his
            //   excellent PLS tutorial.

            double[][] x = 
            {
                new double[] { 4,   9,  6,  7,  7,  8,  3,  2 },
                new double[] { 6,  15, 10, 15, 17, 22,  9,  4 },
                new double[] { 8,  21, 14, 23, 27, 36, 15,  6 },
                new double[] { 10, 21, 14, 13, 11, 10,  3,  4 },
                new double[] { 12, 27, 18, 21, 21, 24,  9,  6 },
                new double[] { 14, 33, 22, 29, 31, 38, 15,  8 },
                new double[] { 16, 33, 22, 19, 15, 12,  3,  6 },
                new double[] { 18, 39, 26, 27, 25, 26,  9,  8 },
                new double[] { 20, 45, 30, 35, 35, 40, 15, 10 }
            };

            double[][] y = 
            {
                new double[] { 1, 1 },
                new double[] { 3, 1 },
                new double[] { 5, 1 },
                new double[] { 1, 3 },
                new double[] { 3, 3 },
                new double[] { 5, 3 },
                new double[] { 1, 5 },
                new double[] { 3, 5 },
                new double[] { 5, 5 }
            };


            var pls = new PartialLeastSquaresAnalysis(
                AnalysisMethod.Center, PartialLeastSquaresAlgorithm.NIPALS);

            var regression = pls.Learn(x, y);


            double[,] eYL = 
            { 
                { 0.808248528018965, -0.588841504103759},
                { 0.588841504103759,  0.808248528018964}
            };

            double[,] eYS = 
            { 
                { -2.79418006424545,   -0.438814047830411 },
                { -1.17768300820752,   -1.61649705603793  },
                {  0.438814047830411,  -2.79418006424545  },
                { -1.61649705603793,	1.17768300820752  },
                {  0.00000000000000,	0.00000000000     },
                {  1.61649705603793,   -1.17768300820752  },
                { -0.438814047830411,	2.79418006424545  },
                {  1.17768300820752,    1.61649705603793  },
                {  2.79418006424545,    0.438814047830411 }
            };


            double[] eProportionsX = { 0.82623088878551032, 0.17376911121448976, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00 };
            double[] eProportionsY = { 0.50000000000000033, 0.50000000000000011, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00 };


            double[,] aXL = pls.Predictors.FactorMatrix.ToMatrix();
            double[,] aYL = pls.Dependents.FactorMatrix.ToMatrix();
            double[,] aXS = pls.Predictors.Result;
            double[,] aYS = pls.Dependents.Result;
            double[][] aW = pls.Weights;

            double[,] aB = regression.Coefficients;
            double[] aC = regression.Intercepts;



            for (int i = 0; i < eProportionsX.Length; i++)
            {
                Assert.AreEqual(eProportionsX[i], pls.Predictors.FactorProportions[i], 0.01);
                Assert.AreEqual(eProportionsY[i], pls.Dependents.FactorProportions[i], 0.01);
            }



            for (int i = 0; i < eYL.GetLength(0); i++)
                for (int j = 0; j < eYL.GetLength(1); j++)
                    Assert.AreEqual(aYL[i, j], eYL[i, j], 0.01);

            for (int i = 0; i < eYS.GetLength(0); i++)
                for (int j = 0; j < eYS.GetLength(1); j++)
                    Assert.AreEqual(aYS[i, j], eYS[i, j], 0.01);

        }