Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Solutions Academia Support User Community Company
spacer spacer spacer spacer spacer spacer

 

Genetic Algorithm and Direct Search Toolbox 2.4.2

Hybrid Scheme in the Genetic Algorithm

Contents

Introduction

This demo uses a hybrid scheme to optimize a function using the Genetic Algorithm and another optimization method. GA can reach the region near an optimum point relatively quickly, but it can take many function evaluations to achieve convergence. A commonly used technique is to run GA for a small number of generations to get near an optimum point. Then the solution from GA is used as an initial point for another optimization solver that is faster and more efficient for local search.

Rosenbrock's Function

For the demo we will optimize Rosenbrock's function (also known as Dejong's second function):

   f(x)= 100*(x(2)-x(1)^2)^2+(1-x(1))^2

This function is notorious in optimization because of the slow convergence most methods exhibit when trying to minimize this function. This function has a unique minimum at the point x* = (1,1) where it has a function value f(x*) = 0.

We can view the code for this fitness function.

type dejong2fcn.m
function scores = dejong2fcn(pop)
%DEJONG2FCN Compute DeJongs second function.
%This function is also known as Rosenbrock's function

%   Copyright 2003-2004 The MathWorks, Inc.
%   $Revision: 1.3.4.2 $  $Date: 2004/08/20 19:50:12 $

scores = zeros(size(pop,1),1);
for i = 1:size(pop,1)
    p = pop(i,:);
    scores(i) = 100 * (p(1)^2 - p(2)) ^2 + (1 - p(1))^2;
end

We use the function PLOTOBJECTIVE in the toolbox to plot the function DEJONG2FCN over the range = [-2 2;-2 2].

plotobjective(@dejong2fcn,[-2 2;-2 2]);

Genetic Algorithm Solution

To start, we will use the Genetic Algorithm, GA, alone to find the minimum of Rosenbrock's function. We need to supply GA with a function handle to the fitness function dejong2fcn.m. Also, GA needs to know the how many variables are in the problem, which is two for this function.

FitnessFcn = @dejong2fcn;
numberOfVariables = 2;

Some plot functions can be selected to monitor the performance of the solver.

options = gaoptimset('PlotFcns', {@gaplotbestf,@gaplotstopping});

We run GA with the above inputs.

[x,fval] = ga(FitnessFcn,numberOfVariables,[],[],[],[],[],[],[],options)
Optimization terminated: average change in the fitness value less than optio
ns.TolFun.

x =

    0.9542    0.9015


fval =

    0.0101

The global optimum is at x* = (1,1). GA found a point near the optimum, but could not get a more accurate answer with the default stopping criteria. By changing the stopping criteria, we might find a more accurate solution, but it may take many more function evaluations to reach x* = (1,1). Instead, we can use a more efficient local search that starts where GA left off. The hybrid function field in GA provides this feature automatically.

Adding a Hybrid Function

We will use a hybrid function to solve the optimization problem, i.e., when GA stops (or you ask it to stop) this hybrid function will start from the final point returned by GA. Our choices are FMINSEARCH, PATTERNSEARCH, or FMINUNC. Since this optimization example is smooth, i.e., continuously differentiable, we can use the FMINUNC function from the Optimization toolbox as our hybrid function. Since FMINUNC has its own options structure, we provide it as an additional argument when specifying the hybrid function.

fminuncOptions = optimset('Display','iter', 'LargeScale','off');
options = gaoptimset(options,'HybridFcn',{@fminunc, fminuncOptions});

Run GA solver again with FMINUNC as the hybrid function.

[x,fval] = ga(@dejong2fcn,numberOfVariables,[],[],[],[],[],[],[],options)
Optimization terminated: average change in the fitness value less than optio
ns.TolFun.
                                                        First-order
 Iteration  Func-count       f(x)        Step-size       optimality
     0           3        0.0681049                          4.37
     1          12        0.0548021     0.00228845           2.75
     2          15        0.0476934              1          0.179
     3          21        0.0470078             10          0.415
     4          24        0.0443759              1          0.928
     5          27        0.0385296              1           2.25
     6          30        0.0320316              1           2.67
     7          33        0.0171581              1           2.26
     8          36        0.0068208              1          0.427
     9          39       0.00312121              1           1.69
    10          42      0.000717581              1          0.122
    11          45     8.29551e-005              1          0.185
    12          48     3.96822e-006              1         0.0481
    13          51      4.8016e-008              1       0.000177
    14          54     1.85915e-009              1         0.0015
    15          57     3.41604e-011              1       0.000169
    16          60     2.11819e-011              1       3.1e-006

Local minimum found.

Optimization completed because the size of the gradient is less than
the default value of the function tolerance.




x =

    1.0000    1.0000


fval =

  2.1182e-011

The first plot shows the best and mean values of the population in every generation. The best value found by GA when it terminated is also shown in the plot title. When GA terminated, FMINUNC (the hybrid function) was automatically called with the best point found by GA so far. The solution 'x' and 'fval' is the result of using GA and FMINUNC together. As shown here, using the hybrid function can improve the accuracy of the solution efficiently.

Contact sales
Free technical kit
Trial software
E-mail this page

Get Pricing and
Licensing Options