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

ConstructorTest1() private method

private ConstructorTest1 ( ) : void
return void
        public void ConstructorTest1()
        {
            Func<double[], double> function = // min f(x) = 10 * (x+1)^2 + y^2
                x => 10.0 * Math.Pow(x[0] + 1.0, 2.0) + Math.Pow(x[1], 2.0);

            Func<double[], double[]> gradient = x => new[] { 20 * (x[0] + 1), 2 * x[1] };

            var target = new BoundedBroydenFletcherGoldfarbShanno(2)
            {
                Function = function,
                Gradient = gradient
            };

            bool success = target.Minimize();
            double minimum = target.Value;
            double[] solution = target.Solution;

            Assert.IsTrue(success);

            Assert.AreEqual(0, minimum, 1e-10);
            Assert.AreEqual(-1, solution[0], 1e-5);
            Assert.AreEqual(0, solution[1], 1e-5);

            double expectedMinimum = function(target.Solution);
            Assert.AreEqual(expectedMinimum, minimum);
        }