Professional Documents
Culture Documents
Optimization With Ga Toolbox
Optimization With Ga Toolbox
1 of 4
Industries
Academia
http://www.mathworks.com/company/newsletters/digest/sept04/optimiz...
Support
User Community
Company
03.11.2008 12:54
2 of 4
http://www.mathworks.com/company/newsletters/digest/sept04/optimiz...
FitnessFcn = @nonSmoothFcn;
optGA = gaoptimset('PlotFcns', @gaplotbestfun, 'PlotInterval', 5, 'PopInitRange', [-5 ; 5]);
[Xga,Fga] = ga(FitnessFcn,2,optGA)
Xga =
-4.7220 0.0205
Fga =
13.0003
-4.712389
-4.7220
-0.0096
x(2)
0.0205
0.0205
Objfcn(x)
13
13.0003
0.0003
x(1)
03.11.2008 12:54
3 of 4
http://www.mathworks.com/company/newsletters/digest/sept04/optimiz...
The hybrid function begins optimizing at the best point returned by the genetic algorithm. As our sample problem is smooth in
the area around the minimum, we can choose the fminunc function from the Optimization Toolbox as our hybrid function. This
function uses a fast derivative-based method, and is designed for unconstrained minimization problems.
Because fminunc can efficiently find the minimum in a smooth region, we can transition to this function once the genetic
algorithm brings the solution into this region. Figure 4 shows that the genetic algorithm finds a solution near the minimum
within the first 15 generations. For this reason, we can change the Stopping criteria within the Genetic Algorithm Tool so
that the genetic algorithm runs for only 15 generations instead of the default value of 100. This is enough for the algorithm to
bring the solution into the smooth region, at which point we can begin our iterations with fminunc.
You can customize a hybrid function with its own set of options. For this problem, we use fminunc with an output function,
which is called after each algorithm iteration. Our output function, fminuncOut.m, plots the best function value at each
iteration of the fminunc algorithm on the same plot as the iterations of the genetic algorithm. We specify the output function in
the Options pane of the Hybrid function section of the Genetic Algorithm Tool by typing the following:
optimset('Outputfcn',@fminuncOut)
After we run the optimization, the Genetic Algorithm Tool and best fitness plot display the optimization results, as shown in
Figure 5.
Exact
solution
x(1)
-4.712389
-4.712389
-7.29017E-12
x(2)
1.6E-7
1.6E-7
Objfcn(x)
13
13.000000
7.5E-14
Note that the hybrid function noticeably improves the accuracy of results compared to the genetic algorithm, and costs only a
few iterations of the fminunc algorithm.
03.11.2008 12:54
4 of 4
http://www.mathworks.com/company/newsletters/digest/sept04/optimiz...
x(1)
-4.712389
-4.712387
1.895E-06
x(2)
Objfcn(x)
13
13.000000
3.592E-12
Summary
This article explored the methods available in the Genetic Algorithm and Direct Search Toolbox. We saw that the genetic
algorithm is an effective solver for nonsmooth problems. Additionally, we found that the genetic algorithm can be combined
with other solvers, such as the fminunc algorithm in the Optimization Toolbox, to efficiently find a more accurate solution. We
used both the GUI and the MATLAB command-line interface to invoke the genetic algorithm. After using the genetic algorithm,
we explored the less well-known but very effective pattern search method on our sample problem via the pattern search GUI.
The optimization techniques available in the Genetic Algorithm and Direct Search Toolbox, sometimes in conjunction with the
methods in the Optimization Toolbox, expand the scope of optimization problems that engineers and scientists can solve to
include problems with discontinuous, nondifferentiable, or stochastic objective functions.
Download the code described in this article.
Site Help
Patents
Trademarks
Privacy Policy
Preventing Piracy
RSS
03.11.2008 12:54