public void FindMinimumGoldsteinPriceFunction_AnalyticResult(MultiDimOptimizerConstraintProvider constraintTransformation) { var randomNumberStream = CreateStubRandomNumberStream(); var optimizer = new PraxisOptimizer(randomNumberStream, PraxisOptimizer.StandardAbortCondition, constraintTransformation); var constraint = optimizer.Constraint.Create(MultiDimRegion.Interval.Create(2, new[] { -2.0, -2.0 }, new[] { 2.0, 2.0 })); var optimizerAlgorithm = optimizer.Create(constraint); optimizerAlgorithm.Function = optimizer.Function.Create(2, z => { var x = z[0]; var y = z[1]; return((1.0 + Math.Pow(x + y + 1.0, 2) * (19.0 - 14.0 * x + 3 * x * x - 14.0 * y + 6.0 * x * y + 3.0 * y * y)) * (30.0 + Math.Pow(2.0 * x - 3.0 * y, 2) * (18.0 - 32.0 * x + 12.0 * x * x + 48.0 * y - 36 * x * y + 27 * y * y))); }); /* take an initial guess which is not extremly fare away from the argMin: */ var actualArgMin = new double[2]; actualArgMin[0] = 0.35; actualArgMin[1] = -0.45; // Box-Constraint Transformation: sometimes one gets quite high arguments -/+ 3.13E19 arguments which yields to f(x) =\infinity and the algorithm fails double actualMinimum; var state = optimizerAlgorithm.FindMinimum(actualArgMin, out actualMinimum); var expectedMinimum = 3.0; Assert.That(actualMinimum, Is.EqualTo(expectedMinimum).Within(1E-2), "Minimum"); var expectedArgMin = new[] { 0.0, -1.0 }; Assert.That(actualArgMin, Is.EqualTo(expectedArgMin).AsCollection.Within(1E-1)); }
public void FindMinimumGoldsteinPriceFunction_AnalyticResult(MultiDimOptimizerConstraintProvider constraintTransformation) { var optimizer = new PowellOptimizer(PowellOptimizer.StandardAbortCondition, PowellOptimizer.StandardLineSearchOptimizer, constraintTransformation); var constraint = optimizer.Constraint.Create(MultiDimRegion.Interval.Create(2, new[] { -2.0, -2.0 }, new[] { 2.0, 2.0 })); var optimizerAlgorithm = optimizer.Create(constraint); optimizerAlgorithm.Function = optimizer.Function.Create(2, z => { var x = z[0]; var y = z[1]; return((1.0 + Math.Pow(x + y + 1.0, 2) * (19.0 - 14.0 * x + 3 * x * x - 14.0 * y + 6.0 * x * y + 3.0 * y * y)) * (30.0 + Math.Pow(2.0 * x - 3.0 * y, 2) * (18.0 - 32.0 * x + 12.0 * x * x + 48.0 * y - 36 * x * y + 27 * y * y))); }); /* take an initial guess which is not extremly fare away from the expected argMin: */ var actualArgMin = new double[2]; actualArgMin[0] = -0.1; actualArgMin[1] = -0.75; double actualMinimum; var state = optimizerAlgorithm.FindMinimum(actualArgMin, out actualMinimum); var expectedMinimum = 3.0; Assert.That(actualMinimum, Is.EqualTo(expectedMinimum).Within(1E-2), "Minimum"); var expectedArgMin = new[] { 0.0, -1.0 }; Assert.That(actualArgMin, Is.EqualTo(expectedArgMin).AsCollection.Within(1E-1)); }
/// <summary>Initializes a new instance of the <see cref="PowellOptimizer"/> class. /// </summary> /// <param name="abortCondition">The abort (stopping) condition for the Simulated Annealing optimizer.</param> /// <param name="lineSearchOptimizer">The line search optimizer to take into account.</param> /// <param name="constraintProvider">The constraint provider, i.e. transformation etc. for the support of specific constraints (the original algorithm does not support any constraints).</param> public PowellOptimizer(PowellOptimizerAbortCondition abortCondition, OneDimOptimizer lineSearchOptimizer, MultiDimOptimizerConstraintProvider constraintProvider) { AbortCondition = abortCondition ?? throw new ArgumentNullException(nameof(abortCondition)); LineSearchOptimizer = lineSearchOptimizer ?? throw new ArgumentNullException(nameof(lineSearchOptimizer)); m_ConstraintProvider = constraintProvider ?? throw new ArgumentNullException(nameof(constraintProvider)); m_Name = new IdentifierString("Powell optimizer"); m_FunctionDescriptor = new OrdinaryMultiDimOptimizerFunctionFactory(); m_ConstraintDescriptor = new MultiDimOptimizerConstraintFactory(constraintProvider.SupportedConstraints); }
/// <summary>Initializes a new instance of the <see cref="NelderMeadOptimizer"/> class. /// </summary> /// <param name="abortCondition">The abort (stopping) condition for the Nelder-Mead optimizer.</param> /// <param name="constraintProvider">The constraint provider, i.e. transformation etc. for the support of specific constraints (the original algorithm does not support any constraints).</param> /// <param name="initialScaleFactor">A scaling factor which is used to create from a specific initial guess the N + 1 points (in \R^N) of the start simplex.</param> public NelderMeadOptimizer(NelderMeadOptimizerAbortCondition abortCondition, MultiDimOptimizerConstraintProvider constraintProvider, double initialScaleFactor = 1.0) { AbortCondition = abortCondition ?? throw new ArgumentNullException(nameof(abortCondition)); m_ConstraintProvider = constraintProvider ?? throw new ArgumentNullException(nameof(constraintProvider)); m_Name = new IdentifierString("Nelder-Mead-Simplex search optimizer"); m_FunctionDescriptor = new OrdinaryMultiDimOptimizerFunctionFactory(); m_ConstraintDescriptor = new MultiDimOptimizerConstraintFactory(constraintProvider.SupportedConstraints); InitialScaleFactor = initialScaleFactor; }
/// <summary>Initializes a new instance of the <see cref="PraxisOptimizer"/> class. /// </summary> /// <param name="randomNumberStream">The random number stream.</param> /// <param name="abortCondition">The abort (stopping) condition for the Simulated Annealing optimizer.</param> /// <param name="constraintProvider">The constraint provider, i.e. transformation etc. for the support of specific constraints (the original algorithm does not support any constraints).</param> /// <param name="scalingFactor">A scaling parameter. If the scales for the different parameters are very different this value should be/ set to a value of about 10.0.</param> /// <param name="expectedDistanceToSolution">A step length parameter which should be set equal to the expected distance from the solution.</param> public PraxisOptimizer(IRandomNumberStream randomNumberStream, PraxisOptimizerAbortCondition abortCondition, MultiDimOptimizerConstraintProvider constraintProvider, double scalingFactor = 1.0, double expectedDistanceToSolution = 1.0) { if (randomNumberStream == null) { throw new ArgumentNullException(nameof(randomNumberStream)); } m_SingleRandomNumberStream = new SingleRandomNumberStream(randomNumberStream, 250); AbortCondition = abortCondition ?? throw new ArgumentNullException(nameof(abortCondition)); m_ConstraintProvider = constraintProvider ?? throw new ArgumentNullException(nameof(constraintProvider)); ScalingFactor = scalingFactor; ExpectedDistanceToSolution = expectedDistanceToSolution; m_Name = new IdentifierString("PRAXIS optimizer"); m_FunctionDescriptor = new OrdinaryMultiDimOptimizerFunctionFactory(); m_ConstraintDescriptor = new MultiDimOptimizerConstraintFactory(constraintProvider.SupportedConstraints); }
/// <summary>Initializes the <see cref="PowellOptimizer" /> class. /// </summary> static PowellOptimizer() { StandardAbortCondition = PowellOptimizerAbortCondition.Create(); StandardLineSearchOptimizer = new BrentOptimizer(); StandardConstraintProvider = MultiDimOptimizerConstraintProvider.BoxTransformation; }
/// <summary>Initializes the <see cref="PraxisOptimizer" /> class. /// </summary> static PraxisOptimizer() { StandardAbortCondition = PraxisOptimizerAbortCondition.Create(); StandardConstraintProvider = MultiDimOptimizerConstraintProvider.BoxTransformation; }
/// <summary>Initializes the <see cref="MultiDimOptimizerConstraintProvider" /> class. /// </summary> static MultiDimOptimizerConstraintProvider() { BoxTransformation = new BoxTransformationFactory(); QuadraticPenalty = new QuadraticPenaltyConstraintProvider(); }