Accord.Tests.Statistics.NonLinearLeastSquaresTest.RunTest C# (CSharp) Method

RunTest() private method

private RunTest ( ) : void
return void
        public void RunTest()
        {
            // Suppose we would like to map the continuous values in the
            // second column to the integer values in the first column.
            double[,] data =
            {
                { -40,    -21142.1111111111 },
                { -30,    -21330.1111111111 },
                { -20,    -12036.1111111111 },
                { -10,      7255.3888888889 },
                {   0,     32474.8888888889 },
                {  10,     32474.8888888889 },
                {  20,      9060.8888888889 },
                {  30,    -11628.1111111111 },
                {  40,    -15129.6111111111 },
            };

            // Extract inputs and outputs
            double[][] inputs = data.GetColumn(0).ToJagged();
            double[] outputs = data.GetColumn(1);

            // Create a Nonlinear regression using 
            NonlinearRegression regression = new NonlinearRegression(4, function, gradient);


            NonlinearLeastSquares nls = new NonlinearLeastSquares(regression);

            Assert.IsTrue(nls.Algorithm is LevenbergMarquardt);

            regression.Coefficients[0] = 0; // m
            regression.Coefficients[1] = 80; // s
            regression.Coefficients[2] = 53805; // a
            regression.Coefficients[3] = -21330.11; //b

            double error = Double.PositiveInfinity;
            for (int i = 0; i < 100; i++)
                error = nls.Run(inputs, outputs);

            double m = regression.Coefficients[0];
            double s = regression.Coefficients[1];
            double a = regression.Coefficients[2];
            double b = regression.Coefficients[3];

            Assert.AreEqual(010345587.465428974, error);

            Assert.AreEqual(5.316196154830604, m, 1e-3);
            Assert.AreEqual(12.792301798208918, s, 1e-3);
            Assert.AreEqual(56794.832645792514, a, 1e-3);
            Assert.AreEqual(-20219.675997523173, b, 1e-2);

            Assert.IsFalse(Double.IsNaN(m));
            Assert.IsFalse(Double.IsNaN(s));
            Assert.IsFalse(Double.IsNaN(a));
            Assert.IsFalse(Double.IsNaN(b));
        }