Accord.Tests.Statistics.PartialLeastSquaresAnalysisTest.NipalsComputeTest_new_method C# (CSharp) Метод

NipalsComputeTest_new_method() приватный Метод

private NipalsComputeTest_new_method ( ) : void
Результат void
        public void NipalsComputeTest_new_method()
        {
            double[][] X = 
            {
                new double[] { 2.5, 2.4 },
                new double[] { 0.5, 0.7 },
                new double[] { 2.2, 2.9 },
                new double[] { 1.9, 2.2 },
                new double[] { 3.1, 3.0 },
                new double[] { 2.3, 2.7 },
                new double[] { 2.0, 1.6 },
                new double[] { 1.0, 1.1 },
                new double[] { 1.5, 1.6 },
                new double[] { 1.1, 0.9 },
            };

            double[][] Y = 
            {
                new double[] { 1 },
                new double[] { 0 },
                new double[] { 1 },
                new double[] { 0 },
                new double[] { 1 },
                new double[] { 1 },
                new double[] { 0 },
                new double[] { 0 },
                new double[] { 0 },
                new double[] { 0 },
            };


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

            double[][] X0 = X.Copy();
            double[][] Y0 = Y.Copy();

            target.Learn(X, Y);

            double[,] x1 = Matrix.Multiply(target.Predictors.Result,
                target.Predictors.FactorMatrix.Transpose().ToMatrix()).Add(Measures.Mean(X, dimension: 0), 0);
            double[,] y1 = Matrix.Multiply(target.Dependents.Result,
                target.Dependents.FactorMatrix.Transpose().ToMatrix()).Add(Measures.Mean(Y, dimension: 0), 0);


            // XS*XL' ~ X0
            Assert.IsTrue(Matrix.IsEqual(x1, X, 0.01));

            // XS*YL' ~ Y0
            Assert.IsTrue(Matrix.IsEqual(y1, Y, 0.60));


            // ti' * tj = 0; 
            double[][] t = target.scoresX;
            for (int i = 0; i < t.Columns(); i++)
            {
                for (int j = 0; j < t.Columns(); j++)
                {
                    if (i != j)
                        Assert.AreEqual(0, t.GetColumn(i).InnerProduct(t.GetColumn(j)), 0.01);
                }
            }

            // wi' * wj = 0;
            double[][] w = target.Weights;
            for (int i = 0; i < w.Columns(); i++)
            {
                for (int j = 0; j < w.Columns(); j++)
                {
                    if (i != j)
                        Assert.AreEqual(0, w.GetColumn(i).InnerProduct(w.GetColumn(j)), 0.01);
                }
            }

        }