public void Unimodal_Square_Optimum()
        {
            var f = new SquareTestFunction().FunctionValueAnalysisFor1D();
            var a = f.ValueWithDerivative(-1);
            var b = f.ValueWithDerivative(2);

            var point = new NumberFunctionOptimizationSearchRange(a: a, b: b);

            point.BorderSmaller.X.AssertIsEqualTo(2);
            point.BorderSmaller.Y.AssertIsEqualTo(4);

            _method.MoveNext(in f, ref point);
            point.BorderSmaller.X.AssertIsEqualTo(1);
            point.BorderSmaller.Y.AssertIsEqualTo(3);

            point.IsEmptyRange.AssertIsTrue();
            try
            {
                _method.MoveNext(in f, ref point);
                throw new Exception("I should never get here");
            }
            catch (AssertException)
            {
                // all is fine.
            }
        }
        public void Unimodal_Square_NegativeDerivative_Optimum()
        {
            var    f = new SquareTestFunction().FunctionValueAnalysisFor1D();
            var    a = f.ValueWithDerivative(1);
            Number b = -2;

            ushort i = _method.FindOptimal(in f, a, b, out NumberFunctionPointWithDerivative solution);

            solution.X.AssertIsEqualTo(1);
            i.AssertIsEqualTo(24);
        }
Exemple #3
0
        public void Unimodal_Square_Optimum()
        {
            var f = new SquareTestFunction().FunctionValueAnalysisFor1D();
            var a = f.ValueWithDerivative(0);
            var b = f.ValueWithDerivative(3);

            NumberFunctionPointWithDerivative actual = _optimizer.MoveNext(f, in a, b.X, out uint complexity);

            actual.X.AssertIsEqualTo(1);
            complexity.AssertIsEqualTo(1u);
        }
        public void Unimodal_Square_NegativeDerivative_Optimum()
        {
            var f = new SquareTestFunction().FunctionValueAnalysisFor1D();
            var a = f.ValueWithDerivative(1);
            var b = f.ValueWithDerivative(-2);

            var point = new NumberFunctionOptimizationSearchRange(a: a, b: b);

            point.BorderSmaller.X.AssertIsEqualTo(1);

            ushort i = _method.FindOptimal(in f, ref point);

            point.BorderSmaller.X.AssertIsEqualTo(1);
            i.AssertIsEqualTo(24);
        }
Exemple #5
0
        public void Unimodal_Square_AtOptimum()
        {
            var f = new SquareTestFunction().FunctionValueAnalysisFor1D();
            var a = f.ValueWithDerivative(1);
            var b = f.ValueWithDerivative(2);

            try
            {
                _optimizer.MoveNext(f, in a, b.X, out _);
                throw new Exception("I should never get here");
            }
            catch (AssertException)
            {
                // all is fine
            }
        }