Click or drag to resize

ContinuousOptimizationMinimize Method (FuncDoubleMatrix, Double, DoubleMatrix)

Finds the minimum of the specified objective function.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static DoubleMatrix Minimize(
	Func<DoubleMatrix, double> objectiveFunction,
	DoubleMatrix initialArgument
)

Parameters

objectiveFunction
Type: SystemFuncDoubleMatrix, Double
The objective function to be minimized.
initialArgument
Type: Novacta.AnalyticsDoubleMatrix
The argument at which the method starts the search for optimality.

Return Value

Type: DoubleMatrix
The argument at which the function is minimized.
Exceptions
ExceptionCondition
ArgumentNullExceptionobjectiveFunction is null.
-or-
initialArgument is null.
ArgumentExceptioninitialArgument is not a row vector.
Remarks

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.

Examples

In the following example, function

LaTeX equation

is minimized in the sub-domain LaTeX equation. To obtain such result, arguments outside that interval are penalized accordingly.

The search for the minimizer starts from the initial argument LaTeX equation.

Minimizing a function in a sub-domain.
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class ContinuousOptimizationExample0  
    {
        public void Main()
        {
            // Define the objective function as follows: 
            // f(x) = exp(-(x-2)^2) + (.8) * exp(-(x+2)^2)),
            // penalized for minimization if x is not in [-3, 3].
            static double objectiveFunction(DoubleMatrix x)
            {
                double y = 0.0;
                var x_0 = x[0];
                y += Math.Exp(-Math.Pow(x_0 - 2.0, 2.0));
                y += .8 * Math.Exp(-Math.Pow(x_0 + 2.0, 2.0));

                // Penalize arguments not in [-3, 3].
                if (x_0 < -3.0 || 3.0 < x_0)
                {
                    y += 100.0 * Math.Abs(x_0 - 3.0);
                }
                return y;
            }

            // Define the argument at which the method starts 
            // the search for optimality.
            var initialArgument = DoubleMatrix.Dense(1, 1, -3.0);

            // Minimize the objective function.
            var minimizer = ContinuousOptimization.Minimize(
                objectiveFunction: objectiveFunction,
                initialArgument: initialArgument);

            // Show the results.
            Console.WriteLine();
            Console.WriteLine("The minimizer of the objective function is:");
            Console.WriteLine(minimizer);

            Console.WriteLine();

            Console.WriteLine("The minimum value of the objective function is:");
            Console.WriteLine(objectiveFunction(minimizer));
        }
    }
}

// Executing method Main() produces the following output:
// 
// 
// The minimizer of the objective function is:
// -0.0318684014    
// 
// 
// 
// The minimum value of the objective function is:
// 0.032734891180979234

See Also