public void FindMinimum_CubicTestfunction_AnalyticResult(double lowerBound, double upperBound, double initialGuess)
        {
            var optimizer = new GoldenSectionSearchOptimizer();

            var optimizerAlgorithm = optimizer.Create(Interval.Create(lowerBound, upperBound));

            optimizerAlgorithm.Function = optimizer.Function.Create(x => 2 * (x - 5) * (x - 5) * (x - 5) * (x - 4) + 4.0);

            var state = optimizerAlgorithm.FindMinimum(initialGuess, out double actualArgMin, out double actualMinimum);

            var expectedArgMin  = 4.25;
            var expectedMinimum = 4.0 - 27.0 / 128.0;

            Assert.That(actualMinimum, Is.EqualTo(expectedMinimum).Within(1E-5), String.Format("Expected argMin: {0}, Actual argMin: {1}", expectedArgMin, actualArgMin));
            Assert.That(actualArgMin, Is.EqualTo(expectedArgMin).Within(1E-5));
        }
        public void FindMinimum_XMinus1SquareTestFunction_AnalyticResult(double lowerBound, double upperBound, double initialGuess)
        {
            Assume.That((lowerBound < upperBound) && (lowerBound < 1.0) && (1.0 < upperBound), "Wrong lower bounds");
            Assume.That((initialGuess < upperBound) && (lowerBound < initialGuess), "Invalid initial guess");

            var optimizer          = new GoldenSectionSearchOptimizer();
            var optimizerAlgorithm = optimizer.Create(Interval.Create(lowerBound, upperBound));

            optimizerAlgorithm.Function = optimizer.Function.Create(x => (x - 1.0) * (x - 1.0));

            var state = optimizerAlgorithm.FindMinimum(initialGuess, out double actualArgMin, out double actualMinimum);

            var expectedArgMin  = 1.0;
            var expectedMinimum = 0.0;

            Assert.That(actualArgMin, Is.EqualTo(expectedArgMin).Within(1E-5));
            Assert.That(actualMinimum, Is.EqualTo(expectedMinimum).Within(1E-5));
        }
예제 #3
0
 /// <summary>Initializes a new instance of the <see cref="Algorithm"/> class.
 /// </summary>
 /// <param name="optimizer">The <see cref="GoldenSectionSearchOptimizer"/> object that serves as factory of the current object.</param>
 /// <param name="constraint">The constraint in its <see cref="OneDimOptimizerConstraint"/> representation.</param>
 internal Algorithm(GoldenSectionSearchOptimizer optimizer, OneDimOptimizerConstraint constraint)
 {
     m_Optimizer  = optimizer;
     m_Constraint = constraint;
 }