Accord.Tests.Math.BoundedBroydenFletcherGoldfarbShannoTest.lbfgsTest3 C# (CSharp) Method

lbfgsTest3() private method

private lbfgsTest3 ( ) : void
return void
        public void lbfgsTest3()
        {
            Accord.Math.Tools.SetupGenerator(0);

            Func<double[], double> f;
            Func<double[], double[]> g;
            createExpDiff(out f, out g);

            int errors = 0;

            for (int i = 0; i < 10000; i++)
            {
                double[] start = Accord.Math.Matrix.Random(2, -1.0, 1.0);

                var lbfgs = new BoundedBroydenFletcherGoldfarbShanno(numberOfVariables: 2,
                    function: f, gradient: g);

                lbfgs.FunctionTolerance = 1e3;

                Assert.IsTrue(lbfgs.Minimize(start));
                double minValue = lbfgs.Value;
                double[] solution = lbfgs.Solution;

                double expected = -2;

                if (Math.Abs(expected - minValue) > 1e-2)
                    errors++;
            }

            Assert.IsTrue(errors < 1000);
        }