Пример #1
0
        public void TestLineSearchDeterminesSaneStepLength2()
        {
            var objectiveFunction = new QuadraticFunction2();
            // given
            var testX         = new double[] { -2 };
            var testValueX    = objectiveFunction.ValueAt(testX);
            var testGradX     = objectiveFunction.GradientAt(testX);
            var testDirection = new double[] { 1 };

            // when
            var lsr = LineSearchResult.GetInitialObject(testValueX, testGradX, testX);

            LineSearch.DoLineSearch(objectiveFunction, testDirection, lsr, 1.0);
            var stepSize = lsr.StepSize;

            // then
            Assert.True(Tolerance < stepSize && stepSize <= 1);
        }
Пример #2
0
        public void TestLineSearchFailsAtMinimum1()
        {
            var objectiveFunction = new QuadraticFunction2();

            // given
            double[] testX      = { 0 };
            var      testValueX = objectiveFunction.ValueAt(testX);
            var      testGradX  = objectiveFunction.GradientAt(testX);

            double[] testDirection = { -1 };
            // when
            var lsr = LineSearchResult.GetInitialObject(testValueX, testGradX, testX);

            LineSearch.DoLineSearch(objectiveFunction, testDirection, lsr, 1.0);
            var stepSize = lsr.StepSize;

            // then
            Assert.False(Tolerance < stepSize && stepSize <= 1);

            Assert.AreEqual(0.0, stepSize, Tolerance);
        }