public void TestLineSearchDeterminesSaneStepLength1() { var objectiveFunction = new QuadraticFunction1(); // given var testX = new double[] { 0 }; 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); }
public void TestLineSearchFailsWithWrongDirection3() { var objectiveFunction = new QuadraticFunction1(); // given double[] testX = { 4 }; 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); }