How do I pass additional parameters to the objective function specified within the GA or the PATTERNSEARCH function in the Genetic Algorithm and Direct Search Toolbox?

33 views (last 30 days)
For example, additional parameters can be passed to the objective function used in the FMINSEARCH function by specifying them in a comma seperated list after the options argument, or by using anonymous functions in MATLAB 7.0 (R14). Can I do the same within the GA or the PATTERNSEARCH functions?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 13 Apr 2023
Edited: MathWorks Support Team on 14 Apr 2023
The documentation for the GA function in the Genetics Algorithm and Direct Search toolbox version R14 and above discusses different methods for passing additional arguments to the objective function. This documentation can be accessed by executing the following at the MATLAB prompt:
doc ga
The online documentation for the GA function is available at,
This documentation gives a link to the section on Passing Extra Parameters in the Optimization Toolbox User's Guide. The online documentation on Passing Extra Parameters is available at,
For previous releases, please read below for any possible workarounds:
Passing additional parameters to the GA or PATTERNSEARCH functions is performed differently than for other functions within MATLAB (e.g., the ODE45 or QUAD functions). For GA or PATTERNSEARCH, the first input argument can be a cell array whose first element is the objective function handle, and each subsequent element is an additional parameter.
[x f] = ga({@objfcn, P1, P2}, 2);
The reason for the change in syntax is that there are different function that can be specified for use within the GA or PATTERNSEARCH functions (e.g., "MutationFcn" and "CrossoverFcn"). Each of these functions can take different input parameters. In the Optimization Toolbox syntax, each function must take the same input parameters. However, in the Genetic Algorithm and Direct Search Toolbox, you can specify different parameters for each function.
options = gaoptimset('MutationFcn', {@mutate, P1}, 'CrossoverFcn', {@cross, P2})
An example of this can be seen in the "Minimizing using additional arguments" example at the following URL:

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!