ContinuousOptimizationMaximizeTFunctionParameter Method (FuncDoubleMatrix, TFunctionParameter, Double, DoubleMatrix, TFunctionParameter) |
Namespace: Novacta.Analytics
public static DoubleMatrix Maximize<TFunctionParameter>( Func<DoubleMatrix, TFunctionParameter, double> objectiveFunction, DoubleMatrix initialArgument, TFunctionParameter functionParameter )
Exception | Condition |
---|---|
ArgumentNullException | objectiveFunction is
null. -or- initialArgument is null. |
ArgumentException | initialArgument is not a row vector. |
It is assumed that the objectiveFunction will accept row vectors as valid representations of an argument. As a consequence, initialArgument is expected to be a row vector.
In the following example, function
is maximized.
The search for the maximizer starts from the initial argument .
using System; namespace Novacta.Analytics.CodeExamples { public class ContinuousOptimizationExample1 { public void Main() { // Define the parametric objective function as follows: // f(x, a) = exp(-(x-2)^2) + (a) * exp(-(x+2)^2)). static double objectiveFunction(DoubleMatrix x, double alpha) { double y = 0.0; var x_0 = x[0]; y += Math.Exp(-Math.Pow(x_0 - 2.0, 2.0)); y += alpha * Math.Exp(-Math.Pow(x_0 + 2.0, 2.0)); return y; } // Define the argument at which the method starts // the search for optimality. var initialArgument = DoubleMatrix.Dense(1, 1, -6.0); // Define the function parameter. double functionParameter = .8; // Maximize the objective function. var maximizer = ContinuousOptimization.Maximize( objectiveFunction: objectiveFunction, initialArgument: initialArgument, functionParameter: functionParameter); // Show the results. Console.WriteLine(); Console.WriteLine("The maximizer of the objective function is:"); Console.WriteLine(maximizer); Console.WriteLine(); Console.WriteLine("The maximum value of the objective function is:"); Console.WriteLine(objectiveFunction(maximizer, functionParameter)); } } } // Executing method Main() produces the following output: // // // The maximizer of the objective function is: // 2.00000859 // // // // The maximum value of the objective function is: // 1.000000089948087