BFGS DFP example

by Trent Guidry 4. October 2009 09:33

In this post I give an example of using the previously created BFGS and DFP classes to solve an unconstrained optimization problem.

For this example, I will minimize the function shown below from a starting guess of x1 = 0 and x2 = 0.

f(x) = 4x12 + 3x22 – 4x1x2 + x1

This function corresponds to example problem 3.10 from Engineering Optimization Methods And Applications by Reklaitis, Ravindran, and Ragsdell.

To solve this optimization problem using the DFP class, I add the following code to the Window Loaded event of a WPF project.

            Parameter X1 = new Parameter(0.0);
            Parameter X2 = new Parameter(0.0);
            Func<double> function = () =>
            {
                return 4.0 * X1 * X1 + 3.0 * X2 * X2 - 4.0 * X1 * X2 + X1;
            };
            Parameter[] optimizationParameters = new Parameter[] { X1, X2 };
            QuasiNewtonBase qnb = new DFP(function, optimizationParameters);
            double prevousValue = 0.0;
            double currentValue = double.PositiveInfinity;
            do
            {
                prevousValue = currentValue;
                qnb.Iterate();
                currentValue = qnb.FunctionValue;
            } while (currentValue < prevousValue);

Running the application gives values of x1 = -0.18750 and x2 = -0.12500 after two line searches. This is identical to the results from the book from which the example was taken, which is to be expected.

To solve this problem using the BFGS class, the line:

            QuasiNewtonBase qnb = new DFP(function, optimizationParameters);

is replaced with:

            QuasiNewtonBase qnb = new BFGS(function, optimizationParameters);

Running this gives the same final result as the DFP case, which is also to be expected.

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading